const path = require('path') const { app, BrowserWindow,ipcMain } = require('electron') // 主进程 const createWindow = () => { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { // dirname当前入口文件的绝对物理路径+相对路径 preload: path.resolve(__dirname, './preload.js') } }) win.loadFile('./index.html') // win.loadURL('./index.html') // 打开开发者工具 win.webContents.openDevTools() app.on('activate', () => { if (BrowserWindow.getAllWindows().length == 0) { createWindow() } }) }
app.on('window-all-closed', () => { if (process.platform == 'darwin') { app.quit() } }) // 监听只有一次,不能每次窗口打开就再次监听吧 ipcMain.handle('send-event',(event,msg)=>{ console.log(msg) })
app.whenReady().then(createWindow)
|