diff --git a/src/MenuTemplate.ts b/src/MenuTemplate.ts new file mode 100644 index 0000000..0bfcb84 --- /dev/null +++ b/src/MenuTemplate.ts @@ -0,0 +1,67 @@ +import { Menu, app } from 'electron' + +const applicationMenu = { + label: 'Application', + submenu: [ + { + label: 'About Application', + selector: 'orderFrontStandardAboutPanel:', + }, + { + type: 'separator' as 'separator', + }, + { + label: 'Quit', + accelerator: 'Command+Q', + click: () => { + app.quit() + }, + }, + ], +} + +const editMenu = { + label: 'Edit', + submenu: [ + { + label: 'Undo', + accelerator: 'CmdOrCtrl+Z', + selector: 'undo:', + }, + { + label: 'Redo', + accelerator: 'Shift+CmdOrCtrl+Z', + selector: 'redo:', + }, + { + type: 'separator' as 'separator', + }, + { + label: 'Cut', + accelerator: 'CmdOrCtrl+X', + selector: 'cut:', + }, + { + label: 'Copy', + accelerator: 'CmdOrCtrl+C', + selector: 'copy:', + }, + { + label: 'Paste', + accelerator: 'CmdOrCtrl+V', + selector: 'paste:', + }, + { + label: 'Select All', + accelerator: 'CmdOrCtrl+A', + selector: 'selectAll:', + }, + ], +} + +const template = [ + applicationMenu, + editMenu, +] + +export const menuTemplate = Menu.buildFromTemplate(template) diff --git a/src/electron.ts b/src/electron.ts index 5420374..cc5217c 100644 --- a/src/electron.ts +++ b/src/electron.ts @@ -1,17 +1,15 @@ import { UpdateInfo } from '../events' -import { BrowserWindow, app } from 'electron' +import { BrowserWindow, app, Menu } from 'electron' import * as path from 'path' -import * as fs from 'fs' - -const { autoUpdater } = require('electron-updater') -const log = require('electron-log') +import { menuTemplate } from './MenuTemplate' +import { autoUpdater } from 'electron-updater' +import * as log from 'electron-log' import { ConnectionManager, updateNotifier } from '../backend/src/index' const isDebugEnabled = Boolean(process.argv.find(arg => arg === 'debug')) require('electron-debug')({ enabled: isDebugEnabled }) autoUpdater.logger = log -autoUpdater.logger.transports.file.level = 'info' log.info('App starting...') const connectionManager = new ConnectionManager() @@ -33,7 +31,7 @@ function createWindow() { icon: iconPath, }) - console.log(iconPath) + console.log('icon path', iconPath) // and load the index.html of the app. mainWindow.loadFile('app/index.html') @@ -56,6 +54,7 @@ function createWindow() { // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', () => { + Menu.setApplicationMenu(menuTemplate) createWindow() let updateInfo: UpdateInfo