Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/common/config-schemata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions app/common/typed-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions app/renderer/js/pages/preference/general-section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
</div>
<div class="setting-control"></div>
</div>
<div
class="setting-row"
id="tray-badge-count-option"
style="display:${process.platform === "darwin" ? "" : "none"}"
>
<div class="setting-description">
${t.__("Show unread count on tray icon")}
</div>
<div class="setting-control"></div>
</div>
<div
class="setting-row"
id="dock-bounce-option"
Expand Down Expand Up @@ -213,6 +223,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {

updateTrayOption();
updateBadgeOption();
updateTrayBadgeCountOption();
updateSilentOption();
autoUpdateOption();
betaUpdateOption();
Expand Down Expand Up @@ -288,6 +299,25 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
});
}

function updateTrayBadgeCountOption(): void {
generateSettingOption({
$element: $root.querySelector(
"#tray-badge-count-option .setting-control",
)!,
value: ConfigUtil.getConfigItem("trayBadgeCount", false),
clickHandler() {
const newValue = !ConfigUtil.getConfigItem("trayBadgeCount", false);
ConfigUtil.setConfigItem("trayBadgeCount", newValue);
ipcRenderer.send(
"forward-message",
"toggle-tray-badge-count",
newValue,
);
updateTrayBadgeCountOption();
},
});
}

function updateDockBouncing(): void {
generateSettingOption({
$element: $root.querySelector("#dock-bounce-option .setting-control")!,
Expand Down
54 changes: 40 additions & 14 deletions app/renderer/js/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,35 @@ const createTray = function (): void {
}
};

const shouldShowTrayIcon = function (): boolean {
return (
process.platform === "darwin" ||
process.platform === "win32" ||
process.platform === "linux"
);
};

const displayTrayIcon = function (tray: ElectronTray): void {
if (process.platform === "darwin") {
tray.setImage(iconPath());
const showTrayBadgeCount = ConfigUtil.getConfigItem(
"trayBadgeCount",
false,
);
tray.setTitle(showTrayBadgeCount && unread > 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) {
Expand All @@ -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);
}
}
});
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down