ZhangXianQiang
2024-05-31 4caa4e8a6aa0f85f8d94e22c55076446e756c935
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
// src-electron/main.js
const { app, BrowserWindow } = require('electron');
const { join } = require('path');
 
// 屏蔽安全警告
// ectron Security Warning (Insecure Content-Security-Policy)
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
 
// 创建浏览器窗口时,调用这个函数。
const createWindow = () => {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
    });
 
    // win.loadURL('http://localhost:3000')
    // development模式
    if (process.env.VITE_DEV_SERVER_URL) {
        win.loadURL(process.env.VITE_DEV_SERVER_URL);
        // 开启调试台
        win.webContents.openDevTools();
    } else {
        win.loadFile(join(__dirname, '../dist/index.html'));
    }
};
 
// Electron 会在初始化后并准备
app.whenReady().then(() => {
    createWindow();
    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow();
    });
});
 
app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit();
});