ZhangXianQiang
2024-06-25 a02473e11943579fa3ef4c2392624609d1475c0e
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { app, BrowserWindow, screen, globalShortcut, ipcMain } = require('electron');
const { join } = require('path');
 
// 屏蔽安全警告
// ectron Security Warning (Insecure Content-Security-Policy)
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
 
// 创建浏览器窗口时,调用这个函数。
const createWindow = (width, height) => {
    const win = new BrowserWindow({
        width: width,
        height: height,
        minWidth: 1280,
        minHeight: 720,
        webPreferences: {
            preload: join(__dirname, 'preload.js')
        }
    });
 
    win.maximize();
    // 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(() => {
    const { width, height } = screen.getPrimaryDisplay().bounds;
    createWindow(width, height);
    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow();
    });
 
    // 监听打开新窗口
    ipcMain.on('open-new-window', (event, meet) => {
        const { meetName, id } = JSON.parse(meet);
        const childWin = new BrowserWindow({
            width: width,
            height: height,
            minWidth: width,
            minHeight: height,
            webPreferences: {
                preload: join(__dirname, 'preload.js')
            }
        });
        childWin.maximize();
        // development模式
        if (process.env.VITE_DEV_SERVER_URL) {
            childWin.loadURL(process.env.VITE_DEV_SERVER_URL + '#/meet?' + `meetName=${meetName}&id=${id}`);
        } else {
            childWin.loadFile(join(__dirname, '../dist/index.html'), {
                hash: '/meet',
                query: {
                    meetName,
                    id
                }
            });
        }
    });
});
 
app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit();
});