diff --git a/package.json b/package.json index 9c3c13b65a..5eeb5396ee 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "electron-window-state": "^5.0.3", "keytar-forked": "7.10.0", "minimist": "^1.2.6", - "png-to-ico": "^2.1.1", "uuid": "^11.0.0" }, "devDependencies": { diff --git a/src/ipc.ts b/src/ipc.ts index ea4a8b5b42..40aaa63398 100644 --- a/src/ipc.ts +++ b/src/ipc.ts @@ -20,18 +20,6 @@ ipcMain.on( // has some Windows support too, and in some Windows environments this leads to two badges rendering atop // each other. See https://github.com/vector-im/element-web/issues/16942 app.badgeCount = count; - } else { - // similarly, we only use setOverlayIcon on Windows as it's only supported on that platform, but has good support - // from all the Windows variants we support. - // https://www.electronjs.org/docs/latest/api/browser-window#winsetoverlayiconoverlay-description-windows - if (imageBuffer && imageBufferDescription !== undefined) { - global.mainWindow?.setOverlayIcon( - nativeImage.createFromBuffer(Buffer.from(imageBuffer)), - imageBufferDescription, - ); - } else { - global.mainWindow?.setOverlayIcon(null, ""); - } } if (count === 0) { global.mainWindow?.flashFrame(false); diff --git a/src/tray.ts b/src/tray.ts index bbf477bfe7..0ee9f002c4 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -7,10 +7,7 @@ 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 } from "electron"; -import pngToIco from "png-to-ico"; -import path from "node:path"; -import fs from "node:fs"; +import { app, Tray, Menu, nativeImage, ipcMain, IpcMainEvent } from "electron"; import { v5 as uuidv5 } from "uuid"; import { _t } from "./language-helper.js"; @@ -71,37 +68,45 @@ export function create(config: IConfig): void { initApplicationMenu(); trayIcon.on("click", toggleWin); - 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:")) { - if (lastFavicon !== null) { - global.mainWindow?.setIcon(defaultIcon); - trayIcon?.setImage(defaultIcon); - lastFavicon = null; + if (process.platform === "win32") { + // We only use setOverlayIcon on Windows as it's only supported on that platform, but has good support + // from all the Windows variants we support. + // https://www.electronjs.org/docs/latest/api/browser-window#winsetoverlayiconoverlay-description-windows + ipcMain.on( + "setBadgeCount", + function (_ev: IpcMainEvent, count: number, imageBuffer?: Buffer, imageBufferDescription?: string): void { + if (imageBuffer && imageBufferDescription !== undefined) { + global.mainWindow?.setOverlayIcon( + nativeImage.createFromBuffer(Buffer.from(imageBuffer)), + imageBufferDescription, + ); + } else { + global.mainWindow?.setOverlayIcon(null, ""); + } + }, + ); + } else { + // For other platforms, we instead update the application icon when the favicon changes. + 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:")) { + if (lastFavicon !== null) { + global.mainWindow?.setIcon(defaultIcon); + trayIcon?.setImage(defaultIcon); + lastFavicon = null; + } + return; } - return; - } - // No need to change, shortcut - if (favicons[0] === lastFavicon) return; - lastFavicon = favicons[0]; + // No need to change, shortcut + if (favicons[0] === lastFavicon) return; + lastFavicon = favicons[0]; - 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"); - fs.writeFileSync(icoPath, await pngToIco(newFavicon.toPNG())); - newFavicon = nativeImage.createFromPath(icoPath); - } catch (e) { - console.error("Failed to make win32 ico", e); - } - } - - trayIcon?.setImage(newFavicon); - global.mainWindow?.setIcon(newFavicon); - }); + let newFavicon = nativeImage.createFromDataURL(favicons[0]); + trayIcon?.setImage(newFavicon); + global.mainWindow?.setIcon(newFavicon); + }); + } global.mainWindow?.webContents.on("page-title-updated", function (ev, title) { trayIcon?.setToolTip(title); diff --git a/yarn.lock b/yarn.lock index d8bd03b458..645a42add6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2243,7 +2243,7 @@ "@types/node" "*" form-data "^4.0.0" -"@types/node@*", "@types/node@18.19.115", "@types/node@^17.0.36", "@types/node@^22.7.7": +"@types/node@*", "@types/node@18.19.115", "@types/node@^22.7.7": version "18.19.115" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.115.tgz#cd94caf14472021b4443c99bcd7aac6bb5c4f672" integrity sha512-kNrFiTgG4a9JAn1LMQeLOv3MvXIPokzXziohMrMsvpYgLpdEt/mMiVYc4sGKtDfyxM5gIDF4VgrPRyCw4fHOYg== @@ -6237,20 +6237,6 @@ pluralizers@^0.1.7: resolved "https://registry.yarnpkg.com/pluralizers/-/pluralizers-0.1.7.tgz#8d38dd0a1b660e739b10ab2eab10b684c9d50142" integrity sha512-mw6AejUiCaMQ6uPN9ObjJDTnR5AnBSmnHHy3uVTbxrSFSxO5scfwpTs8Dxyb6T2v7GSulhvOq+pm9y+hXUvtOA== -png-to-ico@^2.1.1: - version "2.1.8" - resolved "https://registry.yarnpkg.com/png-to-ico/-/png-to-ico-2.1.8.tgz#fdc2eda6f197df1d6c33400707e36c3b802ac6dd" - integrity sha512-Nf+IIn/cZ/DIZVdGveJp86NG5uNib1ZXMiDd/8x32HCTeKSvgpyg6D/6tUBn1QO/zybzoMK0/mc3QRgAyXdv9w== - dependencies: - "@types/node" "^17.0.36" - minimist "^1.2.6" - pngjs "^6.0.0" - -pngjs@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-6.0.0.tgz#ca9e5d2aa48db0228a52c419c3308e87720da821" - integrity sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg== - possible-typed-array-names@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz#89bb63c6fada2c3e90adc4a647beeeb39cc7bf8f"