From de3aae1d95c0b3df638b2afd83e7399dc1362c7e Mon Sep 17 00:00:00 2001 From: Kode Date: Mon, 10 Apr 2023 18:12:58 +0100 Subject: [PATCH] Tray: Option to hide (#7) Co-authored-by: V --- src/main/mainWindow.ts | 13 ++++++++++--- src/renderer/components/Settings.tsx | 16 ++++++++++++---- src/shared/settings.d.ts | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 6188472..93458df 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -15,6 +15,7 @@ import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; import { downloadVencordFiles } from "./utils/vencordLoader"; let isQuitting = false; +let tray: Tray; app.on("before-quit", () => { isQuitting = true; @@ -62,7 +63,7 @@ function initTray(win: BrowserWindow) { } ]); - const tray = new Tray(ICON_PATH); + tray = new Tray(ICON_PATH); tray.setToolTip("Vencord Desktop"); tray.setContextMenu(trayMenu); tray.on("click", () => win.show()); @@ -213,6 +214,12 @@ function initWindowBoundsListeners(win: BrowserWindow) { } function initSettingsListeners(win: BrowserWindow) { + Settings.addChangeListener("tray", enable => { + if (enable) + initTray(win); + else + tray?.destroy(); + }); Settings.addChangeListener("disableMinSize", disable => { if (disable) { // 0 no work @@ -246,7 +253,7 @@ export function createMainWindow() { })); win.on("close", e => { - if (isQuitting || Settings.store.minimizeToTray === false) return; + if (isQuitting || Settings.store.minimizeToTray === false || Settings.store.tray === false) return; e.preventDefault(); win.hide(); @@ -255,7 +262,7 @@ export function createMainWindow() { }); initWindowBoundsListeners(win); - initTray(win); + if (Settings.store.tray ?? true) initTray(win); initMenuBar(win); makeLinksOpenExternally(win); initSettingsListeners(win); diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index dd957ba..995100a 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -21,12 +21,19 @@ export default function SettingsUi() { Button } = Common; - const switches: [keyof typeof Settings, string, string, boolean?][] = [ + const switches: [keyof typeof Settings, string, string, boolean?, (() => boolean)?][] = [ + [ + "tray", + "Tray Icon", + "Add a tray icon for Vencord Desktop", + true + ], [ "minimizeToTray", "Minimize to tray", "Hitting X will make Vencord Desktop minimize to the tray instead of closing", - true + true, + () => Settings["tray"] ?? true ], [ "disableMinSize", @@ -62,9 +69,10 @@ export default function SettingsUi() { - {switches.map(([key, text, note, def]) => ( + {switches.map(([key, text, note, def, predicate]) => ( (Settings[key] = v)} note={note} key={key} diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index 34c4035..cae4826 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -14,5 +14,6 @@ export interface Settings { openLinksWithElectron?: boolean; vencordDir?: string; disableMinSize?: boolean; + tray?: boolean; minimizeToTray?: boolean; }