Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.
TypeScript ai-meeting-assistantai-notetakerelectrongranola-alternativelinuxllama-cpplocal-ailocal-firstmacosmcpmeeting-minutesmeeting-notesoffline-firstopen-sourceprivacyspeech-to-texttranscriptionwhisperwhisper-cppwindows
Auto end: a recording stops by itself once the call's window is gone (Zoom's meeting window, Teams' Leave button), even one started by hand and even while Zoom keeps the mic; a window on another desktop is not gone, and the log says what the mic did after the window went away
christianmatd5d4e5b580f1
diff --git a/app/native/yogurt-mac/main.swift b/app/native/yogurt-mac/main.swiftindex 3291a4c5..3acceff7 100644--- a/app/native/yogurt-mac/main.swift+++ b/app/native/yogurt-mac/main.swift@@ -444,6 +444,32 @@ func missedWindows(_ app: AXUIElement, _ pid: pid_t) -> (windows: [[String: Any]return (windows, mac)}+/// The window number behind an accessibility window: private, but stable for years and used by window managers. Only+/// windows of the current desktop are listed by accessibility, so this is how a call window on another one is told apart+/// from one that closed.+@_silgen_name("_AXUIElementGetWindow")+func _AXUIElementGetWindow(_ element: AXUIElement, _ id: UnsafeMutablePointer<CGWindowID>) -> AXError+func windowNumber(_ w: AXUIElement) -> CGWindowID? {+ var id: CGWindowID = 0+ return _AXUIElementGetWindow(w, &id) == .success && id != 0 ? id : nil+}+/// the window numbers of each app's call windows at its last reading with a call+var callWindowNumbers: [pid_t: Set<CGWindowID>] = [:]+/// Whether a call window read before still exists while accessibility no longer lists it: on another desktop or a full+/// screen Space, not closed. A window that is listed but has lost its call controls (Teams after the call) is gone.+func callWindowOutOfSight(_ app: AXUIElement, _ pid: pid_t) -> Bool {+ guard let known = callWindowNumbers[pid], !known.isEmpty else { return false }+ let listed = Set(((axAttr(app, kAXWindowsAttribute) as? [AXUIElement]) ?? []).compactMap(windowNumber))+ let info = (CGWindowListCopyWindowInfo([.optionAll], kCGNullWindowID) as? [[String: Any]]) ?? []+ let alive = Set(info.compactMap { w -> CGWindowID? in+ guard (w[kCGWindowOwnerPID as String] as? Int) == Int(pid), let n = w[kCGWindowNumber as String] as? Int else { return nil }+ return CGWindowID(n)+ })+ // a closed window is forgotten+ callWindowNumbers[pid] = known.intersection(alive)+ return !known.intersection(alive).subtracting(listed).isEmpty+}+func watchCalls(every: Int, ids: [String], pids: [pid_t] = []) {// Yogurt closes stdin to stop the watch (and a crashed Yogurt closes it too)DispatchQueue.global().async { _ = FileHandle.standardInput.readDataToEndOfFile(); DispatchQueue.main.sync { resetTrees() }; exit(0) }@@ -484,6 +510,7 @@ func watchCalls(every: Int, ids: [String], pids: [pid_t] = []) {if chromium.contains(id) && !id.hasPrefix("com.microsoft.teams") {for w in wins.prefix(4) { AXUIElementSetAttributeValue(w, "AXManualAccessibility" as CFString, kCFBooleanTrue) }}+ callWindowNumbers[target.processIdentifier] = Set(wins.compactMap(windowNumber))let zoom = id == "us.zoom.xos"var budget = zoom ? 1500 : 4000// the tab title belongs to the window that was focused when it was read@@ -502,6 +529,8 @@ func watchCalls(every: Int, ids: [String], pids: [pid_t] = []) {} else {// which windows were looked at and how, so a log can say why a call was missed (#111)var o: [String: Any] = ["t": t, "error": running.isEmpty ? "not-running" : lastControlLook.isEmpty ? "no-call-window" : "no-call-window (\(lastControlLook))"]+ // the call window is still there, out of accessibility's sight: Yogurt must not take that for the call ending+ if running.contains(where: { callWindowOutOfSight(AXUIElementCreateApplication($0.processIdentifier), $0.processIdentifier) }) { o["hidden"] = true }if let (id, app, pid) = teams {misses += 1if misses == 10 {diff --git a/app/src/main/callNames/index.ts b/app/src/main/callNames/index.tsindex 1e089bcc..9dcf3462 100644--- a/app/src/main/callNames/index.ts+++ b/app/src/main/callNames/index.ts@@ -13,7 +13,9 @@ import { readCall, summarize, type AxWindow, type CallKind } from './parse'/** what yogurt-mac call-watch prints each time it reads: the call windows, or why it could not *//** macWindows: how many normal windows of the app the Mac itself shows, beside the ones accessibility lists (#138) */-export type WatchLine = { t: number; app?: string; windows?: AxWindow[]; error?: string; macWindows?: number }+/** hidden: no call window accessibility can see, but the Mac still has the one that was the call (another desktop, a full+ * screen Space): the call is not over */+export type WatchLine = { t: number; app?: string; windows?: AxWindow[]; error?: string; macWindows?: number; hidden?: boolean }/** pids: read only these processes' windows (the call app's processes on the mic); none known, the app's frontmost with a call */export type Watch = (ids: string[], onLine: (l: WatchLine) => void, pids?: number[]) => { stop(): void }@@ -63,7 +65,7 @@ const MAX_RESTARTS = 20const LOGGED_CHANGES = 30type Sample = Omit<CallSample, 'ms'> & { t: number }-type Session = { app: string | null; ids: string[]; pids?: number[]; heardAt: number; quietMs: number; restarts: number; samples: Sample[]; priorLines: Set<number>; watch?: { stop(): void }; everyApp: boolean; offset?: number; startedAt: number; pictured: boolean; missPictured?: boolean; errors: Set<string>; last: string; logged: number }+type Session = { app: string | null; ids: string[]; pids?: number[]; heardAt: number; quietMs: number; restarts: number; samples: Sample[]; priorLines: Set<number>; watch?: { stop(): void }; everyApp: boolean; offset?: number; startedAt: number; pictured: boolean; missPictured?: boolean; errors: Set<string>; last: string; logged: number; /** a call window with people was read (Zoom, Teams) */ windowSeen?: CallKind; /** since when the readings say that window is gone, and the last one that said so */ goneSince?: number; goneAt?: number }export function hookCallNames(p: {store: Pick<Store, 'meeting' | 'segments' | 'setSegmentSpeakers' | 'updateMeeting'>@@ -98,10 +100,27 @@ export function hookCallNames(p: {return s.samples.map(({ t, ...r }) => ({ ...r, ms: t - zero - APP_LAG_MS }))}+ /** the call window was read again after the readings said it was gone */+ const windowBack = (s: Session) => {+ if (s.goneSince !== undefined) log(`call names: the ${s.windowSeen} call window is back after ${Math.round((now() - s.goneSince) / 1000)} s`)+ s.goneSince = undefined; s.goneAt = undefined+ }+const onLine = (id: string, s: Session, l: WatchLine) => {s.quietMs = Math.min(MAX_QUIET_MS, Math.max(QUIET_MS, 3 * (now() - s.heardAt)))s.heardAt = now()if (l.error || !l.app || !l.windows) {+ // the call window gone: the reader looked and found none (or the app quit). Anything else (no permission, a slow+ // window) says nothing either way.+ const gone = !!l.error && (l.error.startsWith('no-call-window') || l.error === 'not-running')+ if (gone && l.hidden) {+ if (!s.errors.has('hidden')) { s.errors.add('hidden'); log('call names: the call window is out of sight (another desktop or full screen), not closed') }+ windowBack(s)+ }+ else if (gone && s.windowSeen) {+ if (s.goneSince === undefined) { s.goneSince = now(); log(`call names: the ${s.windowSeen} call window went away`) }+ s.goneAt = now()+ } else { s.goneSince = undefined; s.goneAt = undefined }const why = l.error ?? 'nothing read'if (!s.errors.has(why)) { s.errors.add(why); log(`call names: ${why}${why === 'not-trusted' ? ' (no Accessibility permission): the other side stays Them' : ''}`) }// a call app with no call window sends its windows once, so the log shows what it gives when a call is missed (#138)@@ -124,6 +143,12 @@ export function hookCallNames(p: {const most = Math.max(r.participants.length, ...s.samples.filter((x) => x.ok !== false && l.t - x.t <= RECENT_MS).map((x) => x.participants.length))if (byMute && most > r.participants.length) r.speaking = []s.samples.push({ t: l.t, ...r, most })+ // Zoom's meeting window and Teams' Leave button are there only during a call. A Meet tab is not followed: switching+ // tabs hides it from the reader, and the browser lets go of the mic as soon as its call ends.+ if (kind === 'zoom' || kind === 'teams') {+ if (r.participants.length) s.windowSeen ??= kind+ windowBack(s)+ }// counts only: main.log is pasted into public issues, and names belong to the people in the callconst said = `${r.speaking.length} of ${r.participants.length}${r.me ? ', me known' : ''}`if (said !== s.last && s.logged < LOGGED_CHANGES) { s.logged++; log(`call names: ${kind} talking ${said}`) }@@ -156,6 +181,8 @@ export function hookCallNames(p: {s.watch?.stop(); s.watch = undefinedconst ids = watchIds(m.app)s.ids = ids; s.heardAt = now()+ // a window read before may have been another app's+ s.windowSeen = undefined; s.goneSince = undefined; s.goneAt = undefinedlog(`call names: the call is in ${m.app}, reading only it`)if (!ids.length) returns.pictured = false@@ -205,6 +232,7 @@ export function hookCallNames(p: {log(`call names: ${s.app} is on the mic now, reading only its process`)s.watch.stop(); s.watch = undefineds.samples = []; s.heardAt = now(); s.pictured = false+ s.windowSeen = undefined; s.goneSince = undefined; s.goneAt = undefinedbegin(id, s)continue}@@ -226,6 +254,16 @@ export function hookCallNames(p: {const s = sessions.get(meetingId)return s?.samples.length ? nameFor({ startMs, endMs }, timeline(s), { myNames: p.myNames() }) : null},+ /**+ * The meeting's call window (watch.ts ends the call when it has been gone a while): null until one with people was+ * read; goneMs 0 while it is there, hidden, or the reader has said nothing lately (no evidence is not gone).+ */+ callWindow(meetingId: string): { goneMs: number } | null {+ const s = sessions.get(meetingId)+ if (!s?.windowSeen) return null+ const fresh = s.goneSince !== undefined && s.goneAt !== undefined && now() - s.goneAt <= s.quietMs+ return { goneMs: fresh ? now() - s.goneSince! : 0 }+ },/** resolves when the names after the meeting are in */finished: (id: string): Promise<void> => finals.get(id) ?? Promise.resolve(),}diff --git a/app/src/main/detect.ts b/app/src/main/detect.tsindex 8e8ff9f7..4404cf21 100644--- a/app/src/main/detect.ts+++ b/app/src/main/detect.ts@@ -153,3 +153,13 @@ export const watchEveryMs = (recording: boolean): number => (recording ? 1_500 :export function callGone(o: { app: string | null; seen: boolean; micIdleMs: number; silentMs: number; graceMs?: number }): boolean {return !!o.app && o.seen && o.micIdleMs >= (o.graceMs ?? CALL_GONE_MS) && o.silentMs >= CALL_SILENCE_MS}++/**+ * The call app's meeting window (Zoom's meeting window, Teams' Leave button) gone this long ends the call, even while+ * the app keeps the mic: Zoom can hold it after a meeting. The call names reader says how long it has been gone, and+ * never counts a window that is only minimised or on another desktop.+ */+export const WINDOW_GONE_MS = 8_000+/** with the window gone, both tracks quiet this long: people still talking in the room are never cut off */+export const WINDOW_QUIET_MS = 15_000+export const windowGone = (o: { goneMs: number; silentMs: number }): boolean => o.goneMs >= WINDOW_GONE_MS && o.silentMs >= WINDOW_QUIET_MSdiff --git a/app/src/main/index.ts b/app/src/main/index.tsindex 929dcc1f..087d9740 100644--- a/app/src/main/index.ts+++ b/app/src/main/index.ts@@ -321,6 +321,10 @@ let recordingControls: { start(o: { eventId?: string; title?: string }): Promise/** the processes of a call app on the mic at the last reading (set once detection starts): names come only from them (#98) */let micPidsNow: (app: string) => number[] = () => []+/** the meeting's call window as the call names reader sees it (set once call names start). Mac only: its reader also+ * says when the call window is just on another desktop, so that is never taken for the call ending */+let callWindowOf: (meetingId: string) => { goneMs: number } | null = () => null+/** fake mode's hooks reach the store and the notes through these */let storeRef: Store | undefinedlet indexerRef: { schedule(): Promise<unknown> } | undefined@@ -351,6 +355,7 @@ function startDetection() {ready: () => !onboardingShowing(),// fake mode: tests can shorten the gracegraceMs: isFake() && process.env.YOGURT_FAKE_CALL_GONE_MS ? Number(process.env.YOGURT_FAKE_CALL_GONE_MS) : CALL_GONE_MS,+ callWindow: (id) => callWindowOf(id),})onMeetingStop(() => { watcher.cleared() })const prompts = createPrompts({@@ -624,6 +629,7 @@ app.whenReady().then(() => {changed: (id) => { win?.webContents.send('transcript:speakers', id); sendWidgetTranscript('transcript:speakers', id); win?.webContents.send('meetings:changed'); notes.applyPeople(id) },onStart: onMeetingStart, onStop: onMeetingStop, onCapture: onCaptureStart, onBind: onMeetingBound, micPids: (app) => micPidsNow(app),})+ if (process.platform === 'darwin') callWindowOf = (id) => callNames.callWindow(id)// Windows and Linux: whisper left the graphics card in a meeting, so the speed check (timed with it) runs again next startonWhisperGpuOff(() => speedStore(speedFile()).forget())hookTranscription({ store, modelPath: () => setup.installed()?.asr, send: (seg) => {diff --git a/app/src/main/watch.ts b/app/src/main/watch.tsindex 7ef9b2bc..c4e28aa5 100644--- a/app/src/main/watch.ts+++ b/app/src/main/watch.ts@@ -1,5 +1,5 @@import type { Meeting } from './store'-import { callAppName, callGone, decide, ended, type Prompt, type Signals } from './detect'+import { callAppName, callGone, decide, ended, windowGone, type Prompt, type Signals } from './detect'import type { Reading } from './detectSignals'/** Everything the watcher needs from outside, so tests and fake mode can stand in */@@ -24,6 +24,8 @@ export type WatchDeps = {autoStopOn?(): boolean/** how long the call must be gone (CALL_GONE_MS unless fake mode says) */graceMs?: number+ /** the call names reader's view of the meeting's call window: null before a call window with people was seen */+ callWindow?(meetingId: string): { goneMs: number } | null}const SNOOZE = 5 * 60_000@@ -36,7 +38,7 @@ export class Watcher {readonly dismissed = new Set<string>()private shown: string | null = null // key of the start card, or 'stop'private busy = false- private rec: { id: string; lastMic: number; snoozeUntil: number; /** the call app was on the mic during this recording */ seen: boolean; stopped: boolean; /** started without a call app (New note, the agenda): never stopped by itself */ byHand: boolean } | null = null+ private rec: { id: string; lastMic: number; snoozeUntil: number; /** the call app was on the mic during this recording */ seen: boolean; stopped: boolean; /** started without a call app (New note, the agenda): stopped by itself only once its call window is gone */ byHand: boolean; /** when the window-gone line last went to the log */ windowLogAt?: number } | null = null/** call apps on the mic at the last look before recording: a recording started from the card belongs to that call */private idleMic = new Set<string>()@@ -120,7 +122,8 @@ export class Watcher {private recording(m: Meeting, s: Signals, now: number) {const starting = this.rec?.id !== m.id- // started by hand (no call app yet: New note, the agenda): never stopped by itself, only asked about. Join and record+ // started by hand (no call app yet: New note, the agenda): the mic alone never stops it, only asks (a pre-join+ // screen lets go of the mic); its call window going away does. Join and record// starts with no app too, but it is a call: like a card start it stops once its call app was on the mic and has goneconst byHand = starting ? !m.app && !this.joins.has(m.id) : this.rec!.byHandconst recent = starting && this.idleCall && now - this.idleCall.at <= 6000 ? this.idleCall.app : null@@ -142,16 +145,28 @@ export class Watcher {const using = !m.app || onMicif (using) r.lastMic = nowconst silentMs = this.d.silentMs?.() ?? 0- if (!r.byHand && this.d.autoStop && this.d.autoStopOn?.() && callGone({ app: m.app, seen: r.seen, micIdleMs: now - r.lastMic, silentMs, graceMs: this.d.graceMs })) {- console.info(`CALL gone meeting=${m.id} app=${m.app} idle_ms=${now - r.lastMic} silent_ms=${silentMs}`)+ // A call window with people seen, then gone: the call ended, whatever the mic says (Zoom can keep it). That is no+ // pre-join screen letting go of the mic, so it ends a recording started by hand too.+ const win = m.app ? this.d.callWindow?.(m.id) ?? null : null+ const goneMs = win?.goneMs ?? 0+ const mic = s.micApps.filter((a) => callAppName(a.bundleId, s.runningApps) === m.app).map((a) => a.bundleId).join(',') || 'none'+ if (goneMs > 0 && (r.windowLogAt === undefined || now - r.windowLogAt >= 10_000)) {+ // what the mic did after the window went away, so the next call that does not end shows why+ r.windowLogAt = now+ console.info(`CALL window-gone meeting=${m.id} app=${m.app} window_ms=${goneMs} on_mic=${onMic} mic=${mic} silent_ms=${silentMs}`)+ } else if (goneMs === 0) r.windowLogAt = undefined+ const byWindow = windowGone({ goneMs, silentMs })+ const byMic = !r.byHand && callGone({ app: m.app, seen: r.seen, micIdleMs: now - r.lastMic, silentMs, graceMs: this.d.graceMs })+ if ((byWindow || byMic) && this.d.autoStop && this.d.autoStopOn?.()) {+ console.info(`CALL gone meeting=${m.id} app=${m.app} idle_ms=${now - r.lastMic} silent_ms=${silentMs} via=${byMic ? 'mic' : 'window'} window_ms=${goneMs} mic=${mic}`)r.stopped = trueif (this.shown === 'stop') { this.shown = null; this.d.hide() }this.d.autoStop(m)return}- const over = ended(now - r.lastMic, silentMs)+ const over = byWindow || ended(now - r.lastMic, silentMs)if (over && this.shown !== 'stop' && now >= r.snoozeUntil) {- console.info(`CALL stop-card meeting=${m.id} app=${m.app ?? 'none'} reason=mic-idle-and-silent idle_ms=${now - r.lastMic} silent_ms=${silentMs}`)+ console.info(`CALL stop-card meeting=${m.id} app=${m.app ?? 'none'} reason=${byWindow ? 'window-gone-and-silent' : 'mic-idle-and-silent'} window_ms=${goneMs} idle_ms=${now - r.lastMic} silent_ms=${silentMs}`)this.shown = 'stop'; this.d.askStop(m)}else if (!over && this.shown === 'stop') { this.shown = null; this.d.hide() }diff --git a/app/test/callNames.test.ts b/app/test/callNames.test.tsindex 7184c539..4e3370cc 100644--- a/app/test/callNames.test.ts+++ b/app/test/callNames.test.ts@@ -69,6 +69,8 @@ function setup(o: { app?: string | null; attendees?: Meeting['attendees']; micPi/** audio heard: meeting time `ms`, arriving at wall clock `at` */audio(ms: number, at: number) { clock = at; capture.emit('pcm', 'them', ms, new Float32Array(1600)) },emit: (l: WatchLine) => emit(l),+ /** the wall clock moves to `at` */+ at(t: number) { clock = t },/** the recording learned its call app (CALL bind) */bind(app: string) { binds.forEach((f) => f({ ...store.meeting(m.id)!, app })) },stop() { const s = { ...store.meeting(m.id)!, state: 'stopped' as const }; stops.forEach((f) => f(s)) },@@ -393,3 +395,80 @@ describe('hookCallNames', () => {await wait()})})++// #auto-end: Christian's Zoom call (Nov 23) never stopped by itself. A call window seen and then gone is a second sign the+// call ended, beside the mic, which Zoom can keep after a meeting.+describe('callWindow: the call window seen, then gone', () => {+ const gone = (t: number, extra: Partial<WatchLine> = {}): WatchLine => ({ t, app: 'us.zoom.xos', error: 'no-call-window', ...extra })+ it('a Zoom meeting window with people that goes away counts how long it has been gone, and says so in the log', () => {+ const s = setup({ app: null })+ s.start(); s.bind('Zoom')+ for (let t = 1_000_000; t <= 1_005_000; t += 500) { s.at(t); s.emit(zoomLine(t, ['Alex Morgan', 'Dana Smith'])) }+ expect(s.hook.callWindow(s.m.id)).toEqual({ goneMs: 0 })+ for (let t = 1_005_500; t <= 1_015_500; t += 500) { s.at(t); s.emit(gone(t)) }+ expect(s.hook.callWindow(s.m.id)).toEqual({ goneMs: 10_000 })+ expect(s.logs).toContain('call names: the zoom call window went away')+ // it comes back (a reading of the window again): not gone+ s.at(1_016_000); s.emit(zoomLine(1_016_000, ['Alex Morgan', 'Dana Smith']))+ expect(s.hook.callWindow(s.m.id)).toEqual({ goneMs: 0 })+ expect(s.logs).toContain('call names: the zoom call window is back after 11 s')+ })+ it('a Teams call whose window (its Leave button) goes away is gone the same way', () => {+ const s = setup({ app: 'Teams' })+ s.start()+ const tree: AxNode = { r: 'frame', k: [{ r: 'section', t: 'Dana Smith, speaking' }, { r: 'tree', t: 'Participants', k: [{ r: 'tree item', t: 'Dana Smith, unmuted' }, { r: 'tree item', t: 'Alex Morgan (You)' }] }] }+ s.at(1_000_000); s.emit({ t: 1_000_000, app: 'com.microsoft.teams2', windows: [{ title: 'Meeting | Microsoft Teams', tree }] })+ for (let t = 1_000_500; t <= 1_008_500; t += 500) { s.at(t); s.emit({ t, app: 'com.microsoft.teams2', error: 'no-call-window' }) }+ expect(s.hook.callWindow(s.m.id)?.goneMs).toBe(8_000)+ expect(s.logs).toContain('call names: the teams call window went away')+ })+ it('Zoom quitting is the window gone too', () => {+ const s = setup()+ s.start()+ s.at(1_000_000); s.emit(zoomLine(1_000_000, ['Alex Morgan', 'Dana Smith']))+ for (let t = 1_000_500; t <= 1_010_500; t += 500) { s.at(t); s.emit({ t, error: 'not-running' }) }+ expect(s.hook.callWindow(s.m.id)?.goneMs).toBe(10_000)+ })+ it('a window the Mac still has but accessibility cannot see (another desktop, full screen) is not gone', () => {+ const s = setup()+ s.start()+ s.at(1_000_000); s.emit(zoomLine(1_000_000, ['Alex Morgan', 'Dana Smith']))+ for (let t = 1_000_500; t <= 1_060_000; t += 500) { s.at(t); s.emit(gone(t, { hidden: true })) }+ expect(s.hook.callWindow(s.m.id)).toEqual({ goneMs: 0 })+ expect(s.logs.filter((l) => l.includes('out of sight'))).toHaveLength(1)+ })+ it('a minimised meeting window is still read, so it is not gone', () => {+ const s = setup()+ s.start()+ for (let t = 1_000_000; t <= 1_060_000; t += 500) {+ const l = zoomLine(t, ['Alex Morgan', 'Dana Smith']); l.windows![0].minimized = t > 1_001_000+ s.at(t); s.emit(l)+ }+ expect(s.hook.callWindow(s.m.id)).toEqual({ goneMs: 0 })+ })+ it('no call window ever seen with people (a pre-join screen, a call not joined yet): no evidence either way', () => {+ const s = setup()+ s.start()+ s.at(1_000_000); s.emit(zoomLine(1_000_000, []))+ for (let t = 1_000_500; t <= 1_060_000; t += 500) { s.at(t); s.emit(gone(t)) }+ expect(s.hook.callWindow(s.m.id)).toBeNull()+ })+ it('a reader that went quiet or lost its permission is no evidence the window went away', () => {+ const s = setup()+ s.start()+ s.at(1_000_000); s.emit(zoomLine(1_000_000, ['Alex Morgan', 'Dana Smith']))+ s.at(1_000_500); s.emit(gone(1_000_500))+ s.at(1_030_000)+ expect(s.hook.callWindow(s.m.id)).toEqual({ goneMs: 0 })+ s.emit({ t: 1_030_000, error: 'not-trusted' })+ s.at(1_040_000); s.emit({ t: 1_040_000, error: 'not-trusted' })+ expect(s.hook.callWindow(s.m.id)).toEqual({ goneMs: 0 })+ })+ it('a Meet tab is not followed: switching tabs hides the call from the reader, and the browser lets go of the mic as soon as the call ends', () => {+ const s = setup({ app: 'Chrome' })+ s.start()+ s.at(1_000_000); s.emit({ t: 1_000_000, app: 'com.google.Chrome', windows: [{ title: 'Meet - abc-defg-hij', tree: { r: 'AXWindow', k: [] } }] })+ for (let t = 1_000_500; t <= 1_060_000; t += 500) { s.at(t); s.emit({ t, app: 'com.google.Chrome', error: 'no-call-window' }) }+ expect(s.hook.callWindow(s.m.id)).toBeNull()+ })+})diff --git a/app/test/watch.test.ts b/app/test/watch.test.tsindex ac95b196..917bbcc4 100644--- a/app/test/watch.test.ts+++ b/app/test/watch.test.ts@@ -490,3 +490,80 @@ it('Close does not change automatic-stop rules when the setting is enabled laterw.dismissStop(); auto = true; await w.tick()expect(log).toEqual(['stop', 'auto:m1'])})++// Nov 23: Christian started a note by hand (CALL watch app=none), Zoom came on the mic 5 s later (CALL bind via=mic), and+// when the call ended nothing stopped: a hand start never stopped by itself, and the stop card needs a quiet minute. The+// meeting window and its Leave button going away is a second sign the call ended, even while Zoom keeps the mic.+describe('the call window going away ends the call', () => {+ let win: { goneMs: number } | null+ const windowWatcher = () => new Watcher({+ read: async () => reading, now: () => clock, active: () => active,+ bindApp: (_id, app) => (active = { ...active!, app }),+ offer: (p) => log.push('offer:' + p.key), askStop: () => log.push('stop'), hide: () => log.push('hide'),+ silentMs: () => silent, callWindow: () => win,+ autoStop: (m) => log.push('auto:' + m.id), autoStopOn: () => auto,+ })+ beforeEach(() => { win = null; auto = true; silent = 0; w = windowWatcher() })+ /** the log's sequence up to the end of the call: watch with no app, bind via mic, a call window with people */+ const callStartedByHand = async () => {+ active = meeting({ app: null })+ reading = { micApps: [], events: [] }; await w.tick()+ clock += 5_000; reading = { micApps: [zoom], events: [] }; await w.tick()+ expect(active!.app).toBe('Zoom')+ win = { goneMs: 0 }+ for (let i = 0; i < 10; i++) { clock += MIN; await w.tick() }+ expect(log).toEqual([])+ }+ it('a note started by hand stops by itself once Zoom\'s meeting window is gone, though Zoom keeps the mic', async () => {+ const info = vi.spyOn(console, 'info')+ await callStartedByHand()+ // people leave, the meeting window closes; Zoom still holds the mic+ for (let ms = 1_500; ms <= 30_000 && !log.length; ms += 1_500) { clock += 1_500; win = { goneMs: ms }; silent = ms; await w.tick() }+ expect(log).toEqual(['auto:m1'])+ const lines = info.mock.calls.map(([l]) => String(l))+ expect(lines.find((l) => l.startsWith('CALL gone'))).toMatch(/^CALL gone meeting=m1 app=Zoom idle_ms=0 silent_ms=15000 via=window window_ms=15000 mic=us\.zoom\.xos$/)+ info.mockRestore()+ })+ it('logs what the mic said for the call app every 10 s after its window went away', async () => {+ const info = vi.spyOn(console, 'info')+ await callStartedByHand()+ // someone is still talking in the room: no end, but the log says what the mic did+ for (let ms = 1_500; ms <= 30_000; ms += 1_500) { clock += 1_500; win = { goneMs: ms }; await w.tick() }+ expect(log).toEqual([])+ const lines = info.mock.calls.map(([l]) => String(l)).filter((l) => l.startsWith('CALL window-gone'))+ expect(lines).toEqual([+ 'CALL window-gone meeting=m1 app=Zoom window_ms=1500 on_mic=true mic=us.zoom.xos silent_ms=0',+ 'CALL window-gone meeting=m1 app=Zoom window_ms=12000 on_mic=true mic=us.zoom.xos silent_ms=0',+ 'CALL window-gone meeting=m1 app=Zoom window_ms=22500 on_mic=true mic=us.zoom.xos silent_ms=0',+ ])+ info.mockRestore()+ })+ it('with "Stop recording when the call ends" off, it asks instead', async () => {+ auto = false+ await callStartedByHand()+ for (let ms = 1_500; ms <= 30_000; ms += 1_500) { clock += 1_500; win = { goneMs: ms }; silent = ms; await w.tick() }+ expect(log).toEqual(['stop'])+ })+ it('never while people are still heard', async () => {+ await callStartedByHand()+ for (let ms = 1_500; ms <= 5 * MIN; ms += 1_500) { clock += 1_500; win = { goneMs: ms }; silent = 0; await w.tick() }+ expect(log).toEqual([])+ })+ it('never while the window is only hidden, minimised or on another desktop (the reader says it is not gone)', async () => {+ await callStartedByHand()+ for (let i = 0; i < 200; i++) { clock += 1_500; win = { goneMs: 0 }; silent = 60_000; await w.tick() }+ expect(log).toEqual([])+ })+ it('a window gone for less than the wait is a blip: no end', async () => {+ await callStartedByHand()+ for (let ms = 1_500; ms <= 6_000; ms += 1_500) { clock += 1_500; win = { goneMs: ms }; silent = 60_000; await w.tick() }+ win = { goneMs: 0 }; clock += 1_500; await w.tick()+ expect(log).toEqual([])+ })+ it('a card start still ends by the mic as before', async () => {+ active = meeting()+ reading = { micApps: [zoom], events: [] }; await w.tick()+ reading = { micApps: [], events: [] }; silent = 60_000; clock += 5_000; await w.tick()+ expect(log).toEqual(['auto:m1'])+ })+})