Skip to content

Commit 665221d

Browse files
committed
feat(desktop): display unread in tray
1 parent d09f5a6 commit 665221d

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

apps/desktop/src/main/src/lib/dock.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ export const setDockCount = (input: number) => {
1111
app.setBadgeCount(input)
1212
}
1313
}
14+
15+
export const getDockCount = () => {
16+
if (isWindows) return null
17+
if (app.dock) {
18+
return app.dock.getBadge()
19+
} else {
20+
return app.getBadgeCount()
21+
}
22+
}

apps/desktop/src/main/src/lib/tray.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
import { name } from "@pkg"
22
import { app, Menu, nativeImage, Tray } from "electron"
33

4-
import { isMacOS } from "~/env"
4+
import { isMacOS, isWindows } from "~/env"
55
import { getTrayIconPath } from "~/helper"
66
import { logger, revealLogFile } from "~/logger"
77
import { checkForAppUpdates } from "~/updater"
88

99
import { getMainWindowOrCreate } from "../window"
10+
import { getDockCount } from "./dock"
1011
import { t } from "./i18n"
1112
import { store } from "./store"
1213

1314
// https://www.electronjs.org/docs/latest/tutorial/tray
1415

1516
let tray: Tray | null = null
1617

17-
export const registerAppTray = () => {
18-
if (!getTrayConfig()) return
19-
if (tray) {
20-
destroyAppTray()
21-
}
22-
23-
const icon = nativeImage.createFromPath(getTrayIconPath())
24-
// See https://stackoverflow.com/questions/41664208/electron-tray-icon-change-depending-on-dark-theme/41998326#41998326
25-
const trayIcon = isMacOS ? icon.resize({ width: 16 }) : icon
26-
trayIcon.setTemplateImage(true)
27-
tray = new Tray(trayIcon)
28-
29-
const contextMenu = Menu.buildFromTemplate([
18+
const getTrayContextMenu = () => {
19+
const count = getDockCount()
20+
return Menu.buildFromTemplate([
21+
...(count
22+
? [
23+
{
24+
label: `${t("menu.unread")} ${count}`,
25+
enabled: false,
26+
},
27+
]
28+
: []),
3029
{
3130
label: t("menu.open", { name }),
3231
click: showWindow,
@@ -71,9 +70,27 @@ export const registerAppTray = () => {
7170
},
7271
},
7372
])
74-
tray.setContextMenu(contextMenu)
73+
}
74+
export const registerAppTray = () => {
75+
if (!getTrayConfig()) return
76+
if (tray) {
77+
destroyAppTray()
78+
}
79+
80+
const icon = nativeImage.createFromPath(getTrayIconPath())
81+
// See https://stackoverflow.com/questions/41664208/electron-tray-icon-change-depending-on-dark-theme/41998326#41998326
82+
const trayIcon = isMacOS ? icon.resize({ width: 16 }) : icon
83+
trayIcon.setTemplateImage(true)
84+
tray = new Tray(trayIcon)
85+
86+
tray.setContextMenu(getTrayContextMenu())
7587
tray.setToolTip(app.getName())
76-
tray.on("click", showWindow)
88+
tray.on("mouse-enter", () => {
89+
tray?.setContextMenu(getTrayContextMenu())
90+
})
91+
if (isWindows) {
92+
tray.on("click", showWindow)
93+
}
7794
}
7895

7996
const showWindow = () => {

locales/native/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"menu.toggleDevTools": "Toggle Developer Tools",
6666
"menu.toggleFullScreen": "Toggle Full Screen",
6767
"menu.undo": "Undo",
68+
"menu.unread": "Unread",
6869
"menu.view": "View",
6970
"menu.window": "Window",
7071
"menu.zenMode": "Zen Mode",

locales/settings/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"actions.action_card.operation_options.matches_regex": "matches regex",
3939
"actions.action_card.operator": "Operator",
4040
"actions.action_card.or": "Or",
41-
"actions.action_card.rewrite_rules": "Rewrite Rules",
41+
"actions.action_card.rewrite_rules": "Rewrite rules",
4242
"actions.action_card.silence": "Silence",
4343
"actions.action_card.source_content": "View source content",
4444
"actions.action_card.then_do": "Then do…",

0 commit comments

Comments
 (0)