|
1 | 1 | import { name } from "@pkg"
|
2 | 2 | import { app, Menu, nativeImage, Tray } from "electron"
|
3 | 3 |
|
4 |
| -import { isMacOS } from "~/env" |
| 4 | +import { isMacOS, isWindows } from "~/env" |
5 | 5 | import { getTrayIconPath } from "~/helper"
|
6 | 6 | import { logger, revealLogFile } from "~/logger"
|
7 | 7 | import { checkForAppUpdates } from "~/updater"
|
8 | 8 |
|
9 | 9 | import { getMainWindowOrCreate } from "../window"
|
| 10 | +import { getDockCount } from "./dock" |
10 | 11 | import { t } from "./i18n"
|
11 | 12 | import { store } from "./store"
|
12 | 13 |
|
13 | 14 | // https://www.electronjs.org/docs/latest/tutorial/tray
|
14 | 15 |
|
15 | 16 | let tray: Tray | null = null
|
16 | 17 |
|
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 | + : []), |
30 | 29 | {
|
31 | 30 | label: t("menu.open", { name }),
|
32 | 31 | click: showWindow,
|
@@ -71,9 +70,27 @@ export const registerAppTray = () => {
|
71 | 70 | },
|
72 | 71 | },
|
73 | 72 | ])
|
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()) |
75 | 87 | 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 | + } |
77 | 94 | }
|
78 | 95 |
|
79 | 96 | const showWindow = () => {
|
|
0 commit comments