Skip to content

Commit cc7608e

Browse files
committed
chg: mac平台有未读消息时托盘图标显示样式修改为原图标加红点
1 parent b42f9de commit cc7608e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+118
-10
lines changed

app/common/config-schemata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const configSchemata = {
3333
startAtLogin: z.boolean(),
3434
startMinimized: z.boolean(),
3535
trayIcon: z.boolean(),
36+
trayBadgeCount: z.boolean(),
3637
useManualProxy: z.boolean(),
3738
useProxy: z.boolean(),
3839
useSystemProxy: z.boolean(),

app/common/typed-ipc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export type RendererMessage = {
7373
"toggle-sidebar": (show: boolean) => void;
7474
"toggle-silent": (state: boolean) => void;
7575
"toggle-tray": (state: boolean) => void;
76+
"toggle-tray-badge-count": (newValue: boolean) => void;
7677
toggletray: () => void;
7778
tray: (argument: number) => void;
7879
"update-realm-icon": (serverURL: string, iconURL: string) => void;

app/renderer/js/pages/preference/general-section.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
6060
</div>
6161
<div class="setting-control"></div>
6262
</div>
63+
<div
64+
class="setting-row"
65+
id="tray-badge-count-option"
66+
style="display:${process.platform === "darwin" ? "" : "none"}"
67+
>
68+
<div class="setting-description">
69+
${t.__("Show unread count on tray icon")}
70+
</div>
71+
<div class="setting-control"></div>
72+
</div>
6373
<div
6474
class="setting-row"
6575
id="dock-bounce-option"
@@ -213,6 +223,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
213223

214224
updateTrayOption();
215225
updateBadgeOption();
226+
updateTrayBadgeCountOption();
216227
updateSilentOption();
217228
autoUpdateOption();
218229
betaUpdateOption();
@@ -288,6 +299,25 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
288299
});
289300
}
290301

302+
function updateTrayBadgeCountOption(): void {
303+
generateSettingOption({
304+
$element: $root.querySelector(
305+
"#tray-badge-count-option .setting-control",
306+
)!,
307+
value: ConfigUtil.getConfigItem("trayBadgeCount", false),
308+
clickHandler() {
309+
const newValue = !ConfigUtil.getConfigItem("trayBadgeCount", false);
310+
ConfigUtil.setConfigItem("trayBadgeCount", newValue);
311+
ipcRenderer.send(
312+
"forward-message",
313+
"toggle-tray-badge-count",
314+
newValue,
315+
);
316+
updateTrayBadgeCountOption();
317+
},
318+
});
319+
}
320+
291321
function updateDockBouncing(): void {
292322
generateSettingOption({
293323
$element: $root.querySelector("#dock-bounce-option .setting-control")!,

app/renderer/js/tray.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ const createTray = function (): void {
178178
}
179179
};
180180

181+
const shouldShowTrayIcon = function (): boolean {
182+
return (
183+
process.platform === "darwin" ||
184+
process.platform === "win32" ||
185+
process.platform === "linux"
186+
);
187+
};
188+
189+
const displayTrayIcon = function (tray: ElectronTray): void {
190+
if (process.platform === "darwin") {
191+
tray.setImage(iconPath());
192+
const showTrayBadgeCount = ConfigUtil.getConfigItem(
193+
"trayBadgeCount",
194+
false,
195+
);
196+
tray.setTitle(showTrayBadgeCount && unread > 0 ? unread.toString() : "");
197+
} else {
198+
const image = renderNativeImage(unread);
199+
tray.setImage(image);
200+
}
201+
202+
tray.setToolTip(`${unread} unread messages`);
203+
};
204+
181205
export function initializeTray(serverManagerView: ServerManagerView) {
182206
ipcRenderer.on("destroytray", () => {
183207
if (!tray) {
@@ -197,17 +221,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
197221
return;
198222
}
199223

200-
// We don't want to create tray from unread messages on macOS since it already has dock badges.
201-
if (process.platform === "linux" || process.platform === "win32") {
224+
if (shouldShowTrayIcon()) {
202225
if (argument === 0) {
203226
unread = argument;
204227
tray.setImage(iconPath());
228+
tray.setTitle("");
205229
tray.setToolTip("No unread messages");
206230
} else {
207231
unread = argument;
208-
const image = renderNativeImage(argument);
209-
tray.setImage(image);
210-
tray.setToolTip(`${argument} unread messages`);
232+
displayTrayIcon(tray);
211233
}
212234
}
213235
});
@@ -225,10 +247,8 @@ export function initializeTray(serverManagerView: ServerManagerView) {
225247
} else {
226248
state = true;
227249
createTray();
228-
if (process.platform === "linux" || process.platform === "win32") {
229-
const image = renderNativeImage(unread);
230-
tray!.setImage(image);
231-
tray!.setToolTip(`${unread} unread messages`);
250+
if (shouldShowTrayIcon()) {
251+
displayTrayIcon(tray!);
232252
}
233253

234254
ConfigUtil.setConfigItem("trayIcon", true);
@@ -239,6 +259,12 @@ export function initializeTray(serverManagerView: ServerManagerView) {
239259

240260
ipcRenderer.on("toggletray", toggleTray);
241261

262+
ipcRenderer.on("toggle-tray-badge-count", () => {
263+
if (tray && shouldShowTrayIcon()) {
264+
displayTrayIcon(tray);
265+
}
266+
});
267+
242268
if (ConfigUtil.getConfigItem("trayIcon", true)) {
243269
createTray();
244270
}

public/translations/ar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"Show desktop notifications": "Show desktop notifications",
132132
"Show sidebar": "Show sidebar",
133133
"Show unread count badge on app icon": "Show unread count badge on app icon",
134+
"Show unread count on tray icon": "إظهار عدد الرسائل غير المقروءة على أيقونة الدرج",
134135
"Spellchecker Languages": "Spellchecker Languages",
135136
"Start app at login": "Start app at login",
136137
"Switch to Next Organization": "Switch to Next Organization",

public/translations/be.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"Show desktop notifications": "Паказваць апавяшчэнні на працоўным стале",
132132
"Show sidebar": "Паказваць бакавую панэль",
133133
"Show unread count badge on app icon": "Show unread count badge on app icon",
134+
"Show unread count on tray icon": "Паказваць колькасць непрачытаных паведамленняў на значку ў трэі",
134135
"Spellchecker Languages": "Мовы для праверкі правапісу",
135136
"Start app at login": "Запусціць праграму пры ўваходзе ва ўліковы запіс",
136137
"Switch to Next Organization": "Пераключыцца на наступную арганізацыю",

public/translations/bg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"Show desktop notifications": "Показване на известията на работния плот",
132132
"Show sidebar": "Показване на страничната лента",
133133
"Show unread count badge on app icon": "Show unread count badge on app icon",
134+
"Show unread count on tray icon": "Показване на броя непрочетени съобщения в иконата на системната лента",
134135
"Spellchecker Languages": "Spellchecker Languages",
135136
"Start app at login": "Стартирайте приложението при влизане",
136137
"Switch to Next Organization": "Превключване към следваща организация",

public/translations/bn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"Show desktop notifications": "Show desktop notifications",
132132
"Show sidebar": "Show sidebar",
133133
"Show unread count badge on app icon": "Show unread count badge on app icon",
134+
"Show unread count on tray icon": "ট্রে আইকনে অপঠিত বার্তার সংখ্যা দেখান",
134135
"Spellchecker Languages": "Spellchecker Languages",
135136
"Start app at login": "Start app at login",
136137
"Switch to Next Organization": "Switch to Next Organization",

public/translations/bqi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"Show desktop notifications": "Show desktop notifications",
132132
"Show sidebar": "Show sidebar",
133133
"Show unread count badge on app icon": "Show unread count badge on app icon",
134+
"Show unread count on tray icon": "نمایش تعداد پیام‌های خوانده نشده روی آیکون سینی",
134135
"Spellchecker Languages": "Spellchecker Languages",
135136
"Start app at login": "Start app at login",
136137
"Switch to Next Organization": "Switch to Next Organization",

public/translations/ca.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"Show desktop notifications": "Show desktop notifications",
132132
"Show sidebar": "Show sidebar",
133133
"Show unread count badge on app icon": "Show unread count badge on app icon",
134+
"Show unread count on tray icon": "Mostra el recompte de missatges no llegits a la icona de la safata",
134135
"Spellchecker Languages": "Spellchecker Languages",
135136
"Start app at login": "Start app at login",
136137
"Switch to Next Organization": "Switch to Next Organization",

0 commit comments

Comments
 (0)