const { BrowserWindow,Menu,globalShortcut } = require('electron') const path = require('path') const { MANUAL_CREATED_FLAG } = require('../../constant') // 引入初始化remote模块 const remote = require('@electron/remote/main') remote.initialize() function createWindow(url,options,node=false) { Menu.setApplicationMenu(null); const window = new BrowserWindow({ // width: 870, // height: 530, webPreferences: { webSecurity: false, contextIsolation: false, enableRemoteModule:true, nodeIntegration: node, preload: path.join(__dirname, 'preload.js') }, ...options }) window[MANUAL_CREATED_FLAG] = true console.log('openWindow', url) window.loadURL(url) // 清除缓存 const ses = window.webContents.session ses.clearCache() // 启用remote模块 remote.enable(window.webContents) // 注册快捷键 window.on('focus', () => { globalShortcut.register('CommandOrControl+Alt+F', function () { window && window.webContents.toggleDevTools(); }) }); window.on('blur', () => { globalShortcut.unregisterAll() // 注销键盘事件 }) // window.webContents.openDevTools() // Open the DevTools. return window } module.exports = { createWindow }