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