// npm start const { app,Menu, BrowserWindow } = require('electron') const path = require('path') const {menuRebuild} = require('./src/comment/TopMenu.js') const createWindow = () => { // Create the browser window. const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration:true, // 启用后nodeIntegration会无效 contextIsolation:false, preload: path.join(__dirname, 'preload.js') } }) // 加载 index.html // win.loadFile('./public/index.html') win.loadURL('http://localhost:3000') // 打开开发工具 win.webContents.openDevTools() win.webContents.on('before-input-event', (event, input) => { // if (input.control && input.key.toLowerCase() === 's') { // console.log('Pressed Control+s') // event.preventDefault() // } console.log('Pressed ',input.key) if (input.key==='f5'){ console.log('Pressed f5') win.reload() } }) Menu.setApplicationMenu(Menu.buildFromTemplate(menuRebuild(win))) } // 这段程序将会在 Electron 结束初始化和创建浏览器窗口的时候调用 // 部分 API 在 ready 事件触发后才能使用。 app.whenReady().then(() => { createWindow() // 在 macOS 系统内, 如果没有已开启的应用窗口 // 点击托盘图标时通常会重新创建一个新窗口 app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) // 除了 macOS 外,当所有窗口都被关闭的时候退出程序。 因此, 通常 // 对应用程序和它们的菜单栏来说应该时刻保持激活状态, // 直到用户使用 Cmd + Q 明确退出 app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit() })