From 2f2b4474b4230d295d826b59d8dc8f3f48fc37b0 Mon Sep 17 00:00:00 2001 From: Amelia Frost Date: Sat, 28 Mar 2026 19:55:40 -0700 Subject: [PATCH] Add option to disable showing/hiding on clicking the tray icon --- avia_core/disableTrayIcon.js | 66 ++++++++++++++++++++++++++++++++++++ src/config.d.ts | 1 + src/main.ts | 3 +- src/native/config.ts | 20 +++++++++++ src/native/tray.ts | 3 ++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 avia_core/disableTrayIcon.js diff --git a/avia_core/disableTrayIcon.js b/avia_core/disableTrayIcon.js new file mode 100644 index 0000000..d94c7df --- /dev/null +++ b/avia_core/disableTrayIcon.js @@ -0,0 +1,66 @@ +(function () { + if (window.__disableTrayClick) return; + window.__disableTrayClick = true; + + function toggleCheckbox(elem, value) { + const checkbox = elem.querySelector("mdui-checkbox"); + if (!checkbox) return; + + if (value) { + checkbox.setAttribute("checked", ""); + checkbox.setAttribute("value", "on"); + } else { + checkbox.removeAttribute("checked"); + checkbox.setAttribute("value", "off"); + } + } + + function createButton(baseElem) { + const newElem = baseElem.cloneNode(true); + + newElem.setAttribute("data-disable-tray-click", "true"); + + const title = newElem.querySelector("div.d_flex.flex-g_1 > div"); + const desc = newElem.querySelector("div.d_flex.flex-g_1 > span"); + const icon = newElem.querySelector("div.w_36px span.material-symbols-outlined"); + + if (title) title.textContent = "Disable Tray Icon Click"; + if (desc) desc.textContent = "Prevents tray icon from toggling the app window."; + if (icon) icon.textContent = "block"; + + let config = window.desktopConfig.get(); + toggleCheckbox(newElem, config.disableTrayClick); + + newElem.addEventListener("click", (e) => { + e.preventDefault(); + e.stopPropagation(); + + let config = window.desktopConfig.get(); + config.disableTrayClick = !config.disableTrayClick; + window.desktopConfig.set(config); + + toggleCheckbox(newElem, config.disableTrayClick); + }); + + return newElem; + } + + function injectButton() { + const base = Array.from(document.querySelectorAll("a")).find((e) => { + const t = e.querySelector("div.d_flex.flex-g_1 > div"); + return t && t.textContent.trim() === "Discord RPC"; + }); + + if (!base) return; + if (document.querySelector("[data-disable-tray-click]")) return; + + const newButton = createButton(base); + base.parentNode.appendChild(newButton); + } + + injectButton(); + + const observer = new MutationObserver(() => injectButton()); + + observer.observe(document.body, { childList: true, subtree: true }); +})(); \ No newline at end of file diff --git a/src/config.d.ts b/src/config.d.ts index 2b4dc63..8a20869 100644 --- a/src/config.d.ts +++ b/src/config.d.ts @@ -3,6 +3,7 @@ declare type DesktopConfig = { customFrame: boolean; customFrameNativeMenu: boolean; minimiseToTray: boolean; + disableTrayClick: boolean; spellchecker: boolean; hardwareAcceleration: boolean; discordRpc: boolean; diff --git a/src/main.ts b/src/main.ts index 7d3982b..cb213df 100644 --- a/src/main.ts +++ b/src/main.ts @@ -59,7 +59,8 @@ const loadInject = () => { "ButtonFix.js", "headliner.js", "aviadesktopversion.js", - "customFrameNativeMenu.js" + "customFrameNativeMenu.js", + "disableTrayIcon.js" ]; for (const plugin of plugins) { diff --git a/src/native/config.ts b/src/native/config.ts index 6b2514d..eb844c8 100644 --- a/src/native/config.ts +++ b/src/native/config.ts @@ -19,6 +19,9 @@ const schema = { minimiseToTray: { type: "boolean", } as JSONSchema.Boolean, + disableTrayClick: { + type: "boolean", + } as JSONSchema.Boolean, startMinimisedToTray: { type: "boolean", } as JSONSchema.Boolean, @@ -60,6 +63,7 @@ const store = new Store({ customFrame: true, customFrameNativeMenu: false, minimiseToTray: true, + disableTrayClick: false, startMinimisedToTray: false, spellchecker: true, hardwareAcceleration: true, @@ -84,6 +88,7 @@ class Config { customFrame: this.customFrame, customFrameNativeMenu: this.customFrameNativeMenu, minimiseToTray: this.minimiseToTray, + disableTrayClick: this.disableTrayClick, startMinimisedToTray: this.startMinimisedToTray, spellchecker: this.spellchecker, hardwareAcceleration: this.hardwareAcceleration, @@ -131,6 +136,21 @@ class Config { this.sync(); } + get disableTrayClick() { + return (store as never as { get(k: string): boolean }).get( + "disableTrayClick", + ); + } + + set disableTrayClick(value: boolean) { + (store as never as { set(k: string, value: boolean): void }).set( + "disableTrayClick", + value, + ); + + this.sync(); + } + get minimiseToTray() { return (store as never as { get(k: string): boolean }).get( "minimiseToTray", diff --git a/src/native/tray.ts b/src/native/tray.ts index cca0fb1..583a6ca 100644 --- a/src/native/tray.ts +++ b/src/native/tray.ts @@ -3,6 +3,7 @@ import { Menu, Tray, nativeImage, app } from "electron"; import trayIconAsset from "../../avia_assets/icon.png?asset"; import macOsTrayIconAsset from "../../avia_assets/iconTemplate.png?asset"; import { version } from "../../package.json"; +import { config } from "./config"; import { mainWindow, quitApp } from "./window"; @@ -28,6 +29,8 @@ export function initTray() { tray.setToolTip("AviaClient for Desktop"); tray.setImage(trayIcon); tray.on("click", () => { + config.sync(); + if (config.disableTrayClick) { return; } if (mainWindow.isVisible()) { mainWindow.hide(); } else {