fix(app): suppress idle sound after interrupt
This commit is contained in:
parent
613562f504
commit
02a7b0637d
1 changed files with 28 additions and 3 deletions
|
|
@ -132,6 +132,28 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
|
||||||
const [index, setIndex] = createStore<NotificationIndex>(buildNotificationIndex(store.list))
|
const [index, setIndex] = createStore<NotificationIndex>(buildNotificationIndex(store.list))
|
||||||
|
|
||||||
const meta = { pruned: false, disposed: false }
|
const meta = { pruned: false, disposed: false }
|
||||||
|
const idleSuppressMs = 5000
|
||||||
|
const idleSuppressedUntilBySession = new Map<string, number>()
|
||||||
|
|
||||||
|
const idleSuppressKey = (directory: string, sessionID?: string) => {
|
||||||
|
if (!sessionID) return
|
||||||
|
return `${directory}:${sessionID}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const markIdleSuppressed = (directory: string, sessionID?: string) => {
|
||||||
|
const key = idleSuppressKey(directory, sessionID)
|
||||||
|
if (!key) return
|
||||||
|
idleSuppressedUntilBySession.set(key, Date.now() + idleSuppressMs)
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldSuppressIdle = (directory: string, sessionID?: string) => {
|
||||||
|
const key = idleSuppressKey(directory, sessionID)
|
||||||
|
if (!key) return false
|
||||||
|
const until = idleSuppressedUntilBySession.get(key)
|
||||||
|
if (until === undefined) return false
|
||||||
|
idleSuppressedUntilBySession.delete(key)
|
||||||
|
return until > Date.now()
|
||||||
|
}
|
||||||
|
|
||||||
const updateUnseen = (scope: "session" | "project", key: string, unseen: Notification[]) => {
|
const updateUnseen = (scope: "session" | "project", key: string, unseen: Notification[]) => {
|
||||||
setIndex(scope, "unseen", key, unseen)
|
setIndex(scope, "unseen", key, unseen)
|
||||||
|
|
@ -290,12 +312,15 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
|
||||||
if (event.type !== "session.idle" && event.type !== "session.error") return
|
if (event.type !== "session.idle" && event.type !== "session.error") return
|
||||||
|
|
||||||
const directory = e.name
|
const directory = e.name
|
||||||
const time = Date.now()
|
if (event.type === "session.error") {
|
||||||
|
markIdleSuppressed(directory, event.properties.sessionID)
|
||||||
|
}
|
||||||
if (event.type === "session.idle") {
|
if (event.type === "session.idle") {
|
||||||
handleSessionIdle(directory, event, time)
|
if (shouldSuppressIdle(directory, event.properties.sessionID)) return
|
||||||
|
handleSessionIdle(directory, event, Date.now())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handleSessionError(directory, event, time)
|
handleSessionError(directory, event, Date.now())
|
||||||
})
|
})
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
meta.disposed = true
|
meta.disposed = true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue