ogi-addon 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/SearchEngine.cjs.map +1 -1
- package/build/SearchEngine.d.cts +1 -1
- package/build/SearchEngine.d.ts +1 -1
- package/build/main.cjs +75 -38
- package/build/main.cjs.map +1 -1
- package/build/main.d.cts +25 -5
- package/build/main.d.ts +25 -5
- package/build/main.js +75 -38
- package/build/main.js.map +1 -1
- package/package.json +1 -1
- package/src/SearchEngine.ts +1 -1
- package/src/main.ts +115 -49
package/src/main.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type OGIAddonEvent =
|
|
|
19
19
|
| 'library-search'
|
|
20
20
|
| 'game-details'
|
|
21
21
|
| 'exit'
|
|
22
|
+
| 'task-run'
|
|
22
23
|
| 'request-dl'
|
|
23
24
|
| 'catalog';
|
|
24
25
|
|
|
@@ -41,6 +42,7 @@ export type OGIAddonServerSentEvent =
|
|
|
41
42
|
| 'setup'
|
|
42
43
|
| 'response'
|
|
43
44
|
| 'library-search'
|
|
45
|
+
| 'task-run'
|
|
44
46
|
| 'game-details'
|
|
45
47
|
| 'request-dl'
|
|
46
48
|
| 'catalog';
|
|
@@ -89,6 +91,21 @@ export type BasicLibraryInfo = {
|
|
|
89
91
|
storefront: string;
|
|
90
92
|
};
|
|
91
93
|
|
|
94
|
+
export type SetupEventResponse = Omit<
|
|
95
|
+
LibraryInfo,
|
|
96
|
+
| 'capsuleImage'
|
|
97
|
+
| 'coverImage'
|
|
98
|
+
| 'name'
|
|
99
|
+
| 'appID'
|
|
100
|
+
| 'storefront'
|
|
101
|
+
| 'addonsource'
|
|
102
|
+
| 'titleImage'
|
|
103
|
+
> & {
|
|
104
|
+
redistributables?: {
|
|
105
|
+
name: string;
|
|
106
|
+
path: string;
|
|
107
|
+
}[];
|
|
108
|
+
};
|
|
92
109
|
export interface EventListenerTypes {
|
|
93
110
|
/**
|
|
94
111
|
* This event is emitted when the addon connects to the OGI Addon Server. Addon does not need to resolve anything.
|
|
@@ -150,19 +167,9 @@ export interface EventListenerTypes {
|
|
|
150
167
|
}[];
|
|
151
168
|
appID: number;
|
|
152
169
|
storefront: string;
|
|
170
|
+
manifest?: Record<string, unknown>;
|
|
153
171
|
},
|
|
154
|
-
event: EventResponse<
|
|
155
|
-
Omit<
|
|
156
|
-
LibraryInfo,
|
|
157
|
-
| 'capsuleImage'
|
|
158
|
-
| 'coverImage'
|
|
159
|
-
| 'name'
|
|
160
|
-
| 'appID'
|
|
161
|
-
| 'storefront'
|
|
162
|
-
| 'addonsource'
|
|
163
|
-
| 'titleImage'
|
|
164
|
-
>
|
|
165
|
-
>
|
|
172
|
+
event: EventResponse<SetupEventResponse>
|
|
166
173
|
) => void;
|
|
167
174
|
|
|
168
175
|
/**
|
|
@@ -176,6 +183,21 @@ export interface EventListenerTypes {
|
|
|
176
183
|
event: EventResponse<BasicLibraryInfo[]>
|
|
177
184
|
) => void;
|
|
178
185
|
|
|
186
|
+
/**
|
|
187
|
+
* This event is emitted when the client requests for a task to be run. Addon should resolve the event with the task.
|
|
188
|
+
* @param task
|
|
189
|
+
* @param event
|
|
190
|
+
* @returns
|
|
191
|
+
*/
|
|
192
|
+
'task-run': (
|
|
193
|
+
task: {
|
|
194
|
+
manifest: Record<string, unknown>;
|
|
195
|
+
downloadPath: string;
|
|
196
|
+
name: string;
|
|
197
|
+
},
|
|
198
|
+
event: EventResponse<void>
|
|
199
|
+
) => void;
|
|
200
|
+
|
|
179
201
|
/**
|
|
180
202
|
* This event is emitted when the client requests for a game details to be fetched. Addon should resolve the event with the game details. This is used to generate a store page for the game.
|
|
181
203
|
* @param appID
|
|
@@ -241,11 +263,13 @@ export interface WebsocketMessageClient {
|
|
|
241
263
|
event: OGIAddonClientSentEvent;
|
|
242
264
|
id?: string;
|
|
243
265
|
args: any;
|
|
266
|
+
statusError?: string;
|
|
244
267
|
}
|
|
245
268
|
export interface WebsocketMessageServer {
|
|
246
269
|
event: OGIAddonServerSentEvent;
|
|
247
270
|
id?: string;
|
|
248
271
|
args: any;
|
|
272
|
+
statusError?: string;
|
|
249
273
|
}
|
|
250
274
|
|
|
251
275
|
/**
|
|
@@ -557,12 +581,16 @@ class OGIAddonWSListener {
|
|
|
557
581
|
case 'config-update':
|
|
558
582
|
const result = this.addon.config.updateConfig(message.args);
|
|
559
583
|
if (!result[0]) {
|
|
560
|
-
this.respondToMessage(
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
584
|
+
this.respondToMessage(
|
|
585
|
+
message.id!!,
|
|
586
|
+
{
|
|
587
|
+
success: false,
|
|
588
|
+
error: result[1],
|
|
589
|
+
},
|
|
590
|
+
undefined
|
|
591
|
+
);
|
|
564
592
|
} else {
|
|
565
|
-
this.respondToMessage(message.id!!, { success: true });
|
|
593
|
+
this.respondToMessage(message.id!!, { success: true }, undefined);
|
|
566
594
|
}
|
|
567
595
|
break;
|
|
568
596
|
case 'search':
|
|
@@ -573,26 +601,18 @@ class OGIAddonWSListener {
|
|
|
573
601
|
this.eventEmitter.emit('search', message.args, searchResultEvent);
|
|
574
602
|
const searchResult =
|
|
575
603
|
await this.waitForEventToRespond(searchResultEvent);
|
|
576
|
-
this.respondToMessage(
|
|
604
|
+
this.respondToMessage(
|
|
605
|
+
message.id!!,
|
|
606
|
+
searchResult.data,
|
|
607
|
+
searchResultEvent
|
|
608
|
+
);
|
|
577
609
|
break;
|
|
578
|
-
case 'setup':
|
|
579
|
-
let setupEvent = new EventResponse<
|
|
610
|
+
case 'setup': {
|
|
611
|
+
let setupEvent = new EventResponse<SetupEventResponse>(
|
|
580
612
|
(screen, name, description) =>
|
|
581
613
|
this.userInputAsked(screen, name, description, this.socket)
|
|
582
614
|
);
|
|
583
|
-
this.eventEmitter.emit(
|
|
584
|
-
'setup',
|
|
585
|
-
{
|
|
586
|
-
path: message.args.path,
|
|
587
|
-
appID: message.args.appID,
|
|
588
|
-
storefront: message.args.storefront,
|
|
589
|
-
type: message.args.type,
|
|
590
|
-
name: message.args.name,
|
|
591
|
-
usedRealDebrid: message.args.usedRealDebrid,
|
|
592
|
-
multiPartFiles: message.args.multiPartFiles,
|
|
593
|
-
},
|
|
594
|
-
setupEvent
|
|
595
|
-
);
|
|
615
|
+
this.eventEmitter.emit('setup', message.args, setupEvent);
|
|
596
616
|
const interval = setInterval(() => {
|
|
597
617
|
if (setupEvent.resolved) {
|
|
598
618
|
clearInterval(interval);
|
|
@@ -606,15 +626,16 @@ class OGIAddonWSListener {
|
|
|
606
626
|
} as ClientSentEventTypes['defer-update']);
|
|
607
627
|
}, 100);
|
|
608
628
|
const setupResult = await this.waitForEventToRespond(setupEvent);
|
|
609
|
-
this.respondToMessage(message.id!!, setupResult.data);
|
|
629
|
+
this.respondToMessage(message.id!!, setupResult.data, setupEvent);
|
|
610
630
|
break;
|
|
631
|
+
}
|
|
611
632
|
case 'library-search':
|
|
612
633
|
let librarySearchEvent = new EventResponse<BasicLibraryInfo[]>(
|
|
613
634
|
(screen, name, description) =>
|
|
614
635
|
this.userInputAsked(screen, name, description, this.socket)
|
|
615
636
|
);
|
|
616
637
|
if (this.eventEmitter.listenerCount('game-details') === 0) {
|
|
617
|
-
this.respondToMessage(message.id!!, []);
|
|
638
|
+
this.respondToMessage(message.id!!, [], librarySearchEvent);
|
|
618
639
|
break;
|
|
619
640
|
}
|
|
620
641
|
this.eventEmitter.emit(
|
|
@@ -624,7 +645,11 @@ class OGIAddonWSListener {
|
|
|
624
645
|
);
|
|
625
646
|
const librarySearchResult =
|
|
626
647
|
await this.waitForEventToRespond(librarySearchEvent);
|
|
627
|
-
this.respondToMessage(
|
|
648
|
+
this.respondToMessage(
|
|
649
|
+
message.id!!,
|
|
650
|
+
librarySearchResult.data,
|
|
651
|
+
librarySearchEvent
|
|
652
|
+
);
|
|
628
653
|
break;
|
|
629
654
|
case 'game-details':
|
|
630
655
|
let gameDetailsEvent = new EventResponse<StoreData | undefined>(
|
|
@@ -632,9 +657,13 @@ class OGIAddonWSListener {
|
|
|
632
657
|
this.userInputAsked(screen, name, description, this.socket)
|
|
633
658
|
);
|
|
634
659
|
if (this.eventEmitter.listenerCount('game-details') === 0) {
|
|
635
|
-
this.respondToMessage(
|
|
636
|
-
|
|
637
|
-
|
|
660
|
+
this.respondToMessage(
|
|
661
|
+
message.id!!,
|
|
662
|
+
{
|
|
663
|
+
error: 'No event listener for game-details',
|
|
664
|
+
},
|
|
665
|
+
gameDetailsEvent
|
|
666
|
+
);
|
|
638
667
|
break;
|
|
639
668
|
}
|
|
640
669
|
this.eventEmitter.emit(
|
|
@@ -644,7 +673,11 @@ class OGIAddonWSListener {
|
|
|
644
673
|
);
|
|
645
674
|
const gameDetailsResult =
|
|
646
675
|
await this.waitForEventToRespond(gameDetailsEvent);
|
|
647
|
-
this.respondToMessage(
|
|
676
|
+
this.respondToMessage(
|
|
677
|
+
message.id!!,
|
|
678
|
+
gameDetailsResult.data,
|
|
679
|
+
gameDetailsEvent
|
|
680
|
+
);
|
|
648
681
|
break;
|
|
649
682
|
case 'request-dl':
|
|
650
683
|
let requestDLEvent = new EventResponse<SearchResult>(
|
|
@@ -652,9 +685,13 @@ class OGIAddonWSListener {
|
|
|
652
685
|
this.userInputAsked(screen, name, description, this.socket)
|
|
653
686
|
);
|
|
654
687
|
if (this.eventEmitter.listenerCount('request-dl') === 0) {
|
|
655
|
-
this.respondToMessage(
|
|
656
|
-
|
|
657
|
-
|
|
688
|
+
this.respondToMessage(
|
|
689
|
+
message.id!!,
|
|
690
|
+
{
|
|
691
|
+
error: 'No event listener for request-dl',
|
|
692
|
+
},
|
|
693
|
+
requestDLEvent
|
|
694
|
+
);
|
|
658
695
|
break;
|
|
659
696
|
}
|
|
660
697
|
this.eventEmitter.emit(
|
|
@@ -666,9 +703,7 @@ class OGIAddonWSListener {
|
|
|
666
703
|
const requestDLResult =
|
|
667
704
|
await this.waitForEventToRespond(requestDLEvent);
|
|
668
705
|
if (requestDLEvent.failed) {
|
|
669
|
-
this.respondToMessage(message.id!!,
|
|
670
|
-
statusError: requestDLEvent.failed,
|
|
671
|
-
});
|
|
706
|
+
this.respondToMessage(message.id!!, undefined, requestDLEvent);
|
|
672
707
|
break;
|
|
673
708
|
}
|
|
674
709
|
if (
|
|
@@ -679,7 +714,11 @@ class OGIAddonWSListener {
|
|
|
679
714
|
'Request DL event did not return a valid result. Please ensure that the event does not resolve with another `request` download type.'
|
|
680
715
|
);
|
|
681
716
|
}
|
|
682
|
-
this.respondToMessage(
|
|
717
|
+
this.respondToMessage(
|
|
718
|
+
message.id!!,
|
|
719
|
+
requestDLResult.data,
|
|
720
|
+
requestDLEvent
|
|
721
|
+
);
|
|
683
722
|
break;
|
|
684
723
|
case 'catalog':
|
|
685
724
|
let catalogEvent = new EventResponse<{
|
|
@@ -691,8 +730,30 @@ class OGIAddonWSListener {
|
|
|
691
730
|
}>();
|
|
692
731
|
this.eventEmitter.emit('catalog', catalogEvent);
|
|
693
732
|
const catalogResult = await this.waitForEventToRespond(catalogEvent);
|
|
694
|
-
this.respondToMessage(message.id!!, catalogResult.data);
|
|
733
|
+
this.respondToMessage(message.id!!, catalogResult.data, catalogEvent);
|
|
695
734
|
break;
|
|
735
|
+
case 'task-run': {
|
|
736
|
+
let taskRunEvent = new EventResponse<void>(
|
|
737
|
+
(screen, name, description) =>
|
|
738
|
+
this.userInputAsked(screen, name, description, this.socket)
|
|
739
|
+
);
|
|
740
|
+
this.eventEmitter.emit('task-run', message.args, taskRunEvent);
|
|
741
|
+
const interval = setInterval(() => {
|
|
742
|
+
if (taskRunEvent.resolved) {
|
|
743
|
+
clearInterval(interval);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
this.send('defer-update', {
|
|
747
|
+
logs: taskRunEvent.logs,
|
|
748
|
+
deferID: message.args.deferID,
|
|
749
|
+
progress: taskRunEvent.progress,
|
|
750
|
+
failed: taskRunEvent.failed,
|
|
751
|
+
} as ClientSentEventTypes['defer-update']);
|
|
752
|
+
}, 100);
|
|
753
|
+
const taskRunResult = await this.waitForEventToRespond(taskRunEvent);
|
|
754
|
+
this.respondToMessage(message.id!!, taskRunResult.data, taskRunEvent);
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
696
757
|
}
|
|
697
758
|
});
|
|
698
759
|
}
|
|
@@ -725,12 +786,17 @@ class OGIAddonWSListener {
|
|
|
725
786
|
});
|
|
726
787
|
}
|
|
727
788
|
|
|
728
|
-
public respondToMessage(
|
|
789
|
+
public respondToMessage(
|
|
790
|
+
messageID: string,
|
|
791
|
+
response: any,
|
|
792
|
+
originalEvent: EventResponse<any> | undefined
|
|
793
|
+
) {
|
|
729
794
|
this.socket.send(
|
|
730
795
|
JSON.stringify({
|
|
731
796
|
event: 'response',
|
|
732
797
|
id: messageID,
|
|
733
798
|
args: response,
|
|
799
|
+
statusError: originalEvent ? originalEvent.failed : undefined,
|
|
734
800
|
})
|
|
735
801
|
);
|
|
736
802
|
console.log('dispatched response to ' + messageID);
|