const { app, BrowserWindow, session } = require('electron') const path = require('path') const devServerUrl = process.env.ELECTRON_RENDERER_URL const rendererEntry = path.join(__dirname, '..', 'dist', 'build', 'h5', 'index.html') if (devServerUrl) { app.commandLine.appendSwitch('disable-http-cache') } function createWindow() { const win = new BrowserWindow({ width: 1200, height: 800, webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, nodeIntegration: false, }, }) if (devServerUrl) { win.webContents.session.clearCache().catch(() => {}) win.loadURL(devServerUrl) win.webContents.openDevTools({ mode: 'detach' }) return } win.loadFile(rendererEntry) } function setupMediaPermissions() { const ses = session.defaultSession if (!ses) { return } const mediaPermissions = new Set(['media', 'videoCapture', 'audioCapture', 'camera', 'microphone']) ses.setPermissionCheckHandler((webContents, permission) => { if (mediaPermissions.has(permission)) { return true } return false }) ses.setPermissionRequestHandler((webContents, permission, callback) => { callback(mediaPermissions.has(permission)) }) if (typeof ses.setDevicePermissionHandler === 'function') { ses.setDevicePermissionHandler((details) => { return details.deviceType === 'videoCapture' || details.deviceType === 'audioCapture' }) } } app.whenReady().then(() => { setupMediaPermissions() createWindow() app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() } }) }) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } })