mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-22 15:15:12 +08:00
Fixed unread tray icon always showing when windows is blurred (#1017)
This commit is contained in:
parent
f4929c7c9b
commit
de07989480
1 changed files with 27 additions and 15 deletions
|
@ -6,8 +6,8 @@ import { BadgeStore } from 'mailspring-exports';
|
|||
// https://github.com/atom/electron/issues/1299
|
||||
const { platform } = process;
|
||||
const INBOX_ZERO_ICON = path.join(__dirname, '..', 'assets', platform, 'MenuItem-Inbox-Zero.png');
|
||||
const INBOX_UNREAD_ICON = path.join(__dirname, '..', 'assets', platform, 'MenuItem-Inbox-Full.png');
|
||||
const INBOX_UNREAD_ALT_ICON = path.join(
|
||||
const INBOX_FULL_ICON = path.join(__dirname, '..', 'assets', platform, 'MenuItem-Inbox-Full.png');
|
||||
const INBOX_FULL_UNREAD_ICON = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'assets',
|
||||
|
@ -15,12 +15,27 @@ const INBOX_UNREAD_ALT_ICON = path.join(
|
|||
'MenuItem-Inbox-Full-NewItems.png'
|
||||
);
|
||||
|
||||
/*
|
||||
Current / Intended Behavior:
|
||||
|
||||
- If your inbox is at "Inbox Zero", we use an empty looking icon in the tray.
|
||||
|
||||
- If the app is in the foreground, we show a gray "full mailbox" icon.
|
||||
|
||||
- If the app is in the backgrorund, WHEN the count changes, we switch to showing
|
||||
a blue "new mail in your mailbox" icon. (Eg: going from 4 unread to 5 unread
|
||||
will trigger it.)
|
||||
|
||||
The blue is meant to reflect "new stuff since you last foregrounded the app",
|
||||
not an absolute count of unread messages. This is a very old design decision (2014?)
|
||||
and maybe it should be reconsidered soon.
|
||||
*/
|
||||
class SystemTrayIconStore {
|
||||
static INBOX_ZERO_ICON = INBOX_ZERO_ICON;
|
||||
|
||||
static INBOX_UNREAD_ICON = INBOX_UNREAD_ICON;
|
||||
static INBOX_FULL_ICON = INBOX_FULL_ICON;
|
||||
|
||||
static INBOX_UNREAD_ALT_ICON = INBOX_UNREAD_ALT_ICON;
|
||||
static INBOX_FULL_UNREAD_ICON = INBOX_FULL_UNREAD_ICON;
|
||||
|
||||
_windowBlurred = false;
|
||||
_unsubscribers: (() => void)[];
|
||||
|
@ -46,15 +61,6 @@ class SystemTrayIconStore {
|
|||
this._unsubscribers.forEach(unsub => unsub());
|
||||
}
|
||||
|
||||
_getIconImageData(isInboxZero, isWindowBlurred) {
|
||||
if (isInboxZero) {
|
||||
return { iconPath: INBOX_ZERO_ICON, isTemplateImg: true };
|
||||
}
|
||||
return isWindowBlurred
|
||||
? { iconPath: INBOX_UNREAD_ALT_ICON, isTemplateImg: false }
|
||||
: { iconPath: INBOX_UNREAD_ICON, isTemplateImg: true };
|
||||
}
|
||||
|
||||
_onWindowBlur = () => {
|
||||
// Set state to blurred, but don't trigger a change. The icon should only be
|
||||
// updated when the count changes
|
||||
|
@ -71,8 +77,14 @@ class SystemTrayIconStore {
|
|||
const unread = BadgeStore.unread();
|
||||
const unreadString = (+unread).toLocaleString();
|
||||
const isInboxZero = BadgeStore.total() === 0;
|
||||
const { iconPath, isTemplateImg } = this._getIconImageData(isInboxZero, this._windowBlurred);
|
||||
ipcRenderer.send('update-system-tray', iconPath, unreadString, isTemplateImg);
|
||||
|
||||
let icon = { path: INBOX_FULL_ICON, isTemplateImg: true };
|
||||
if (isInboxZero) {
|
||||
icon = { path: INBOX_ZERO_ICON, isTemplateImg: true };
|
||||
} else if (this._windowBlurred && unread !== 0) {
|
||||
icon = { path: INBOX_FULL_UNREAD_ICON, isTemplateImg: false };
|
||||
}
|
||||
ipcRenderer.send('update-system-tray', icon.path, unreadString, icon.isTemplateImg);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue