-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
49 lines (41 loc) · 1.6 KB
/
Copy pathpreload.js
File metadata and controls
49 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
send: (channel, data) => ipcRenderer.send(channel, data),
on: (channel, func) => ipcRenderer.on(channel, (event, ...args) => func(...args))
}
});
contextBridge.exposeInMainWorld('electronAPI', {
getAppVersion: () => ipcRenderer.invoke('get-app-version'),
exportWorkspace: (workspace) => ipcRenderer.invoke('export-workspace', workspace),
importWorkspace: () => ipcRenderer.invoke('import-workspace'),
loadExample: (exampleName) => ipcRenderer.invoke('load-example', exampleName),
onImportExample: (callback) => {
ipcRenderer.on('import-example', async (_event, exampleName) => {
const data = await ipcRenderer.invoke('load-example', exampleName);
callback(data);
});
},
onThemeChange: (callback) => {
ipcRenderer.on('set-theme', (_event, theme) => {
callback(theme);
});
},
focusFix: () => ipcRenderer.send('focus-fix')
});
contextBridge.executeInMainWorld({
func: () => {
const originalAlert = window.alert;
const originalConfirm = window.confirm;
window.alert = function (message) {
const result = originalAlert(message);
window.electronAPI?.focusFix();
return result;
};
window.confirm = function (message) {
const result = originalConfirm(message);
window.electronAPI?.focusFix();
return result;
};
}
});