Skip to content

Commit a2cdf79

Browse files
committed
Improve preload readability
1 parent 1132c65 commit a2cdf79

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/preload.cts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { contextBridge, ipcRenderer } from 'electron';
1+
import * as electron from 'electron';
2+
const {
3+
contextBridge,
4+
ipcRenderer: { invoke: ipcInvoke }
5+
} = electron;
26

37
import type { ContextMenuDefinition } from './context-menu.ts';
48

@@ -12,16 +16,13 @@ let authToken: string | undefined;
1216
let deviceInfo: {} | undefined;
1317

1418
const preloadPromise = Promise.all([
15-
ipcRenderer.invoke('get-desktop-version').then(result => {
16-
desktopVersion = result;
17-
}),
18-
ipcRenderer.invoke('get-server-auth-token').then(result => {
19-
authToken = result;
20-
}),
19+
ipcInvoke('get-desktop-version')
20+
.then(result => { desktopVersion = result; }),
21+
ipcInvoke('get-server-auth-token')
22+
.then(result => { authToken = result; }),
2123
Promise.race([
22-
ipcRenderer.invoke('get-device-info').then(result => {
23-
deviceInfo = result;
24-
}),
24+
ipcInvoke('get-device-info')
25+
.then(result => { deviceInfo = result; }),
2526
// Give up after 500m - might complete later, but we don't
2627
// want to block 'API ready' for this info.
2728
new Promise((resolve) => setTimeout(resolve, 500))
@@ -36,15 +37,15 @@ contextBridge.exposeInMainWorld('desktopApi', {
3637
getDeviceInfo: () => deviceInfo,
3738

3839
selectApplication: () =>
39-
ipcRenderer.invoke('select-application'),
40+
ipcInvoke('select-application'),
4041
selectFilePath: () =>
41-
ipcRenderer.invoke('select-file-path'),
42+
ipcInvoke('select-file-path'),
4243
selectSaveFilePath: () =>
43-
ipcRenderer.invoke('select-save-file-path'),
44+
ipcInvoke('select-save-file-path'),
4445

4546
openContextMenu: (options: ContextMenuDefinition) =>
46-
ipcRenderer.invoke('open-context-menu', options),
47+
ipcInvoke('open-context-menu', options),
4748

4849
restartApp: () =>
49-
ipcRenderer.invoke('restart-app')
50+
ipcInvoke('restart-app')
5051
});

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"noUnusedLocals": true,
1313
"noImplicitThis": true,
1414
"noUnusedParameters": true,
15-
"importHelpers": true,
16-
"noEmitHelpers": true,
15+
"importHelpers": false,
16+
"noEmitHelpers": false,
1717
"module": "node20",
1818
"moduleResolution": "nodenext",
1919
"rewriteRelativeImportExtensions": true,

0 commit comments

Comments
 (0)