const electron = require('electron') // Module to control application life. const { app, Menu, dialog } = electron // Module to create native browser window. const { BrowserWindow } = electron // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let win const template = [ { label: '功能', submenu: [ { label: '地图编辑', accelerator: 'CmdOrCtrl+1', click() { console.log('地图编辑') win.loadURL('https://test.kingsome.cn/html/shoot_editor/index.html') } }, { label: '配置管理', accelerator: 'CmdOrCtrl+2', click() { console.log('配置管理') win.loadURL('https://test.kingsome.cn/html/cfgtool/index.html') } } ] }, { label: '选项', submenu: [ { label: '重新加载', role: 'reload' }, { label: '强制刷新', role: 'forceReload' }, { label: '全屏切换', role: 'togglefullscreen' }, { label: '开发者工具', role: 'toggleDevTools' } ] } ] function createWindow() { // Create the browser window. win = new BrowserWindow({ width: 1290, height: 940, webPreferences: { nodeIntegration: true, webSecurity: false, enableRemoteModule: true } }) // and load the index.html of the app. // http://h5tools.client.jy/index.html // win.loadURL('http://localhost:8080/#/index') win.loadURL('https://test.kingsome.cn/html/cfgtool/index.html') // win.loadFile('./index.html') // Open the DevTools. // win.webContents.openDevTools(); win.webContents.on('did-finish-load', () => { win.webContents.send('ping', 'whoooooooh!') }) // Emitted when the window is closed. win.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. win = null }) if (process.platform === 'darwin') { template.unshift({ label: app.getName(), submenu: [ { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click() { app.quit() } } ] }) } const appMenu = Menu.buildFromTemplate(template) Menu.setApplicationMenu(appMenu) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow) // Quit when all windows are closed. app.on('window-all-closed', () => { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (win === null) { createWindow() } })