From f3b85fdbd2bd468b1a5b0cc2dc54d12e501b9c28 Mon Sep 17 00:00:00 2001 From: Aiden Date: Sat, 14 Sep 2024 15:53:55 -0400 Subject: [PATCH] basic dynamic tray implementation --- eslint.config.js | 1 + resources/placeholderTrayIcon.png | Bin 0 -> 10148 bytes src/@types/config.d.ts | 1 + src/main/discord/discordWindow.ts | 5 +++-- src/main/main.ts | 7 ++++++- src/main/tray.ts | 24 ++++++++++++++++++++++++ src/shared/config.ts | 3 ++- tsconfig.json | 3 +++ 8 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 resources/placeholderTrayIcon.png create mode 100644 src/main/tray.ts diff --git a/eslint.config.js b/eslint.config.js index 3b9670e..ef95d14 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -17,6 +17,7 @@ export default tseslint.config( }, rules: { "no-constant-binary-expression": 0, + "@typescript-eslint/no-non-null-assertion": 0, "@typescript-eslint/no-unused-vars": [ 2, { diff --git a/resources/placeholderTrayIcon.png b/resources/placeholderTrayIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..f64b855f75fee45002306c28a267f219141ce675 GIT binary patch literal 10148 zcmZ{K1yEc~5atpzxCROC1a}YaPH>0d?(XgqAh^2*cbDJ}i?a~iU3RhKzq`7+x~i+G znXa07{knVRee=z$=_qAIDHKEkL;wJQA|oxX`XP<}s|au(?Z0#no)1C#Q(9F40Pv;; z00Kh+0LVvI;1K}e#sUDG7y$r$=>Pz(V|Is%z{dcbiJX);;Qhan-(8jr08ppNh>NIs zuAS$2rRWX&T?+Mf$XzZh2tHdr%<<`ne8m(!<6q&aXZ?$6(C6Rc)F+c2I>hVcl-tOw z82{=>x+R9}i@qpY+pptlvSD@<=q#x?O|f;D$oT6XA{MuN z$!=Y?f1O;kMXSo+)Q{ zEy|-kT=xK=OLXH~!x9l6A{;hBON^qhrmfG~b^j?~3G+NZJ$rmGh7V6_N(XgU4e`8@ zOKS-LZvaPeP@p!gw&|R1s4d0C(OIWm4Ff+r86>nb+I~$6ES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T^;GC_crNB*P?WL z{;%wX5-FFo(L3+rtM%EE_}Ur!YUs=-wVf9oyK_<`M3*Bz^L=t*GcpUsGoJ{ML}{_- zp`oE)KPJ%IdZ|)fNnKMjVE?zSJ$N(>*TB!}^otQiPl3#8Z*E9DJ85x=IZ7#w8P7?$Hw)+2)Em1UC{)hj`hymdz zU5=u~Mc3^#iU0FD=q&*03&W94ljU4=2D?RzLJnVZV@-|S$DK}%x-5PeRNAc)uEwM^ zYvZ3t8rGZ7YfrG|xbHacnlA!1oM2!7tNk=X|GT&U$R*e30&Er#@Q!c%LI3e80CBu-xg%37?IP&HAq~ zQ$HR;)Rh)HxRCxpW4uyhyvpj}&g?_BFMyd_y_wrCJ*Kp&!&|T|*J<&>@kU>t@a5a< zb88p)AdA^if7+O(_{ZI?>|fFkb4vYqz#_b;9-RdLrEbbC`g { - await createDiscordWindow(); + const Acorn = await createDiscordWindow(); + if (getConfig("tray")) { + startTray(Acorn.webContents); + } }); diff --git a/src/main/tray.ts b/src/main/tray.ts new file mode 100644 index 0000000..b6c035e --- /dev/null +++ b/src/main/tray.ts @@ -0,0 +1,24 @@ +import {app, Menu, nativeImage, Tray, type WebContents} from "electron"; +import icon from "../../resources/placeholderTrayIcon.png?asset"; + +export function startTray(pageData: WebContents) { + const tray = new Tray(icon as string); + tray.setToolTip("Acorn"); + tray.setContextMenu( + Menu.buildFromTemplate([ + { + label: "Quit", + click() { + app.quit(); + } + } + ]) + ); + pageData.on("page-favicon-updated", (_, favicons) => { + try { + tray.setImage(nativeImage.createFromDataURL(favicons[0]!)); + } catch { + return; // NOTE - Discord will send a URL before fully loaded + } + }); +} diff --git a/src/shared/config.ts b/src/shared/config.ts index a2d1705..51f9a58 100644 --- a/src/shared/config.ts +++ b/src/shared/config.ts @@ -10,7 +10,8 @@ function makeConfig() { channel: "stable", multiInstance: false, mods: ["vencord"], - autoHideMenuBar: true + autoHideMenuBar: true, + tray: true } as Config; writeFileSync(configLocation, JSON.stringify(config, null, 2), {encoding: "utf8", flag: "w"}); } diff --git a/tsconfig.json b/tsconfig.json index 568f79c..b3e4f71 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,9 @@ "ESNext", "DOM" ], + "types": [ + "electron-vite/node" + ], "target": "ESNext", }, "include": [