-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
38 lines (33 loc) · 915 Bytes
/
main.js
File metadata and controls
38 lines (33 loc) · 915 Bytes
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
const { app, BrowserWindow } = require('electron');
const path = require('path');
// 创建浏览器窗口的函数
function createWindow() {
// 创建浏览器窗口
const win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'electron/preload.js'),
contextIsolation: true,
nodeIntegration: false,
},
});
// 加载Vite开发服务器
win.loadURL('http://localhost:3000');
}
// 应用就绪时创建窗口
app.whenReady().then(() => {
createWindow();
// macOS上,当点击dock图标且没有其他窗口打开时,重新创建一个窗口
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
// 关闭所有窗口时退出应用(macOS除外)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});