mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Desktop notifications now carry a narrow target payload so clicking a permission, completion, or scheduled-task notification can reopen the matching tab and reconnect the session. macOS uses the native notification bridge for tap callbacks, while the shared desktop notification layer also accepts plugin action payloads where the platform exposes them. Constraint: Notification clicks need to activate existing desktop tabs without adding a new navigation state channel. Rejected: Store only notification ids and infer the active session later | stale notifications would point at the wrong session after tab changes. Confidence: high Scope-risk: moderate Directive: Keep notification targets serializable and versioned through desktopNotifications before adding new target types. Tested: bun run quality:pr with ALLOW_CLI_CORE_CHANGE=1; desktop unit tests; server tests; native sidecar build and cargo check; docs build. Not-tested: Packaged Windows toast activation runtime; current fallback depends on Tauri notification action delivery.
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { useChatStore } from '../stores/chatStore'
|
|
import { useSessionStore } from '../stores/sessionStore'
|
|
import { SCHEDULED_TAB_ID, useTabStore } from '../stores/tabStore'
|
|
import {
|
|
installDesktopNotificationClickListener,
|
|
type DesktopNotificationTarget,
|
|
} from './desktopNotifications'
|
|
|
|
const SCHEDULED_TAB_TITLE = 'Scheduled Tasks'
|
|
|
|
export function openDesktopNotificationTarget(target: DesktopNotificationTarget): void {
|
|
if (target.type === 'scheduled') {
|
|
useTabStore.getState().openTab(SCHEDULED_TAB_ID, SCHEDULED_TAB_TITLE, 'scheduled')
|
|
return
|
|
}
|
|
|
|
const knownTitle = useSessionStore
|
|
.getState()
|
|
.sessions
|
|
.find((session) => session.id === target.sessionId)
|
|
?.title
|
|
useTabStore.getState().openTab(target.sessionId, target.title || knownTitle || 'Session', 'session')
|
|
useChatStore.getState().connectToSession(target.sessionId)
|
|
}
|
|
|
|
export function installDesktopNotificationNavigation(): Promise<() => void> {
|
|
return installDesktopNotificationClickListener(openDesktopNotificationTarget)
|
|
}
|