From 9d69024758cf1630e591717d064f59e1064e9853 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Mon, 18 Sep 2023 04:38:23 -0400 Subject: [PATCH] Add hotkey option to toggle hide to tray Fixes #3043 --- src/public/app/components/root_command_executor.js | 10 ++++++++++ src/services/keyboard_actions.js | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/public/app/components/root_command_executor.js b/src/public/app/components/root_command_executor.js index f3c326b454..6d65d5c80b 100644 --- a/src/public/app/components/root_command_executor.js +++ b/src/public/app/components/root_command_executor.js @@ -6,6 +6,7 @@ import openService from "../services/open.js"; import protectedSessionService from "../services/protected_session.js"; import options from "../services/options.js"; import froca from "../services/froca.js"; +import utils from "../services/utils.js"; export default class RootCommandExecutor extends Component { editReadOnlyNoteCommand() { @@ -155,6 +156,15 @@ export default class RootCommandExecutor extends Component { } } + toggleTrayCommand() { + if (!utils.isElectron()) return; + const {BrowserWindow} = utils.dynamicRequire('@electron/remote'); + const windows = BrowserWindow.getAllWindows(); + const isVisible = windows.every(w => w.isVisible()); + const action = isVisible ? "hide" : "show" + for (const window of windows) window[action](); + } + firstTabCommand() { this.#goToTab(1); } secondTabCommand() { this.#goToTab(2); } thirdTabCommand() { this.#goToTab(3); } diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index d566a78a40..368e6db986 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -240,6 +240,12 @@ const DEFAULT_KEYBOARD_ACTIONS = [ description: "Open new empty window", scope: "window" }, + { + actionName: "toggleTray", + defaultShortcuts: [], + description: "Shows/hides the application from the system tray", + scope: "window" + }, { actionName: "firstTab", defaultShortcuts: ["CommandOrControl+1"],