fix: restore vscode native notification behavior

Move VS Code/Cursor desktop notifications onto the webview Notification API instead of the extension-host watcher path, which could not reliably produce native OS notifications.

Route OpenCode runtime events from the shared sync pipeline into the VS Code webview so completion, error, question, and permission notifications use the same live event stream as the UI.

Respect the OpenChamber notification settings in VS Code, including template rendering, completion cooldowns, permission auto-accept suppression, and the notify-while-focused mode.

Use VS Code's window focus signal from the extension host instead of document.hasFocus() inside the webview, so hidden-only notifications are suppressed while Cursor or VS Code is focused across platforms.
This commit is contained in:
Bohdan Triapitsyn
2026-05-19 02:06:32 +03:00
parent d928185640
commit a57b02a308
8 changed files with 484 additions and 45 deletions
+11
View File
@@ -6,6 +6,7 @@ import type { StoreApi } from "zustand"
import { useStore } from "zustand"
import type { OpencodeClient } from "@opencode-ai/sdk/v2/client"
import { createEventPipeline } from "./event-pipeline"
import { isVSCodeRuntime } from "@/lib/desktop"
import { reduceGlobalEvent, applyGlobalProject, applyDirectoryEvent } from "./event-reducer"
import { useGlobalSyncStore, type GlobalSyncStore } from "./global-sync-store"
import { ChildStoreManager, type DirectoryStore } from "./child-store"
@@ -308,6 +309,15 @@ type EventRoutingIndex = {
sessionMessageIdsById: Map<string, Set<string>>
}
const SHOULD_DISPATCH_VSCODE_NOTIFICATIONS = isVSCodeRuntime()
const dispatchVSCodeRuntimeNotificationEvent = (directory: string, payload: Event) => {
if (!SHOULD_DISPATCH_VSCODE_NOTIFICATIONS || typeof window === "undefined") return
window.dispatchEvent(new CustomEvent("openchamber:vscode-notification-event", {
detail: { directory, payload },
}))
}
const createEventRoutingIndex = (): EventRoutingIndex => ({
sessionDirectoryById: new Map(),
messageSessionById: new Map(),
@@ -1432,6 +1442,7 @@ export function SyncProvider(props: {
return resolveDirectoryFromRoutingIndex(routingIndex, directory, payload, childStores)
},
onEvent: (directory, payload) => {
dispatchVSCodeRuntimeNotificationEvent(directory, payload)
if (payload.type === "installation.update-available") {
const version = typeof (payload.properties as { version?: unknown })?.version === "string"
? (payload.properties as { version: string }).version