| | |
| | | // src-electron/main.js |
| | | const { app, BrowserWindow,screen } = require('electron'); |
| | | const { app, BrowserWindow, screen, globalShortcut, ipcMain } = require('electron'); |
| | | const { join } = require('path'); |
| | | |
| | | // 屏蔽安全警告 |
| | |
| | | process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'; |
| | | |
| | | // 创建浏览器窗口时,调用这个函数。 |
| | | const createWindow = () => { |
| | | const {width, height} = screen.getPrimaryDisplay().bounds; |
| | | const createWindow = (width, height) => { |
| | | const win = new BrowserWindow({ |
| | | width: width, |
| | | height: height, |
| | | minWidth: 1280, |
| | | minHeight: 720, |
| | | webPreferences: { |
| | | preload: join(__dirname, 'preload.js') |
| | | } |
| | | }); |
| | | |
| | | // win.loadURL('http://localhost:3000') |
| | | win.maximize(); |
| | | // development模式 |
| | | if (process.env.VITE_DEV_SERVER_URL) { |
| | | win.loadURL(process.env.VITE_DEV_SERVER_URL); |
| | |
| | | |
| | | // Electron 会在初始化后并准备 |
| | | app.whenReady().then(() => { |
| | | createWindow(); |
| | | const { width, height } = screen.getPrimaryDisplay().bounds; |
| | | createWindow(width, height); |
| | | app.on('activate', () => { |
| | | if (BrowserWindow.getAllWindows().length === 0) createWindow(); |
| | | }); |
| | | |
| | | // 监听打开新窗口 |
| | | ipcMain.on('open-new-window', () => { |
| | | 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'); |
| | | } else { |
| | | childWin.loadFile(join(__dirname, '../dist/index.html'), { |
| | | hash: '/meet' |
| | | }); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | app.on('window-all-closed', () => { |
| | | if (process.platform !== 'darwin') app.quit(); |
| | | }); |
| | | |
| | | |
| | | |