-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
49 lines (41 loc) · 1.7 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// eslint-disable-next-line import/no-extraneous-dependencies
// const ElectronStore = require('electron-store');
// // ElectronStore.initRenderer();
// const store = new ElectronStore();
// store.set('test', 666);
// console.log('09789087init', store.get('test'));
// eslint-disable-next-line import/no-extraneous-dependencies
const isDev = require('electron-is-dev');
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const Store = require('electron-store');
const store = new Store();
// IPC listener => https://electron-react-boilerplate.js.org/docs/electron-store
ipcMain.on('electron-store-get', async (event, val) => {
event.returnValue = store.get(val);
});
ipcMain.on('electron-store-set', async (event, key, val) => {
store.set(key, val);
});
app.on('ready', () => {
const mainWindow = new BrowserWindow({
height: 600,
width: 800,
webPreferences: {
// webSecurity: false,
nodeIntegration: true,
// ontextBridge API can only be used when contextIsolation is enabled
// contextIsolation: false,
contextIsolation: true, // actually, it's a default value,but here i type it clearly
enableRemoteModule: true, // 使用remote模块,这一行实际上貌似可以胜利
preload: path.join(__dirname, 'preload.js'),
},
});
// eslint-disable-next-line global-require
require('@electron/remote/main').initialize();
// eslint-disable-next-line global-require
require('@electron/remote/main').enable(mainWindow.webContents);
// mainWindow.webContents.openDevTools(); // 调试工具
const url = isDev ? 'http://localhost:3000/' : 'dummy'; // dummy 占位,todo,生产环境先不管
mainWindow.loadURL(url);
});