Skip to content

Commit

Permalink
Don't override trayicon with favicon when manually configured
Browse files Browse the repository at this point in the history
  • Loading branch information
3nprob committed Aug 8, 2022
1 parent a591698 commit 3aa5416
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ declare global {
launcher: AutoLaunch;
vectorConfig: Record<string, any>;
trayConfig: {
iconPath: string;
brand: string;
iconPath: string;
allowWebIcons: boolean;
};
store: Store<{
warnBeforeExit?: boolean;
Expand Down
7 changes: 5 additions & 2 deletions src/electron-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ async function setupGlobals(): Promise<void> {
: (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({
Expand Down
17 changes: 11 additions & 6 deletions src/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ function toggleWin(): void {
}
}

interface IConfig {
export interface IConfig {
allowWebIconOverride: boolean;
iconPath: string;
brand: string;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3aa5416

Please sign in to comment.