From 611ad57096a3b36001f80c2578941d69e7bf1307 Mon Sep 17 00:00:00 2001 From: Andy Merskin Date: Wed, 19 Jul 2017 11:20:16 -0600 Subject: [PATCH] add app menu --- src/main/index.js | 2 ++ src/main/menu.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/menu.js diff --git a/src/main/index.js b/src/main/index.js index 048b33c..9aecc12 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,6 +1,7 @@ import { app, BrowserWindow } from 'electron' import fs from 'fs-extra' import path from 'path' +import { setApplicationMenu } from './menu' /** * Set `__static` path to static files in production @@ -53,6 +54,7 @@ app.on('will-finish-launching', () => { }) app.on('ready', createWindow) +app.on('ready', setApplicationMenu) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { diff --git a/src/main/menu.js b/src/main/menu.js new file mode 100644 index 0000000..572970a --- /dev/null +++ b/src/main/menu.js @@ -0,0 +1,52 @@ +import { app, Menu } from 'electron' + +const aboutMenu = { + label: app.getName(), + submenu: [ + {role: 'about'}, + {type: 'separator'}, + {role: 'services', submenu: []}, + {type: 'separator'}, + {role: 'hide'}, + {role: 'hideothers'}, + {role: 'unhide'}, + {type: 'separator'}, + {role: 'quit'} + ] +} + +const editMenu = { + label: 'Edit', + submenu: [ + { role: 'undo' }, + { role: 'redo' }, + { type: 'separator' }, + { role: 'cut' }, + { role: 'copy' }, + { role: 'paste' }, + { role: 'selectall' } + ] +} + +const windowMenu = { + role: 'window', + submenu: [ + { role: 'close' }, + { role: 'minimize' }, + { role: 'zoom' }, + { type: 'separator' }, + { role: 'front' } + ] +} + +const template = [ + aboutMenu, + editMenu, + windowMenu, + { role: 'help', submenu: [] } +] + +export function setApplicationMenu() { + const menu = Menu.buildFromTemplate(template) + Menu.setApplicationMenu(menu) +} \ No newline at end of file