1
+ import type { IpcRendererEvent } from 'electron' ;
1
2
import { contextBridge , ipcRenderer } from 'electron' ;
2
3
3
4
/**
@@ -11,25 +12,78 @@ const appAPI = {
11
12
return ipcRenderer . invoke ( 'ping' ) ;
12
13
} ,
13
14
/**
14
- * List available characters for a given play.net account.
15
+ * Add credentials for a given play.net account.
15
16
*/
16
- sgeListCharacters : async ( options : {
17
+ sgeAddAccount : async ( options : {
18
+ gameCode : string ;
17
19
username : string ;
18
20
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 : {
19
28
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 ) ;
22
32
} ,
23
33
/**
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.
25
48
*/
26
- sgePlayCharacter : async ( options : {
49
+ sgeListCharacters : async ( options : {
50
+ gameCode : string ;
27
51
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 : {
29
66
gameCode : string ;
67
+ username : string ;
30
68
characterName : string ;
31
69
} ) : 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 ) ;
33
87
} ,
34
88
} ;
35
89
0 commit comments