Restore tray icon updates for Windows.
This commit is contained in:
+22
-4
@@ -7,8 +7,11 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { app, Tray, Menu, nativeImage, ipcMain, type IpcMainEvent } from "electron";
|
||||
import { app, Tray, Menu, nativeImage } from "electron";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import pngToIco from "png-to-ico";
|
||||
import path from "node:path";
|
||||
|
||||
import { _t } from "./language-helper.js";
|
||||
|
||||
@@ -68,6 +71,7 @@ export function create(config: IConfig): void {
|
||||
initApplicationMenu();
|
||||
trayIcon.on("click", toggleWin);
|
||||
|
||||
// See also, badge.ts
|
||||
let lastFavicon: string | null = null;
|
||||
global.mainWindow?.webContents.on("page-favicon-updated", async function (ev, favicons) {
|
||||
if (!favicons || favicons.length <= 0 || !favicons[0].startsWith("data:")) {
|
||||
@@ -83,9 +87,23 @@ export function create(config: IConfig): void {
|
||||
if (favicons[0] === lastFavicon) return;
|
||||
lastFavicon = favicons[0];
|
||||
|
||||
const newFavicon = nativeImage.createFromDataURL(favicons[0]);
|
||||
trayIcon?.setImage(newFavicon);
|
||||
global.mainWindow?.setIcon(newFavicon);
|
||||
let newFavicon = nativeImage.createFromDataURL(favicons[0]);
|
||||
|
||||
// Windows likes ico's too much.
|
||||
if (process.platform === "win32") {
|
||||
try {
|
||||
const icoPath = path.join(app.getPath("temp"), "win32_element_icon.ico");
|
||||
await writeFile(icoPath, await pngToIco(newFavicon.toPNG()));
|
||||
newFavicon = nativeImage.createFromPath(icoPath);
|
||||
} catch (e) {
|
||||
console.error("Failed to make win32 ico", e);
|
||||
}
|
||||
// Always update the tray icon for Windows.
|
||||
trayIcon?.setImage(newFavicon);
|
||||
} else {
|
||||
trayIcon?.setImage(newFavicon);
|
||||
global.mainWindow?.setIcon(newFavicon);
|
||||
}
|
||||
});
|
||||
|
||||
global.mainWindow?.webContents.on("page-title-updated", function (ev, title) {
|
||||
|
||||
Reference in New Issue
Block a user