Fixed unread tray icon always showing when windows is blurred (#1017)

This commit is contained in:
Harvzor 2019-09-23 10:34:52 -05:00
parent f4929c7c9b
commit de07989480

View file

@ -6,8 +6,8 @@ import { BadgeStore } from 'mailspring-exports';
// https://github.com/atom/electron/issues/1299 // https://github.com/atom/electron/issues/1299
const { platform } = process; const { platform } = process;
const INBOX_ZERO_ICON = path.join(__dirname, '..', 'assets', platform, 'MenuItem-Inbox-Zero.png'); 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_FULL_ICON = path.join(__dirname, '..', 'assets', platform, 'MenuItem-Inbox-Full.png');
const INBOX_UNREAD_ALT_ICON = path.join( const INBOX_FULL_UNREAD_ICON = path.join(
__dirname, __dirname,
'..', '..',
'assets', 'assets',
@ -15,12 +15,27 @@ const INBOX_UNREAD_ALT_ICON = path.join(
'MenuItem-Inbox-Full-NewItems.png' '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 { class SystemTrayIconStore {
static INBOX_ZERO_ICON = INBOX_ZERO_ICON; 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; _windowBlurred = false;
_unsubscribers: (() => void)[]; _unsubscribers: (() => void)[];
@ -46,15 +61,6 @@ class SystemTrayIconStore {
this._unsubscribers.forEach(unsub => unsub()); 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 = () => { _onWindowBlur = () => {
// Set state to blurred, but don't trigger a change. The icon should only be // Set state to blurred, but don't trigger a change. The icon should only be
// updated when the count changes // updated when the count changes
@ -71,8 +77,14 @@ class SystemTrayIconStore {
const unread = BadgeStore.unread(); const unread = BadgeStore.unread();
const unreadString = (+unread).toLocaleString(); const unreadString = (+unread).toLocaleString();
const isInboxZero = BadgeStore.total() === 0; 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);
}; };
} }