Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions apps/emdash-desktop/src/main/core/app/app-badge-service.ts
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)));
}
Comment thread
janburzinski marked this conversation as resolved.

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();
4 changes: 4 additions & 0 deletions apps/emdash-desktop/src/main/core/app/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getDiagnosticLogAttachment } from '@main/lib/file-logger';
import { telemetryService } from '@main/lib/telemetry';
import { createRPCController } from '@shared/lib/ipc/rpc';
import type { OpenInAppId } from '@shared/openInApps';
import { appBadgeService } from './app-badge-service';
import { appService } from './service';

export const appController = createRPCController({
Expand Down Expand Up @@ -109,5 +110,8 @@ export const appController = createRPCController({
getAppVersion: () => appService.getCachedAppVersion(),
getElectronVersion: () => process.versions.electron,
getPlatform: () => process.platform,
setNotificationBadgeCount: (count: number) => {
appBadgeService.setVisibleNotificationCount(count);
},
getDiagnosticLogAttachment,
});
4 changes: 3 additions & 1 deletion apps/emdash-desktop/src/main/core/tasks/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ export class TaskService implements Hookable<TaskLifecycleHooks> {

async restoreTask(id: string): Promise<void> {
const task = await restoreTask(id);
if (task) this._hooks.callHookBackground('task:updated', task);
if (task) {
this._hooks.callHookBackground('task:updated', task);
}
}

async renameTask(
Expand Down
3 changes: 3 additions & 0 deletions apps/emdash-desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createMainWindow } from './app/window';
import { providerTokenRegistry } from './core/account/provider-token-registry';
import { emdashAccountService } from './core/account/services/emdash-account-service';
import { agentHookService } from './core/agent-hooks/agent-hook-service';
import { appBadgeService } from './core/app/app-badge-service';
import { appService } from './core/app/service';
import { automationsService } from './core/automations/automations-service';
import { cleanupLegacyBrowserPartitions } from './core/browser/browser-partition-cleanup';
Expand Down Expand Up @@ -133,6 +134,7 @@ void app.whenReady().then(async () => {
prSyncScheduler.initialize();
automationsService.start();
appService.initialize();
appBadgeService.initialize();
await appSettingsService.initialize();
browserWebContentsRegistry.setKeyboardSettings(await appSettingsService.get('keyboard'));
setBrowserCorsRelaxationSettings(await appSettingsService.get('browser'));
Expand Down Expand Up @@ -193,6 +195,7 @@ app.on('before-quit', (event) => {
telemetryService.capture('app_closed');
void telemetryService.dispose().finally(() => {
automationsService.stop();
appBadgeService.clear();
agentHookService.dispose();
stopResourceSampler();
updateService.dispose();
Expand Down
2 changes: 2 additions & 0 deletions apps/emdash-desktop/src/renderer/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QueryClientProvider } from '@tanstack/react-query';
import { useCallback, useEffect, useState } from 'react';
import { AppMenuEvents } from './app/app-menu-events';
import { NotificationBadgeSync } from './app/notification-badge-sync';
import { WelcomeScreen } from './app/welcome';
import { Workspace } from './app/workspace';
import { IntegrationsProvider } from './features/integrations/integrations-provider';
Expand Down Expand Up @@ -99,6 +100,7 @@ function AppContent() {
<IntegrationsProvider>
<WorkspaceViewProvider>
<AppMenuEvents onOpenSettings={handleOpenSettingsFromMenu} />
<NotificationBadgeSync />
<RightSidebarProvider>
<ThemeProvider>
<ModalRenderer />
Expand Down
28 changes: 28 additions & 0 deletions apps/emdash-desktop/src/renderer/app/notification-badge-sync.tsx
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;
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { Command } from 'cmdk';
import { useObserver } from 'mobx-react-lite';
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 { getTaskNotificationItems } from '@renderer/features/tasks/stores/task-notifications';
import { getTaskView } from '@renderer/features/tasks/stores/task-selectors';
import { isRegistered, type TaskStore } from '@renderer/features/tasks/stores/task-store';
import type { NavigateFnTyped } from '@renderer/lib/layout/navigation-provider';
import { cn } from '@renderer/utils/utils';
import { PaletteConversationItem } from './palette-conversation-item';
import { PaletteTaskItem } from './palette-task-item';

type NotificationItem =
| { kind: 'task'; projectId: string; taskStore: TaskStore }
| { kind: 'conversation'; projectId: string; taskId: string; conv: ConversationStore };

const GROUP_CLASS = cn(
'[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5',
'[&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium',
Expand All @@ -36,38 +26,7 @@ export function PaletteNotificationsGroup({
onClose,
navigate,
}: PaletteNotificationsGroupProps) {
const items = useObserver((): NotificationItem[] => {
const result: NotificationItem[] = [];

for (const projectStore of getProjectManagerStore().projects.values()) {
const mounted = asMounted(projectStore);
if (!mounted) continue;
const pid = mounted.data.id;

for (const [tid, taskStore] of mounted.taskManager.tasks) {
if (!isRegistered(taskStore)) continue;
const conversations = conversationRegistry.get(tid);
if (!conversations) continue;

const status = conversations.taskStatus;
// Only surface awaiting-input, error, completed — not working or idle.
if (!status || status === 'idle' || status === 'working') continue;

if (pid === currentProjectId && tid === currentTaskId) {
// We're already in this task — surface individual unseen conversations.
for (const conv of conversations.conversations.values()) {
if (!conv.seen && conv.indicatorStatus) {
result.push({ kind: 'conversation', projectId: pid, taskId: tid, conv });
}
}
} else {
result.push({ kind: 'task', projectId: pid, taskStore });
}
}
}

return result;
});
const items = useObserver(() => getTaskNotificationItems(currentProjectId, currentTaskId));

if (items.length === 0) return null;

Expand Down
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;
}
Loading