From 3aa541678525327ab8bf2f28d8e90ab880448c46 Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@example.com> Date: Tue, 9 Aug 2022 08:24:12 +0900 Subject: [PATCH] Don't override trayicon with favicon when manually configured --- src/@types/global.d.ts | 3 ++- src/electron-main.ts | 7 +++++-- src/tray.ts | 17 +++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 68c3a62b87..39fe59dda1 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -29,8 +29,9 @@ declare global { launcher: AutoLaunch; vectorConfig: Record; trayConfig: { - iconPath: string; brand: string; + iconPath: string; + allowWebIcons: boolean; }; store: Store<{ warnBeforeExit?: boolean; diff --git a/src/electron-main.ts b/src/electron-main.ts index 4e89240358..83f1f2a529 100644 --- a/src/electron-main.ts +++ b/src/electron-main.ts @@ -197,9 +197,12 @@ async function setupGlobals(): Promise { : (global.vectorConfig?.tray_icons?.png || path.join(resPath, 'img', 'element.png')); global.trayConfig = { - iconPath, brand: global.vectorConfig.brand || 'Element', - }; + iconPath, + allowWebIconOverride: !!( + process.platform === 'win32' && global.vectorConfig?.tray_icons?.ico || global.vectorConfig?.tray_icons?.png + ), + } as tray.IConfig; // launcher global.launcher = new AutoLaunch({ diff --git a/src/tray.ts b/src/tray.ts index 684db3d57f..c816d04652 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -45,7 +45,8 @@ function toggleWin(): void { } } -interface IConfig { +export interface IConfig { + allowWebIconOverride: boolean; iconPath: string; brand: string; } @@ -61,7 +62,15 @@ export function create(config: IConfig): void { trayIcon.on('click', toggleWin); let lastFavicon = null; - global.mainWindow.webContents.on('page-favicon-updated', async function(ev, favicons) { + global.mainWindow.webContents.on('page-title-updated', (_ev: Event, title: string) => { + trayIcon.setToolTip(title); + }); + + if (!config.allowWebIconOverride) { + return; + } + + global.mainWindow.webContents.on('page-favicon-updated', async (_ev: Event, favicons: string[]) => { if (!favicons || favicons.length <= 0 || !favicons[0].startsWith('data:')) { if (lastFavicon !== null) { global.mainWindow.setIcon(defaultIcon); @@ -91,10 +100,6 @@ export function create(config: IConfig): void { trayIcon.setImage(newFavicon); global.mainWindow.setIcon(newFavicon); }); - - global.mainWindow.webContents.on('page-title-updated', function(ev, title) { - trayIcon.setToolTip(title); - }); } export function initApplicationMenu(): void {