-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
43 lines (36 loc) · 1.18 KB
/
Copy pathmain.js
File metadata and controls
43 lines (36 loc) · 1.18 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
const { app, BrowserWindow } = require('electron');
const config = require('./config/dev');
// 保持一个对于 window 对象的全局引用,如果你不这样做,
// 当 JavaScript 对象被垃圾回收, window 会被自动地关闭
let win;
// 打开主窗口
function createWindow() {
// 创建浏览器窗口
win = new BrowserWindow({
width: 1280,
height: 960,
webPreferences: {
nodeIntegration: true, // https://newsn.net/say/electron-require-not-defined.html
},
});
// 加载应用的 index.html
const indexPageURL = `http://localhost:${config.port}/index.html`;
win.loadURL(indexPageURL);
win.webContents.openDevTools();
// 当 window 被关闭,这个事件会被触发
win.on('closed', () => {
// 取消引用 window 对象
win = null;
});
}
// Electron 会在创建浏览器窗口时调用这个函数。
app.on('ready', createWindow);
// 当全部窗口关闭时退出
app.on('window-all-closed', () => {
// 在 macOS 上,除非用户用 Cmd + Q 确定地退出
// 否则绝大部分应用会保持激活
if (process.platform !== 'darwin') {
app.quit();
}
});
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';