-
Notifications
You must be signed in to change notification settings - Fork 517
feat: show notification badge on app icon #2645
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
Open
janburzinski
wants to merge
7
commits into
main
Choose a base branch
from
emdash/notification-number-xgw4r
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−44
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ba364c
fix(app): sync dock badge notifications
janburzinski 94a5250
fix(app): refresh badge after task archive
janburzinski bdfac9a
fix(app): match badge to command palette
janburzinski 7484488
refactor(renderer): centralize task notification helpers
janburzinski 5da51f2
style(renderer): sort notification imports
janburzinski 22d24dc
fix(app): ignore archived task notifications
janburzinski 9c03e8d
fix(app): align notification badge count
janburzinski 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
30 changes: 30 additions & 0 deletions
30
apps/emdash-desktop/src/main/core/app/app-badge-service.ts
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,30 @@ | ||
| import { app } from 'electron'; | ||
| import { log } from '@main/lib/logger'; | ||
|
|
||
| class AppBadgeService { | ||
| private unreadCount = 0; | ||
|
|
||
| initialize(): void { | ||
| this.clear(); | ||
| } | ||
|
|
||
| clear(): void { | ||
| this.setCount(0); | ||
| } | ||
|
|
||
| setVisibleNotificationCount(count: number): void { | ||
| this.setCount(Math.max(0, Math.floor(count))); | ||
| } | ||
|
|
||
| private setCount(count: number): void { | ||
| if (count === this.unreadCount) return; | ||
|
|
||
| this.unreadCount = count; | ||
| const succeeded = app.setBadgeCount(count); | ||
| if (!succeeded && count > 0) { | ||
| log.debug('app-badge: platform did not accept badge count', { count }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const appBadgeService = new AppBadgeService(); | ||
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
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
28 changes: 28 additions & 0 deletions
28
apps/emdash-desktop/src/renderer/app/notification-badge-sync.tsx
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,28 @@ | ||
| import { reaction } from 'mobx'; | ||
| import { useEffect } from 'react'; | ||
| import { getVisibleTaskNotificationCount } from '@renderer/features/tasks/stores/task-notifications'; | ||
| import { rpc } from '@renderer/lib/ipc'; | ||
| import { appState } from '@renderer/lib/stores/app-state'; | ||
|
|
||
| export function NotificationBadgeSync() { | ||
| useEffect( | ||
| () => | ||
| reaction( | ||
| () => { | ||
| const taskParams = | ||
| appState.navigation.currentViewId === 'task' | ||
| ? appState.navigation.viewParamsStore.task | ||
| : undefined; | ||
|
|
||
| return getVisibleTaskNotificationCount(taskParams?.projectId, taskParams?.taskId); | ||
| }, | ||
| (count) => { | ||
| void rpc.app.setNotificationBadgeCount(count); | ||
| }, | ||
| { fireImmediately: true } | ||
| ), | ||
| [] | ||
| ); | ||
|
|
||
| return null; | ||
| } |
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
94 changes: 94 additions & 0 deletions
94
apps/emdash-desktop/src/renderer/features/tasks/stores/task-notifications.ts
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,94 @@ | ||
| import { | ||
| asMounted, | ||
| getProjectManagerStore, | ||
| } from '@renderer/features/projects/stores/project-selectors'; | ||
| import type { ConversationStore } from '@renderer/features/tasks/conversations/conversation-manager'; | ||
| import { conversationRegistry } from '@renderer/features/tasks/stores/conversation-registry'; | ||
| import { isRegistered, type TaskStore } from '@renderer/features/tasks/stores/task-store'; | ||
|
|
||
| export type TaskNotificationItem = | ||
| | { kind: 'task'; projectId: string; taskStore: TaskStore } | ||
| | { kind: 'conversation'; projectId: string; taskId: string; conv: ConversationStore }; | ||
|
|
||
| function hasVisibleTaskNotification(taskId: string): boolean { | ||
| const conversations = conversationRegistry.get(taskId); | ||
| if (!conversations) return false; | ||
|
|
||
| const status = conversations.taskStatus; | ||
| return status !== null && status !== 'idle' && status !== 'working'; | ||
| } | ||
|
|
||
| function getUnseenConversationNotificationCount(taskId: string): number { | ||
| const conversations = conversationRegistry.get(taskId); | ||
| if (!conversations) return 0; | ||
|
|
||
| let count = 0; | ||
| for (const conversation of conversations.conversations.values()) { | ||
| if (!conversation.seen && conversation.indicatorStatus) count += 1; | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| export function getVisibleTaskNotificationCount( | ||
| currentProjectId: string | undefined, | ||
| currentTaskId: string | undefined | ||
| ): number { | ||
| let count = 0; | ||
|
|
||
| for (const projectStore of getProjectManagerStore().projects.values()) { | ||
| const mounted = asMounted(projectStore); | ||
| if (!mounted) continue; | ||
| const projectId = mounted.data.id; | ||
|
|
||
| for (const [taskId, taskStore] of mounted.taskManager.tasks) { | ||
| if (!isRegistered(taskStore)) continue; | ||
| if (taskStore.data.archivedAt) continue; | ||
| if (!hasVisibleTaskNotification(taskId)) continue; | ||
|
|
||
| if (projectId === currentProjectId && taskId === currentTaskId) { | ||
| count += getUnseenConversationNotificationCount(taskId); | ||
| } else { | ||
| count += 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| export function getTaskNotificationItems( | ||
| currentProjectId: string | undefined, | ||
| currentTaskId: string | undefined | ||
| ): TaskNotificationItem[] { | ||
| const result: TaskNotificationItem[] = []; | ||
|
|
||
| for (const projectStore of getProjectManagerStore().projects.values()) { | ||
| const mounted = asMounted(projectStore); | ||
| if (!mounted) continue; | ||
| const projectId = mounted.data.id; | ||
|
|
||
| for (const [taskId, taskStore] of mounted.taskManager.tasks) { | ||
| if (!isRegistered(taskStore)) continue; | ||
| if (taskStore.data.archivedAt) continue; | ||
| if (!hasVisibleTaskNotification(taskId)) continue; | ||
|
|
||
| if (projectId === currentProjectId && taskId === currentTaskId) { | ||
| const conversations = conversationRegistry.get(taskId)?.conversations.values() ?? []; | ||
| for (const conversation of conversations) { | ||
| if (!conversation.seen && conversation.indicatorStatus) { | ||
| result.push({ | ||
| kind: 'conversation', | ||
| projectId, | ||
| taskId, | ||
| conv: conversation, | ||
| }); | ||
| } | ||
| } | ||
| } else { | ||
| result.push({ kind: 'task', projectId, taskStore }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } |
Oops, something went wrong.
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.