-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
45 lines (41 loc) · 1.19 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
const path = require("path");
const { app, BrowserWindow } = require("electron");
require("@electron/remote/main").initialize();
if (require("electron-squirrel-startup")) {
app.quit();
}
const isDev = process.env.IS_DEV === "true";
function createWindow() {
const mainWindow = new BrowserWindow({
width: 1400,
height: 800,
frame: true,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true, // 如果为false,则不能访问 Node.js 模块
contextIsolation: false, // 如果为true,则需要在 preload 中使用 contextBridge
enableRemoteModule: true, //开启remote模块
},
});
require("@electron/remote/main").enable(mainWindow.webContents);
if (isDev) {
mainWindow.loadURL("http://localhost:3000");
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadFile(path.join("dist/index.html"));
// mainWindow.webContents.openDevTools();
}
}
app.whenReady().then(() => {
createWindow();
app.on("activate", function () {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.quit();
}
});