-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add desktop dock icon indicator in Electron #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
df2653d
Add desktop dock icon indicator
marcaaron 772ba7a
fix newline
marcaaron b216c53
save lastReadActionIDs so we can reference them later
marcaaron 99c9b9e
not zero use sequenceNumber
marcaaron 40083b9
remove isUnread from report
marcaaron 3153f2e
Simplify the SidebarLink component
marcaaron 0e904e2
add electron events
marcaaron 50999a7
use throttle to minimize calls to the updater
marcaaron 7717b1b
add comment
marcaaron d9d1424
Move updateUnread method to its own utility
marcaaron 2ec176e
fix broken imports
marcaaron 5766871
Implement iOS
marcaaron 4499c7e
remove new line
marcaaron 515c1f4
Merge remote-tracking branch 'origin' into marcaaron-desktopbadge
marcaaron f83cfe7
create a index.desktop.js and index.website.js file
marcaaron 2ddade2
add android and ios
marcaaron f6b9958
fix comment
marcaaron a7f2d58
fix conflict
marcaaron 4608b09
eslint likes new lines
marcaaron 21a950b
fix index.website.js bundler for cross platform and fix import
roryabraham 34d66f5
remove unnecessary blacklist code
roryabraham a1532f5
fix conflicts
marcaaron dd72182
fix conflicts
marcaaron 26a6ced
Merge branch 'marcaaron-desktopbadge' of https://github.com/Expensify…
marcaaron a5792ce
use Math.max remove new line
marcaaron c640d6f
Fix bug where chat reports would not showing up as unread
marcaaron 0dbb4cf
fix conflicts
marcaaron 92bf235
woops
marcaaron 71fd6aa
remove unneeded stuff
marcaaron 2f2fb02
update names of methods and move to sign out area
marcaaron 58793f6
derp
marcaaron 30dfd18
woops snuck in old change
marcaaron 427185a
derp
marcaaron 8e5ead8
add Podfile.lock back
marcaaron 70a5b46
fix podfile
marcaaron aa1f1bd
make these constants consistent
marcaaron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import _ from 'underscore'; | ||
| import Ion from '../Ion'; | ||
| import IONKEYS from '../../IONKEYS'; | ||
|
|
||
| /** | ||
| * Web browsers have a tab title and favicon which can be updated to show there are unread comments | ||
| */ | ||
| import CONFIG from '../../CONFIG'; | ||
|
|
||
| // We conditionally import the ipcRenderer here so that we can | ||
| // communicate with the main Electron process in main.js | ||
| const ipcRenderer = window.require ? window.require('electron').ipcRenderer : null; | ||
|
|
||
| const reportMap = {}; | ||
|
|
||
| /** | ||
| * Updates the title and favicon of the current browser tab | ||
| * and Mac OS dock icon with an unread indicator. | ||
| * | ||
| * @param {boolean} hasUnread | ||
| */ | ||
| function updatePageTitleAndUnreadCount() { | ||
| const totalCount = _.reduce(reportMap, (total, report) => total + ((report && report.unreadActionCount) || 0), 0); | ||
| const hasUnread = totalCount > 0; | ||
| document.title = hasUnread ? `(NEW!) ${CONFIG.SITE_TITLE}` : CONFIG.SITE_TITLE; | ||
| document.getElementById('favicon').href = hasUnread ? CONFIG.FAVICON.UNREAD : CONFIG.FAVICON.DEFAULT; | ||
|
|
||
| if (ipcRenderer) { | ||
| // Ask the main Electron process to update our | ||
| // badge count in the Mac OS dock icon | ||
| ipcRenderer.send('request-update-badge-count', totalCount); | ||
| } | ||
| } | ||
|
|
||
| Ion.connect({ | ||
| key: IONKEYS.COLLECTION.REPORT, | ||
| callback: (report) => { | ||
| if (!report || !report.reportID) { | ||
| return; | ||
| } | ||
|
|
||
| reportMap[report.reportID] = report; | ||
marcaaron marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| updatePageTitleAndUnreadCount(); | ||
| } | ||
| }); | ||
|
|
||
| export default { | ||
| init: () => {}, | ||
| }; | ||
4 changes: 3 additions & 1 deletion
4
src/lib/PageTitleUpdater/index.native.js → ...ib/UnreadIndicatorUpdater/index.native.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| /** | ||
| * Native devices (iOS, Android) don't have page title like web does, so this module doesn't do anything | ||
| */ | ||
| export default () => {}; | ||
| export default { | ||
| init: () => {}, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,9 @@ Ion.connect({ | |
| // Keeps track of the max sequence number for each report | ||
| const reportMaxSequenceNumbers = {}; | ||
|
|
||
| // Keeps track of the last read for each report | ||
| const lastReadActionIDs = {}; | ||
|
|
||
| // List of reportIDs that we define in .env | ||
| const configReportIDs = CONFIG.REPORT_IDS.split(',').map(Number); | ||
|
|
||
|
|
@@ -56,29 +59,30 @@ const configReportIDs = CONFIG.REPORT_IDS.split(',').map(Number); | |
| * @param {object} report | ||
| * @returns {boolean} | ||
| */ | ||
| function hasUnreadActions(report) { | ||
| function getUnreadActionCount(report) { | ||
| const usersLastReadActionID = lodashGet(report, [ | ||
| 'reportNameValuePairs', | ||
| `lastReadActionID_${currentUserAccountID}`, | ||
| ]); | ||
|
|
||
| // Save the lastReadActionID locally so we can access this later | ||
| lastReadActionIDs[report.reportID] = usersLastReadActionID; | ||
|
|
||
| if (report.reportActionList.length === 0) { | ||
| return false; | ||
| return 0; | ||
| } | ||
|
|
||
| if (!usersLastReadActionID) { | ||
| return true; | ||
| return report.reportActionList.length; | ||
| } | ||
|
|
||
| // Find the most recent sequence number from the report actions | ||
| const maxSequenceNumber = reportMaxSequenceNumbers[report.reportID]; | ||
|
|
||
| if (!maxSequenceNumber) { | ||
| return false; | ||
| } | ||
|
|
||
| // There are unread items if the last one the user has read is less than the highest sequence number we have | ||
| return usersLastReadActionID < maxSequenceNumber; | ||
| // There are unread items if the last one the user has read is less | ||
| // than the highest sequence number we have. | ||
| const unreadActionCount = (maxSequenceNumber || report.reportActionList.length) - usersLastReadActionID; | ||
| return unreadActionCount > 0 ? unreadActionCount : 0; | ||
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -92,11 +96,13 @@ function hasUnreadActions(report) { | |
| * @returns {object} | ||
| */ | ||
| function getSimplifiedReportObject(report) { | ||
| const unreadActionCount = getUnreadActionCount(report); | ||
| return { | ||
| reportID: report.reportID, | ||
| reportName: report.reportName, | ||
| reportNameValuePairs: report.reportNameValuePairs, | ||
| isUnread: hasUnreadActions(report), | ||
| unreadActionCount, | ||
| isUnread: unreadActionCount > 0, | ||
marcaaron marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pinnedReport: configReportIDs.includes(report.reportID), | ||
| }; | ||
| } | ||
|
|
@@ -183,6 +189,7 @@ function updateReportWithNewAction(reportID, reportAction) { | |
| // by handleReportChanged | ||
| Ion.merge(`${IONKEYS.COLLECTION.REPORT}${reportID}`, { | ||
| reportID, | ||
| unreadActionCount: newMaxSequenceNumber - (lastReadActionIDs[reportID] || 0), | ||
| isUnread: hasNewSequenceNumber, | ||
| maxSequenceNumber: reportAction.sequenceNumber, | ||
| }); | ||
|
|
@@ -440,9 +447,12 @@ function updateLastReadActionID(reportID, sequenceNumber) { | |
| return; | ||
| } | ||
|
|
||
| lastReadActionIDs[reportID] = sequenceNumber; | ||
|
|
||
| // Update the lastReadActionID on the report optimistically | ||
| Ion.merge(`${IONKEYS.COLLECTION.REPORT}${reportID}`, { | ||
| isUnread: false, | ||
| unreadActionCount: 0, | ||
| reportNameValuePairs: { | ||
| [`lastReadActionID_${currentUserAccountID}`]: sequenceNumber, | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.