Skip to content

Commit 5338db4

Browse files
committed
WIP
1 parent 91cb13b commit 5338db4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+591
-661
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
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'
27

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
129
const eventListeners = {}
1310

14-
const ElectronApi = {
11+
export const ElectronApi = {
1512
updateAppSettings(settings) {
1613
return ipcRenderer.invoke('update-app-settings', settings)
1714
},
1815
getActiveProfile() {
1916
return activeProfileId
2017
},
21-
updateActiveProfile(id) {
18+
updateActiveProfile(id: string) {
2219
activeProfileId = id
2320
},
24-
async renameProfileFolder(oldPath, newPath) {
21+
async renameProfileFolder(oldPath: string, newPath: string): Promise<void> {
2522
return ipcRenderer.invoke('get-path', 'userData').then((userDataPath) => {
2623
if (oldPath.startsWith(userDataPath)) {
2724
try {
@@ -32,7 +29,7 @@ const ElectronApi = {
3229
}
3330
})
3431
},
35-
async removeProfileFolder(profilePath) {
32+
async removeProfileFolder(profilePath): Promise<void> {
3633
return ipcRenderer.invoke('get-path', 'userData').then((userDataPath) => {
3734
// Check that the removing profile path matches the user data path
3835
// so that we don't try and remove things outside our scope
@@ -47,7 +44,7 @@ const ElectronApi = {
4744
}
4845
})
4946
},
50-
async listProfileFolders(profileStoragePath) {
47+
async listProfileFolders(profileStoragePath): Promise<void | string[]> {
5148
return ipcRenderer.invoke('get-path', 'userData').then((userDataPath) => {
5249
// Check that the profile path matches the user data path
5350
// so that we don't try and remove things outside our scope
@@ -68,7 +65,7 @@ const ElectronApi = {
6865
PincodeManager: PincodeManager,
6966
DeepLinkManager: DeepLinkManager,
7067
NotificationManager: NotificationManager,
71-
async getStrongholdBackupDestination(defaultPath) {
68+
async getStrongholdBackupDestination(defaultPath: string): Promise<null | string> {
7269
return ipcRenderer
7370
.invoke('show-save-dialog', {
7471
properties: ['createDirectory', 'showOverwriteConfirmation'],
@@ -83,7 +80,7 @@ const ElectronApi = {
8380
return result.filePath
8481
})
8582
},
86-
async exportTransactionHistory(defaultPath, contents) {
83+
async exportTransactionHistory(defaultPath, contents): Promise<null | string> {
8784
return ipcRenderer
8885
.invoke('show-save-dialog', {
8986
properties: ['createDirectory', 'showOverwriteConfirmation'],
@@ -105,16 +102,7 @@ const ElectronApi = {
105102
})
106103
},
107104

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 {
118106
return kdbx.checkFormat(buffer)
119107
},
120108
/**
@@ -124,7 +112,7 @@ const ElectronApi = {
124112
*
125113
* @returns {Promise}
126114
*/
127-
getUserDataPath() {
115+
getUserDataPath(): Promise<string> {
128116
return ipcRenderer.invoke('get-path', 'userData')
129117
},
130118
/**
@@ -134,7 +122,7 @@ const ElectronApi = {
134122
*
135123
* @returns {Promise}
136124
*/
137-
getDiagnostics() {
125+
getDiagnostics(): Promise<string> {
138126
return ipcRenderer.invoke('diagnostics')
139127
},
140128
/**
@@ -144,7 +132,7 @@ const ElectronApi = {
144132
*
145133
* @returns {Promise}
146134
*/
147-
getOS() {
135+
getOS(): Promise<string> {
148136
return ipcRenderer.invoke('get-os')
149137
},
150138
/**
@@ -154,57 +142,22 @@ const ElectronApi = {
154142
*
155143
* @returns {Promise}
156144
*/
157-
getMachineId() {
145+
getMachineId(): Promise<string> {
158146
return ipcRenderer.invoke('get-machine-id')
159147
},
160-
/**
161-
* Starts an update of the application
162-
*
163-
* @method updateDownload
164-
*
165-
* @returns void
166-
*/
167-
updateDownload() {
148+
updateDownload(): Promise<void> {
168149
return ipcRenderer.invoke('update-download')
169150
},
170-
/**
171-
* Cancels an update of the application
172-
*
173-
* @method updateCancel
174-
*
175-
* @returns void
176-
*/
177-
updateCancel() {
151+
updateCancel(): Promise<void> {
178152
return ipcRenderer.invoke('update-cancel')
179153
},
180-
/**
181-
* Install an update of the application
182-
*
183-
* @method updateInstall
184-
*
185-
* @returns void
186-
*/
187-
updateInstall() {
154+
updateInstall(): Promise<void> {
188155
return ipcRenderer.invoke('update-install')
189156
},
190-
/**
191-
* Check for an update of the application
192-
*
193-
* @method updateCheck
194-
*
195-
* @returns void
196-
*/
197-
updateCheck() {
157+
updateCheck(): Promise<void> {
198158
return ipcRenderer.invoke('update-check')
199159
},
200-
/**
201-
* Get version details
202-
*
203-
* @method getVersionDetails
204-
*
205-
* @returns void
206-
*/
207-
getVersionDetails() {
160+
getVersionDetails(): Promise<void> {
208161
return ipcRenderer.invoke('get-version-details')
209162
},
210163
/**
@@ -220,58 +173,38 @@ const ElectronApi = {
220173
})
221174
}
222175
},
223-
/**
224-
* Show the popup menu
225-
* @returns {undefined}
226-
*/
227-
popupMenu() {
176+
popupMenu(): Promise<void> {
228177
return ipcRenderer.invoke('menu-popup')
229178
},
230-
/**
231-
* Minimize the app
232-
* @returns {undefined}
233-
*/
234-
minimize() {
179+
minimize(): Promise<void> {
235180
return ipcRenderer.invoke('minimize')
236181
},
237-
/**
238-
* Maximize the app
239-
* @returns {undefined}
240-
*/
241-
maximize() {
182+
maximize(): Promise<void> {
242183
return ipcRenderer.invoke('maximize')
243184
},
244-
/**
245-
* Is the app maximized
246-
* @returns {boolean}
247-
*/
248-
isMaximized() {
185+
isMaximized(): Promise<boolean> {
249186
return ipcRenderer.invoke('isMaximized')
250187
},
251-
/**
252-
* Close the app
253-
* @returns {undefined}
254-
*/
255-
close() {
188+
close(): Promise<void> {
256189
return ipcRenderer.invoke('close')
257190
},
258191
/*
259192
* Opens url and checks against acceptlist
260193
* @param {string} url - Target url
261-
* @returns {undefined}
194+
* @returns {Promise<void>}
262195
*/
263-
openUrl(url) {
196+
openUrl(url: string): Promise<void> {
264197
return ipcRenderer.invoke('open-url', url)
265198
},
266-
copyFile(sourceFilePath, destinationFilePath) {
199+
copyFile(sourceFilePath: string, destinationFilePath: string): Promise<void> {
267200
return ipcRenderer.invoke('copy-file', sourceFilePath, destinationFilePath)
268201
},
269202
/**
270203
* Log unhandled exception
271204
* @param {string} errorType The type of eerror
272205
* @param {Errir} error The error
273206
*/
274-
unhandledException(errorType, error) {
207+
unhandledException(errorType: string, error: Error): Promise<void> {
275208
return ipcRenderer.invoke('handle-error', errorType, error)
276209
},
277210
/**
@@ -280,7 +213,7 @@ const ElectronApi = {
280213
* @param {function} callback - Event trigger callback
281214
* @returns {undefined}
282215
*/
283-
onEvent(event, callback) {
216+
onEvent(event: string, callback: () => unknown) {
284217
let listeners = eventListeners[event]
285218
if (!listeners) {
286219
listeners = eventListeners[event] = []
@@ -299,15 +232,15 @@ const ElectronApi = {
299232
* @param {function} callback - Event trigger callback
300233
* @returns {undefined}
301234
*/
302-
removeListenersForEvent(event) {
235+
removeListenersForEvent(event: string): void {
303236
eventListeners[event] = []
304-
return ipcRenderer.removeAllListeners(event)
237+
return void ipcRenderer.removeAllListeners(event)
305238
},
306239
/**
307240
* Save the recovery kit
308241
* @returns
309242
*/
310-
async saveRecoveryKit(recoverKitData) {
243+
async saveRecoveryKit(recoveryKitData: ArrayBuffer): Promise<void> {
311244
return ipcRenderer
312245
.invoke('show-save-dialog', {
313246
properties: ['createDirectory', 'showOverwriteConfirmation'],
@@ -323,7 +256,7 @@ const ElectronApi = {
323256
}
324257

325258
try {
326-
fs.writeFileSync(result.filePath, Buffer.from(recoverKitData))
259+
fs.writeFileSync(result.filePath, Buffer.from(recoveryKitData))
327260
} catch (err) {
328261
console.error(err)
329262
}
@@ -335,5 +268,3 @@ const ElectronApi = {
335268
*/
336269
hookErrorLogger,
337270
}
338-
339-
module.exports = ElectronApi

packages/desktop/electron/lib/aboutPreload.js

-16
This file was deleted.

packages/desktop/electron/lib/appUpdater.js

-72
This file was deleted.

0 commit comments

Comments
 (0)