diff --git a/app/common/config-schemata.ts b/app/common/config-schemata.ts index e2db7b80f..b7e89c3b1 100644 --- a/app/common/config-schemata.ts +++ b/app/common/config-schemata.ts @@ -33,6 +33,7 @@ export const configSchemata = { startAtLogin: z.boolean(), startMinimized: z.boolean(), trayIcon: z.boolean(), + trayBadgeCount: z.boolean(), useManualProxy: z.boolean(), useProxy: z.boolean(), useSystemProxy: z.boolean(), diff --git a/app/common/typed-ipc.ts b/app/common/typed-ipc.ts index ca10625a7..64d188584 100644 --- a/app/common/typed-ipc.ts +++ b/app/common/typed-ipc.ts @@ -73,6 +73,7 @@ export type RendererMessage = { "toggle-sidebar": (show: boolean) => void; "toggle-silent": (state: boolean) => void; "toggle-tray": (state: boolean) => void; + "toggle-tray-badge-count": (newValue: boolean) => void; toggletray: () => void; tray: (argument: number) => void; "update-realm-icon": (serverURL: string, iconURL: string) => void; diff --git a/app/renderer/js/pages/preference/general-section.ts b/app/renderer/js/pages/preference/general-section.ts index b981e0c46..b900a8337 100644 --- a/app/renderer/js/pages/preference/general-section.ts +++ b/app/renderer/js/pages/preference/general-section.ts @@ -60,6 +60,16 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
+
+
+ ${t.__("Show unread count on tray icon")} +
+
+
0 ? unread.toString() : ""); + } else { + const image = renderNativeImage(unread); + tray.setImage(image); + } + + tray.setToolTip( + t.__mf( + "{number, plural, one {# unread message} other {# unread messages}}", + {number: `${unread}`}, + ), + ); +}; + export function initializeTray(serverManagerView: ServerManagerView) { ipcRenderer.on("destroytray", () => { if (!tray) { @@ -198,22 +227,15 @@ export function initializeTray(serverManagerView: ServerManagerView) { return; } - // We don't want to create tray from unread messages on macOS since it already has dock badges. - if (process.platform === "linux" || process.platform === "win32") { + if (shouldShowTrayIcon()) { if (argument === 0) { unread = argument; tray.setImage(iconPath()); + tray.setTitle(""); tray.setToolTip(t.__("No unread messages")); } else { unread = argument; - const image = renderNativeImage(argument); - tray.setImage(image); - tray.setToolTip( - t.__mf( - "{number, plural, one {# unread message} other {# unread messages}}", - {number: `${argument}`}, - ), - ); + displayTrayIcon(tray); } } }); @@ -231,10 +253,8 @@ export function initializeTray(serverManagerView: ServerManagerView) { } else { state = true; createTray(); - if (process.platform === "linux" || process.platform === "win32") { - const image = renderNativeImage(unread); - tray!.setImage(image); - tray!.setToolTip(`${unread} unread messages`); + if (shouldShowTrayIcon()) { + displayTrayIcon(tray!); } ConfigUtil.setConfigItem("trayIcon", true); @@ -245,6 +265,12 @@ export function initializeTray(serverManagerView: ServerManagerView) { ipcRenderer.on("toggletray", toggleTray); + ipcRenderer.on("toggle-tray-badge-count", () => { + if (tray && shouldShowTrayIcon()) { + displayTrayIcon(tray); + } + }); + if (ConfigUtil.getConfigItem("trayIcon", true)) { createTray(); }