Update with a proper comment

This commit is contained in:
Half-Shot 2025-07-14 15:52:41 +01:00
parent 92a7da38ea
commit b13f3ba1bd
3 changed files with 24 additions and 51 deletions

View File

@ -76,5 +76,13 @@
"bring_all_to_front": "Bring All to Front",
"label": "Window",
"zoom": "Zoom"
},
"icon_overlay": {
"description_notifications": {
"one": "You have %(count)s unread notification.",
"other": "You have %(count)s unread notifications."
},
"description_error": "Error"
}
}

View File

@ -12,21 +12,6 @@ import { randomArray } from "./utils.js";
import { getDisplayMediaCallback, setDisplayMediaCallback } from "./displayMediaCallback.js";
import Store, { clearDataAndRelaunch } from "./store.js";
ipcMain.on(
"setBadgeCount",
function (_ev: IpcMainEvent, count: number, imageBuffer?: Buffer, imageBufferDescription?: string): void {
if (process.platform !== "win32") {
// only set badgeCount on Mac/Linux, the docs say that only those platforms support it but turns out Electron
// 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;
}
if (count === 0) {
global.mainWindow?.flashFrame(false);
}
},
);
let focusHandlerAttached = false;
ipcMain.on("loudNotification", function (): void {
if (process.platform === "win32" || process.platform === "linux") {

View File

@ -68,45 +68,25 @@ export function create(config: IConfig): void {
initApplicationMenu();
trayIcon.on("click", toggleWin);
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;
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;
}
// 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];
const newFavicon = nativeImage.createFromDataURL(favicons[0]);
trayIcon?.setImage(newFavicon);
global.mainWindow?.setIcon(newFavicon);
});
}
const 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);