From de07989480568851dce9cfec54b35c773a465371 Mon Sep 17 00:00:00 2001 From: Harvzor Date: Mon, 23 Sep 2019 10:34:52 -0500 Subject: [PATCH] Fixed unread tray icon always showing when windows is blurred (#1017) --- .../system-tray/lib/system-tray-icon-store.ts | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/app/internal_packages/system-tray/lib/system-tray-icon-store.ts b/app/internal_packages/system-tray/lib/system-tray-icon-store.ts index 0eae56843..7d7f7767b 100644 --- a/app/internal_packages/system-tray/lib/system-tray-icon-store.ts +++ b/app/internal_packages/system-tray/lib/system-tray-icon-store.ts @@ -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); }; }