From 4fd328e716221ba6eb11493e2c8f6db6f3e7dcee Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Mon, 25 Feb 2019 13:52:07 +0100 Subject: [PATCH] Add zoom menu and shortcuts --- src/MenuTemplate.ts | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/MenuTemplate.ts b/src/MenuTemplate.ts index 41344ee..8a9f124 100644 --- a/src/MenuTemplate.ts +++ b/src/MenuTemplate.ts @@ -8,7 +8,6 @@ const applicationMenu = { { label: 'About Application', click: () => { - console.log(path.join(__dirname, 'icon.png')) openAboutWindow({ icon_path: path.join(__dirname, '..', '..', 'icon.png'), license: 'AGPL-3.0', @@ -75,9 +74,50 @@ const editMenu = { ], } +const viewMenu = { + label: 'View', + submenu: [ + { + label: 'Default size', + accelerator: 'CmdOrCtrl+0', + click: () => { + const window = BrowserWindow.getFocusedWindow() + if (window) { + window.webContents.setZoomFactor(1) + } + }, + }, + { + label: 'Increase size', + accelerator: 'CmdOrCtrl+Plus', + click: () => { + const window = BrowserWindow.getFocusedWindow() + if (window) { + window.webContents.getZoomFactor((zoom) => { + window.webContents.setZoomFactor(Math.min(zoom + 0.1, 2.0)) + }) + } + }, + }, + { + label: 'Reduce size', + accelerator: 'CmdOrCtrl+-', + click: () => { + const window = BrowserWindow.getFocusedWindow() + if (window) { + window.webContents.getZoomFactor((zoom) => { + window.webContents.setZoomFactor(Math.max(zoom - 0.1, 0.5)) + }) + } + }, + }, + ], +} + const template = [ applicationMenu, editMenu, + viewMenu, ] export const menuTemplate = Menu.buildFromTemplate(template)