Просмотр исходного кода

fix(app): don't show notification on session if active

Adam 1 месяц назад
Родитель
Сommit
64c80f1b51
1 измененных файлов с 18 добавлено и 7 удалено
  1. 18 7
      packages/app/src/context/notification.tsx

+ 18 - 7
packages/app/src/context/notification.tsx

@@ -1,5 +1,6 @@
 import { createStore } from "solid-js/store"
 import { createEffect, onCleanup } from "solid-js"
+import { useParams } from "@solidjs/router"
 import { createSimpleContext } from "@opencode-ai/ui/context"
 import { useGlobalSDK } from "./global-sdk"
 import { useGlobalSync } from "./global-sync"
@@ -7,7 +8,7 @@ import { usePlatform } from "@/context/platform"
 import { useLanguage } from "@/context/language"
 import { useSettings } from "@/context/settings"
 import { Binary } from "@opencode-ai/util/binary"
-import { base64Encode } from "@opencode-ai/util/encode"
+import { base64Decode, base64Encode } from "@opencode-ai/util/encode"
 import { EventSessionError } from "@opencode-ai/sdk/v2"
 import { Persist, persisted } from "@/utils/persist"
 import { playSound, soundSrc } from "@/utils/sound"
@@ -44,6 +45,7 @@ function pruneNotifications(list: Notification[]) {
 export const { use: useNotification, provider: NotificationProvider } = createSimpleContext({
   name: "Notification",
   init: () => {
+    const params = useParams()
     const globalSDK = useGlobalSDK()
     const globalSync = useGlobalSync()
     const platform = usePlatform()
@@ -73,10 +75,15 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
     const unsub = globalSDK.event.listen((e) => {
       const directory = e.name
       const event = e.details
-      const base = {
-        directory,
-        time: Date.now(),
-        viewed: false,
+      const time = Date.now()
+      const activeDirectory = params.dir ? base64Decode(params.dir) : undefined
+      const activeSession = params.id
+      const viewed = (sessionID?: string) => {
+        if (!activeDirectory) return false
+        if (!activeSession) return false
+        if (!sessionID) return false
+        if (directory !== activeDirectory) return false
+        return sessionID === activeSession
       }
       switch (event.type) {
         case "session.idle": {
@@ -89,7 +96,9 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
           playSound(soundSrc(settings.sounds.agent()))
 
           append({
-            ...base,
+            directory,
+            time,
+            viewed: viewed(sessionID),
             type: "turn-complete",
             session: sessionID,
           })
@@ -115,7 +124,9 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
 
           const error = "error" in event.properties ? event.properties.error : undefined
           append({
-            ...base,
+            directory,
+            time,
+            viewed: viewed(sessionID),
             type: "error",
             session: sessionID ?? "global",
             error,