From 0c584dcbb06cb12556141dcd3f65ea1ebebe58ce Mon Sep 17 00:00:00 2001 From: Michael Hays Date: Sat, 2 Oct 2021 22:22:01 -0500 Subject: feat: add a globalShortcut to toggle main window (#2002) Fixes #1663 Co-authored-by: Vijay A --- src/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/index.js b/src/index.js index 87f45e7fc..d947d96ca 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ /* eslint-disable import/first */ -import { app, BrowserWindow, ipcMain, session, dialog } from 'electron'; +import { app, BrowserWindow, globalShortcut, ipcMain, session, dialog } from 'electron'; import { emptyDirSync, ensureFileSync } from 'fs-extra'; import { join } from 'path'; @@ -17,6 +17,7 @@ import { isMac, isWindows, isLinux, + altKey, } from './environment'; import { isDevMode, @@ -360,6 +361,13 @@ const createWindow = () => { } else { mainWindow.show(); } + + app.whenReady().then(() => { + // Toggle the window on 'Alt+X' + globalShortcut.register(`${altKey()}+X`, () => { + trayIcon.trayMenuTemplate[0].click(); + }); + }); }; // Allow passing command line parameters/switches to electron -- cgit v1.2.3-54-g00ecf