1
- const { ipcRenderer } = require ( 'electron' )
1
+ import { ipcRenderer } from 'electron'
2
+ import fs from 'fs'
3
+ import { PincodeManager , DeepLinkManager , NotificationManager } from './lib/managers'
4
+ import { kdbx } from './lib'
5
+ import { menuState } from './lib/menu'
6
+ import { hookErrorLogger } from 'shared/lib/shell/errorLogger'
2
7
3
- const fs = require ( 'fs' )
4
- const PincodeManager = require ( './lib/pincodeManager' )
5
- const DeepLinkManager = require ( './lib/deepLinkManager' )
6
- const NotificationManager = require ( './lib/notificationManager' )
7
- const { menuState } = require ( './lib/menuState' )
8
- const kdbx = require ( './lib/kdbx' )
9
- const { hookErrorLogger } = require ( 'shared/lib/shell/errorLogger' )
10
-
11
- let activeProfileId = null
8
+ let activeProfileId : string | null = null
12
9
const eventListeners = { }
13
10
14
- const ElectronApi = {
11
+ export const ElectronApi = {
15
12
updateAppSettings ( settings ) {
16
13
return ipcRenderer . invoke ( 'update-app-settings' , settings )
17
14
} ,
18
15
getActiveProfile ( ) {
19
16
return activeProfileId
20
17
} ,
21
- updateActiveProfile ( id ) {
18
+ updateActiveProfile ( id : string ) {
22
19
activeProfileId = id
23
20
} ,
24
- async renameProfileFolder ( oldPath , newPath ) {
21
+ async renameProfileFolder ( oldPath : string , newPath : string ) : Promise < void > {
25
22
return ipcRenderer . invoke ( 'get-path' , 'userData' ) . then ( ( userDataPath ) => {
26
23
if ( oldPath . startsWith ( userDataPath ) ) {
27
24
try {
@@ -32,7 +29,7 @@ const ElectronApi = {
32
29
}
33
30
} )
34
31
} ,
35
- async removeProfileFolder ( profilePath ) {
32
+ async removeProfileFolder ( profilePath ) : Promise < void > {
36
33
return ipcRenderer . invoke ( 'get-path' , 'userData' ) . then ( ( userDataPath ) => {
37
34
// Check that the removing profile path matches the user data path
38
35
// so that we don't try and remove things outside our scope
@@ -47,7 +44,7 @@ const ElectronApi = {
47
44
}
48
45
} )
49
46
} ,
50
- async listProfileFolders ( profileStoragePath ) {
47
+ async listProfileFolders ( profileStoragePath ) : Promise < void | string [ ] > {
51
48
return ipcRenderer . invoke ( 'get-path' , 'userData' ) . then ( ( userDataPath ) => {
52
49
// Check that the profile path matches the user data path
53
50
// so that we don't try and remove things outside our scope
@@ -68,7 +65,7 @@ const ElectronApi = {
68
65
PincodeManager : PincodeManager ,
69
66
DeepLinkManager : DeepLinkManager ,
70
67
NotificationManager : NotificationManager ,
71
- async getStrongholdBackupDestination ( defaultPath ) {
68
+ async getStrongholdBackupDestination ( defaultPath : string ) : Promise < null | string > {
72
69
return ipcRenderer
73
70
. invoke ( 'show-save-dialog' , {
74
71
properties : [ 'createDirectory' , 'showOverwriteConfirmation' ] ,
@@ -83,7 +80,7 @@ const ElectronApi = {
83
80
return result . filePath
84
81
} )
85
82
} ,
86
- async exportTransactionHistory ( defaultPath , contents ) {
83
+ async exportTransactionHistory ( defaultPath , contents ) : Promise < null | string > {
87
84
return ipcRenderer
88
85
. invoke ( 'show-save-dialog' , {
89
86
properties : [ 'createDirectory' , 'showOverwriteConfirmation' ] ,
@@ -105,16 +102,7 @@ const ElectronApi = {
105
102
} )
106
103
} ,
107
104
108
- /**
109
- * Validates Seed Vault
110
- *
111
- * @method validateSeedVault
112
- *
113
- * @param {Buffer } buffer
114
- *
115
- * @returns {boolean }
116
- */
117
- validateSeedVault ( buffer ) {
105
+ validateSeedVault ( buffer : Buffer ) : boolean {
118
106
return kdbx . checkFormat ( buffer )
119
107
} ,
120
108
/**
@@ -124,7 +112,7 @@ const ElectronApi = {
124
112
*
125
113
* @returns {Promise }
126
114
*/
127
- getUserDataPath ( ) {
115
+ getUserDataPath ( ) : Promise < string > {
128
116
return ipcRenderer . invoke ( 'get-path' , 'userData' )
129
117
} ,
130
118
/**
@@ -134,7 +122,7 @@ const ElectronApi = {
134
122
*
135
123
* @returns {Promise }
136
124
*/
137
- getDiagnostics ( ) {
125
+ getDiagnostics ( ) : Promise < string > {
138
126
return ipcRenderer . invoke ( 'diagnostics' )
139
127
} ,
140
128
/**
@@ -144,7 +132,7 @@ const ElectronApi = {
144
132
*
145
133
* @returns {Promise }
146
134
*/
147
- getOS ( ) {
135
+ getOS ( ) : Promise < string > {
148
136
return ipcRenderer . invoke ( 'get-os' )
149
137
} ,
150
138
/**
@@ -154,57 +142,22 @@ const ElectronApi = {
154
142
*
155
143
* @returns {Promise }
156
144
*/
157
- getMachineId ( ) {
145
+ getMachineId ( ) : Promise < string > {
158
146
return ipcRenderer . invoke ( 'get-machine-id' )
159
147
} ,
160
- /**
161
- * Starts an update of the application
162
- *
163
- * @method updateDownload
164
- *
165
- * @returns void
166
- */
167
- updateDownload ( ) {
148
+ updateDownload ( ) : Promise < void > {
168
149
return ipcRenderer . invoke ( 'update-download' )
169
150
} ,
170
- /**
171
- * Cancels an update of the application
172
- *
173
- * @method updateCancel
174
- *
175
- * @returns void
176
- */
177
- updateCancel ( ) {
151
+ updateCancel ( ) : Promise < void > {
178
152
return ipcRenderer . invoke ( 'update-cancel' )
179
153
} ,
180
- /**
181
- * Install an update of the application
182
- *
183
- * @method updateInstall
184
- *
185
- * @returns void
186
- */
187
- updateInstall ( ) {
154
+ updateInstall ( ) : Promise < void > {
188
155
return ipcRenderer . invoke ( 'update-install' )
189
156
} ,
190
- /**
191
- * Check for an update of the application
192
- *
193
- * @method updateCheck
194
- *
195
- * @returns void
196
- */
197
- updateCheck ( ) {
157
+ updateCheck ( ) : Promise < void > {
198
158
return ipcRenderer . invoke ( 'update-check' )
199
159
} ,
200
- /**
201
- * Get version details
202
- *
203
- * @method getVersionDetails
204
- *
205
- * @returns void
206
- */
207
- getVersionDetails ( ) {
160
+ getVersionDetails ( ) : Promise < void > {
208
161
return ipcRenderer . invoke ( 'get-version-details' )
209
162
} ,
210
163
/**
@@ -220,58 +173,38 @@ const ElectronApi = {
220
173
} )
221
174
}
222
175
} ,
223
- /**
224
- * Show the popup menu
225
- * @returns {undefined }
226
- */
227
- popupMenu ( ) {
176
+ popupMenu ( ) : Promise < void > {
228
177
return ipcRenderer . invoke ( 'menu-popup' )
229
178
} ,
230
- /**
231
- * Minimize the app
232
- * @returns {undefined }
233
- */
234
- minimize ( ) {
179
+ minimize ( ) : Promise < void > {
235
180
return ipcRenderer . invoke ( 'minimize' )
236
181
} ,
237
- /**
238
- * Maximize the app
239
- * @returns {undefined }
240
- */
241
- maximize ( ) {
182
+ maximize ( ) : Promise < void > {
242
183
return ipcRenderer . invoke ( 'maximize' )
243
184
} ,
244
- /**
245
- * Is the app maximized
246
- * @returns {boolean }
247
- */
248
- isMaximized ( ) {
185
+ isMaximized ( ) : Promise < boolean > {
249
186
return ipcRenderer . invoke ( 'isMaximized' )
250
187
} ,
251
- /**
252
- * Close the app
253
- * @returns {undefined }
254
- */
255
- close ( ) {
188
+ close ( ) : Promise < void > {
256
189
return ipcRenderer . invoke ( 'close' )
257
190
} ,
258
191
/*
259
192
* Opens url and checks against acceptlist
260
193
* @param {string } url - Target url
261
- * @returns {undefined }
194
+ * @returns {Promise<void> }
262
195
*/
263
- openUrl ( url ) {
196
+ openUrl ( url : string ) : Promise < void > {
264
197
return ipcRenderer . invoke ( 'open-url' , url )
265
198
} ,
266
- copyFile ( sourceFilePath , destinationFilePath ) {
199
+ copyFile ( sourceFilePath : string , destinationFilePath : string ) : Promise < void > {
267
200
return ipcRenderer . invoke ( 'copy-file' , sourceFilePath , destinationFilePath )
268
201
} ,
269
202
/**
270
203
* Log unhandled exception
271
204
* @param {string } errorType The type of eerror
272
205
* @param {Errir } error The error
273
206
*/
274
- unhandledException ( errorType , error ) {
207
+ unhandledException ( errorType : string , error : Error ) : Promise < void > {
275
208
return ipcRenderer . invoke ( 'handle-error' , errorType , error )
276
209
} ,
277
210
/**
@@ -280,7 +213,7 @@ const ElectronApi = {
280
213
* @param {function } callback - Event trigger callback
281
214
* @returns {undefined }
282
215
*/
283
- onEvent ( event , callback ) {
216
+ onEvent ( event : string , callback : ( ) => unknown ) {
284
217
let listeners = eventListeners [ event ]
285
218
if ( ! listeners ) {
286
219
listeners = eventListeners [ event ] = [ ]
@@ -299,15 +232,15 @@ const ElectronApi = {
299
232
* @param {function } callback - Event trigger callback
300
233
* @returns {undefined }
301
234
*/
302
- removeListenersForEvent ( event ) {
235
+ removeListenersForEvent ( event : string ) : void {
303
236
eventListeners [ event ] = [ ]
304
- return ipcRenderer . removeAllListeners ( event )
237
+ return void ipcRenderer . removeAllListeners ( event )
305
238
} ,
306
239
/**
307
240
* Save the recovery kit
308
241
* @returns
309
242
*/
310
- async saveRecoveryKit ( recoverKitData ) {
243
+ async saveRecoveryKit ( recoveryKitData : ArrayBuffer ) : Promise < void > {
311
244
return ipcRenderer
312
245
. invoke ( 'show-save-dialog' , {
313
246
properties : [ 'createDirectory' , 'showOverwriteConfirmation' ] ,
@@ -323,7 +256,7 @@ const ElectronApi = {
323
256
}
324
257
325
258
try {
326
- fs . writeFileSync ( result . filePath , Buffer . from ( recoverKitData ) )
259
+ fs . writeFileSync ( result . filePath , Buffer . from ( recoveryKitData ) )
327
260
} catch ( err ) {
328
261
console . error ( err )
329
262
}
@@ -335,5 +268,3 @@ const ElectronApi = {
335
268
*/
336
269
hookErrorLogger,
337
270
}
338
-
339
- module . exports = ElectronApi
0 commit comments