-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
30 lines (27 loc) · 840 Bytes
/
preload.js
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
// Preload (Isolated World)
const { contextBridge, ipcRenderer } = require('electron');
const remote = require('@electron/remote');
const fs = require('fs');
const path = require('path');
// const ElectronStore = require('electron-store');
// console.log('4543645', new ElectronStore());
// ElectronStore.initRenderer();
// 新版本api更改了: exposeInIsolatedWorld => exposeInMainWorld
contextBridge.exposeInMainWorld('electron', {
doThing: () => ipcRenderer.send('do-a-thing'), // demo
fs,
path,
ipcRenderer,
remote,
aa: {},
store: {
get(key) {
return ipcRenderer.sendSync('electron-store-get', key);
},
set(property, val) {
ipcRenderer.send('electron-store-set', property, val);
},
// Other method you want to add like has(), reset(), etc.
},
// store: new ElectronStore(),
});