Add option to disable showing/hiding on clicking the tray icon
This commit is contained in:
parent
0e1c696a68
commit
2f2b4474b4
5 changed files with 92 additions and 1 deletions
66
avia_core/disableTrayIcon.js
Normal file
66
avia_core/disableTrayIcon.js
Normal file
|
|
@ -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 });
|
||||||
|
})();
|
||||||
1
src/config.d.ts
vendored
1
src/config.d.ts
vendored
|
|
@ -3,6 +3,7 @@ declare type DesktopConfig = {
|
||||||
customFrame: boolean;
|
customFrame: boolean;
|
||||||
customFrameNativeMenu: boolean;
|
customFrameNativeMenu: boolean;
|
||||||
minimiseToTray: boolean;
|
minimiseToTray: boolean;
|
||||||
|
disableTrayClick: boolean;
|
||||||
spellchecker: boolean;
|
spellchecker: boolean;
|
||||||
hardwareAcceleration: boolean;
|
hardwareAcceleration: boolean;
|
||||||
discordRpc: boolean;
|
discordRpc: boolean;
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ const loadInject = () => {
|
||||||
"ButtonFix.js",
|
"ButtonFix.js",
|
||||||
"headliner.js",
|
"headliner.js",
|
||||||
"aviadesktopversion.js",
|
"aviadesktopversion.js",
|
||||||
"customFrameNativeMenu.js"
|
"customFrameNativeMenu.js",
|
||||||
|
"disableTrayIcon.js"
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const plugin of plugins) {
|
for (const plugin of plugins) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ const schema = {
|
||||||
minimiseToTray: {
|
minimiseToTray: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
} as JSONSchema.Boolean,
|
} as JSONSchema.Boolean,
|
||||||
|
disableTrayClick: {
|
||||||
|
type: "boolean",
|
||||||
|
} as JSONSchema.Boolean,
|
||||||
startMinimisedToTray: {
|
startMinimisedToTray: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
} as JSONSchema.Boolean,
|
} as JSONSchema.Boolean,
|
||||||
|
|
@ -60,6 +63,7 @@ const store = new Store({
|
||||||
customFrame: true,
|
customFrame: true,
|
||||||
customFrameNativeMenu: false,
|
customFrameNativeMenu: false,
|
||||||
minimiseToTray: true,
|
minimiseToTray: true,
|
||||||
|
disableTrayClick: false,
|
||||||
startMinimisedToTray: false,
|
startMinimisedToTray: false,
|
||||||
spellchecker: true,
|
spellchecker: true,
|
||||||
hardwareAcceleration: true,
|
hardwareAcceleration: true,
|
||||||
|
|
@ -84,6 +88,7 @@ class Config {
|
||||||
customFrame: this.customFrame,
|
customFrame: this.customFrame,
|
||||||
customFrameNativeMenu: this.customFrameNativeMenu,
|
customFrameNativeMenu: this.customFrameNativeMenu,
|
||||||
minimiseToTray: this.minimiseToTray,
|
minimiseToTray: this.minimiseToTray,
|
||||||
|
disableTrayClick: this.disableTrayClick,
|
||||||
startMinimisedToTray: this.startMinimisedToTray,
|
startMinimisedToTray: this.startMinimisedToTray,
|
||||||
spellchecker: this.spellchecker,
|
spellchecker: this.spellchecker,
|
||||||
hardwareAcceleration: this.hardwareAcceleration,
|
hardwareAcceleration: this.hardwareAcceleration,
|
||||||
|
|
@ -131,6 +136,21 @@ class Config {
|
||||||
this.sync();
|
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() {
|
get minimiseToTray() {
|
||||||
return (store as never as { get(k: string): boolean }).get(
|
return (store as never as { get(k: string): boolean }).get(
|
||||||
"minimiseToTray",
|
"minimiseToTray",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { Menu, Tray, nativeImage, app } from "electron";
|
||||||
import trayIconAsset from "../../avia_assets/icon.png?asset";
|
import trayIconAsset from "../../avia_assets/icon.png?asset";
|
||||||
import macOsTrayIconAsset from "../../avia_assets/iconTemplate.png?asset";
|
import macOsTrayIconAsset from "../../avia_assets/iconTemplate.png?asset";
|
||||||
import { version } from "../../package.json";
|
import { version } from "../../package.json";
|
||||||
|
import { config } from "./config";
|
||||||
|
|
||||||
import { mainWindow, quitApp } from "./window";
|
import { mainWindow, quitApp } from "./window";
|
||||||
|
|
||||||
|
|
@ -28,6 +29,8 @@ export function initTray() {
|
||||||
tray.setToolTip("AviaClient for Desktop");
|
tray.setToolTip("AviaClient for Desktop");
|
||||||
tray.setImage(trayIcon);
|
tray.setImage(trayIcon);
|
||||||
tray.on("click", () => {
|
tray.on("click", () => {
|
||||||
|
config.sync();
|
||||||
|
if (config.disableTrayClick) { return; }
|
||||||
if (mainWindow.isVisible()) {
|
if (mainWindow.isVisible()) {
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue