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