// import {enableLiveReload} from 'electron-compile'; // // enableLiveReload(); const {app, BrowserWindow, Menu} = require('electron') let win app.on('ready', () => { // Create the browser window. if (process.platform === 'darwin') { win = new BrowserWindow({ width: 800, height: 600, frame: 'false', titleBarStyle: 'hiddenInset', show: false }) } else { win = new BrowserWindow({ width: 800, height: 600, frame: false, show: false }) } win.once('ready-to-show', () => { win.show() }) // and load the index.html of the app. win.loadFile('index.html') // 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 }) setMainMenu(); }); // 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. // Quit when all windows are closed. app.on('window-all-closed', () => { // On macOS 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 macOS 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() } }) function setMainMenu() { const template = [ { label: 'Edit', submenu: [ { role: 'undo' }, { role: 'redo' }, { type: 'separator' }, { role: 'cut' }, { role: 'copy' }, { role: 'paste' }, { role: 'pasteandmatchstyle' }, { role: 'delete' }, { role: 'selectall' } ] }, { label: 'View', submenu: [ { role: 'togglefullscreen' }, { label: 'Developer', submenu: [ { role: 'reload' }, { role: 'forcereload' }, { role: 'toggledevtools' }, ] }, ] }, { role: 'window', submenu: [ { role: 'minimize' }, { role: 'close' } ] }, { role: 'help', submenu: [ { label: 'Learn More', click () { shell.openExternal('https://electron.atom.io') } }, { label: 'Documentation', click () { shell.openExternal( `https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme` ) } }, { label: 'Community Discussions', click () { shell.openExternal('https://discuss.atom.io/c/electron') } }, { label: 'Search Issues', click () { shell.openExternal('https://github.com/electron/electron/issues') } } ] } ] if (process.platform === 'darwin') { template.unshift({ label: 'Electron', submenu: [ { role: 'about' }, { type: 'separator' }, { role: 'services', submenu: [] }, { type: 'separator' }, { role: 'hide' }, { role: 'hideothers' }, { role: 'unhide' }, { type: 'separator' }, { role: 'quit' } ] }) template[1].submenu.push( { type: 'separator' }, { label: 'Speech', submenu: [ { role: 'startspeaking' }, { role: 'stopspeaking' } ] } ) template[3].submenu = [ { role: 'close' }, { role: 'minimize' }, { type: 'separator' }, { role: 'front' } ] } else { template.unshift({ label: 'File', submenu: [ { role: 'quit' } ] }) } Menu.setApplicationMenu(Menu.buildFromTemplate(template)); }