From 54e27fd87779cdfca314042b0c23ff33f0d108dc Mon Sep 17 00:00:00 2001 From: jliddev Date: Tue, 1 Jun 2021 08:20:13 -0500 Subject: [PATCH] Remove the global shortcuts, use the menu accelerators --- wowup-electron/app-menu.ts | 111 ++++++++++++++++++------------------- wowup-electron/main.ts | 15 +---- 2 files changed, 56 insertions(+), 70 deletions(-) diff --git a/wowup-electron/app-menu.ts b/wowup-electron/app-menu.ts index 441e03ab..b56f08d2 100644 --- a/wowup-electron/app-menu.ts +++ b/wowup-electron/app-menu.ts @@ -31,30 +31,10 @@ function createMacMenuItems(win: BrowserWindow, config?: MenuConfig): Array onMenuZoomIn(win), - accelerator: "CommandOrControl+=", - }, - { - label: config.zoomOutLabel, - click: () => onMenuZoomOut(win), - accelerator: "CommandOrControl+-", - }, - { - label: config.zoomResetLabel, - click: () => onMenuZoomReset(win), - accelerator: "CommandOrControl+0", - } - ); - } + createViewMenu(viewMenuArr, win, config); viewMenuArr.push({ type: "separator" }, { label: config.toggleFullScreenLabel, role: "togglefullscreen" }); - console.debug(config); - return [ { label: app.name, @@ -86,6 +66,20 @@ function createMacMenuItems(win: BrowserWindow, config?: MenuConfig): Array { + const viewMenu: MenuItemConstructorOptions = { + label: config.viewLabel, + submenu: [ + { label: config.reloadLabel, role: "reload" }, + { label: config.forceReloadLabel, role: "forceReload" }, + { label: config.toggleDevToolsLabel, role: "toggleDevTools", accelerator: "CommandOrControl+Shift+I" }, + ], + }; + + const submenu = viewMenu.submenu as MenuItemConstructorOptions[]; + createViewMenu(submenu, win, config); + + submenu.push({ type: "separator" }, { label: config.toggleFullScreenLabel, role: "togglefullscreen" }); + return [ { label: app.name, @@ -103,20 +97,7 @@ function createLinuxMenuItems(win: BrowserWindow, config?: MenuConfig): Array onMenuZoomIn(win), - accelerator: "CommandOrControl+=", - }, - { - label: config.zoomOutLabel, - click: () => onMenuZoomOut(win), - accelerator: "CommandOrControl+-", - }, - { - label: config.zoomResetLabel, - click: () => onMenuZoomReset(win), - accelerator: "CommandOrControl+0", - } - ); - } + const submenu = viewMenu.submenu as MenuItemConstructorOptions[]; + createViewMenu(submenu, win, config); - viewMenuArr.push({ type: "separator" }, { label: config.toggleFullScreenLabel, role: "togglefullscreen" }); + submenu.push({ type: "separator" }, { label: config.toggleFullScreenLabel, role: "togglefullscreen" }); return [viewMenu]; } +function createViewMenu(submenu: MenuItemConstructorOptions[], win: BrowserWindow, config?: MenuConfig): void { + if (!config) { + return; + } + + submenu.push( + { + label: config.zoomInLabel, + click: () => onMenuZoomIn(win), + accelerator: "CommandOrControl+=", + }, + { + label: config.zoomOutLabel, + click: () => onMenuZoomOut(win), + accelerator: "CommandOrControl+-", + }, + { + label: config.zoomResetLabel, + click: () => onMenuZoomReset(win), + accelerator: "CommandOrControl+0", + }, + { + label: config.zoomInLabel + "num", + visible: false, + click: () => onMenuZoomIn(win), + accelerator: "CommandOrControl+numadd", + }, + { + label: config.zoomOutLabel + "num", + visible: false, + click: () => onMenuZoomOut(win), + accelerator: "CommandOrControl+numsub", + } + ); +} + function createMenuItems(win: BrowserWindow, config?: MenuConfig): Array { console.debug("CREATING MENU"); if (!config) { diff --git a/wowup-electron/main.ts b/wowup-electron/main.ts index bda808b0..d6658152 100644 --- a/wowup-electron/main.ts +++ b/wowup-electron/main.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow, BrowserWindowConstructorOptions, globalShortcut, powerMonitor } from "electron"; +import { app, BrowserWindow, BrowserWindowConstructorOptions, powerMonitor } from "electron"; import * as log from "electron-log"; import { find } from "lodash"; import * as minimist from "minimist"; @@ -268,18 +268,6 @@ function createWindow(): BrowserWindow { initializeAppUpdater(win); initializeAppUpdateIpcHandlers(win); - globalShortcut.register("CommandOrControl+numadd", () => { - onMenuZoomIn(win); - }); - - globalShortcut.register("CommandOrControl+numsub", () => { - onMenuZoomOut(win); - }); - - globalShortcut.register("CommandOrControl+num0", () => { - onMenuZoomReset(win); - }); - // Keep track of window state mainWindowManager.monitorState(win); @@ -354,7 +342,6 @@ function createWindow(): BrowserWindow { win.once("closed", () => { win = null; - globalShortcut.unregisterAll(); }); win.on("maximize", () => {