Skip to content

Commit b6da0df

Browse files
committed
feat: sge and game ipc commands
1 parent ac3194f commit b6da0df

File tree

2 files changed

+106
-16
lines changed

2 files changed

+106
-16
lines changed

electron/preload/index.d.ts

+44-8
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,63 @@
44
declare const appAPI: {
55
ping: () => Promise<string>;
66
/**
7-
* List available characters for a given play.net account.
7+
* Add credentials for a given play.net account.
88
*/
9-
sgeListCharacters: (options: {
9+
sgeAddAccount: (options: {
10+
gameCode: string;
1011
username: string;
1112
password: string;
13+
}) => Promise<void>;
14+
/**
15+
* Remove credentials for a given play.net account.
16+
*/
17+
sgeRemoveAccount: (options: {
18+
gameCode: string;
19+
username: string;
20+
}) => Promise<void>;
21+
/**
22+
* List saved play.net accounts.
23+
*/
24+
sgeListAccounts: (options: { gameCode: string }) => Promise<
25+
{
26+
gameCode: string;
27+
username: string;
28+
}[]
29+
>;
30+
/**
31+
* List available characters for a given play.net account.
32+
*/
33+
sgeListCharacters: (options: {
1234
gameCode: string;
35+
username: string;
1336
}) => Promise<
14-
Array<{
37+
{
1538
id: string;
1639
name: string;
17-
}>
40+
}[]
1841
>;
1942
/**
20-
* Log in to game with a given character.
43+
* Play the game with a given character.
44+
* This app can only play one character at a time.
45+
* Use the `onMessage` API to receive game data.
2146
*/
22-
sgePlayCharacter: (options: {
23-
username: string;
24-
password: string;
47+
gamePlayCharacter: (options: {
2548
gameCode: string;
49+
username: string;
2650
characterName: string;
2751
}) => Promise<void>;
52+
/**
53+
* Sends a command to the game as the currently playing character.
54+
* Use the `onMessage` API to receive game data.
55+
*/
56+
gameSendCommand: (command: string) => Promise<void>;
57+
/**
58+
* Allows the renderer to subscribe to messages from the main process.
59+
*/
60+
onMessage: (
61+
channel: string,
62+
callback: (event: Electron.IpcRendererEvent, ...args: any[]) => void
63+
) => void;
2864
};
2965
declare global {
3066
type TypeOfAppAPI = typeof appAPI;

electron/preload/index.ts

+62-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { IpcRendererEvent } from 'electron';
12
import { contextBridge, ipcRenderer } from 'electron';
23

34
/**
@@ -11,25 +12,78 @@ const appAPI = {
1112
return ipcRenderer.invoke('ping');
1213
},
1314
/**
14-
* List available characters for a given play.net account.
15+
* Add credentials for a given play.net account.
1516
*/
16-
sgeListCharacters: async (options: {
17+
sgeAddAccount: async (options: {
18+
gameCode: string;
1719
username: string;
1820
password: string;
21+
}): Promise<void> => {
22+
return ipcRenderer.invoke('sgeAddAccount', options);
23+
},
24+
/**
25+
* Remove credentials for a given play.net account.
26+
*/
27+
sgeRemoveAccount: async (options: {
1928
gameCode: string;
20-
}): Promise<Array<{ id: string; name: string }>> => {
21-
return ipcRenderer.invoke('sgeListCharacters', options);
29+
username: string;
30+
}): Promise<void> => {
31+
return ipcRenderer.invoke('sgeRemoveAccount', options);
2232
},
2333
/**
24-
* Log in to game with a given character.
34+
* List saved play.net accounts.
35+
*/
36+
sgeListAccounts: async (options: {
37+
gameCode: string;
38+
}): Promise<
39+
Array<{
40+
gameCode: string;
41+
username: string;
42+
}>
43+
> => {
44+
return ipcRenderer.invoke('sgeListAccounts', options);
45+
},
46+
/**
47+
* List available characters for a given play.net account.
2548
*/
26-
sgePlayCharacter: async (options: {
49+
sgeListCharacters: async (options: {
50+
gameCode: string;
2751
username: string;
28-
password: string;
52+
}): Promise<
53+
Array<{
54+
id: string;
55+
name: string;
56+
}>
57+
> => {
58+
return ipcRenderer.invoke('sgeListCharacters', options);
59+
},
60+
/**
61+
* Play the game with a given character.
62+
* This app can only play one character at a time.
63+
* Use the `onMessage` API to receive game data.
64+
*/
65+
gamePlayCharacter: async (options: {
2966
gameCode: string;
67+
username: string;
3068
characterName: string;
3169
}): Promise<void> => {
32-
return ipcRenderer.invoke('sgePlayCharacter', options);
70+
return ipcRenderer.invoke('gamePlayCharacter', options);
71+
},
72+
/**
73+
* Sends a command to the game as the currently playing character.
74+
* Use the `onMessage` API to receive game data.
75+
*/
76+
gameSendCommand: async (command: string): Promise<void> => {
77+
return ipcRenderer.invoke('gameSendCommand', command);
78+
},
79+
/**
80+
* Allows the renderer to subscribe to messages from the main process.
81+
*/
82+
onMessage: (
83+
channel: string,
84+
callback: (event: IpcRendererEvent, ...args: Array<any>) => void
85+
) => {
86+
ipcRenderer.on(channel, callback);
3387
},
3488
};
3589

0 commit comments

Comments
 (0)