Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more
Ask when a meeting ends, detect browser meetings (#1130)
ALTIC5ffc4bebad44
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swiftindex 00503823..bd7d5c89 100644--- a/Sources/Fluid/Persistence/SettingsStore.swift+++ b/Sources/Fluid/Persistence/SettingsStore.swift@@ -2126,9 +2126,14 @@ final class SettingsStore: ObservableObject {}}- /// Tier 2 browser-tab meeting auto-detection (default: OFF — reads the frontmost tab's URL).+ /// Tier 2 browser-tab meeting auto-detection. On unless the user turned it off: Google Meet+ /// only exists in a browser. It reads the frontmost tab's URL, which is never stored or sent.var meetingAutoDetectBrowserEnabled: Bool {- get { self.defaults.bool(forKey: Keys.meetingAutoDetectBrowserEnabled) }+ get {+ let value = self.defaults.object(forKey: Keys.meetingAutoDetectBrowserEnabled)+ if value == nil { return true }+ return self.defaults.bool(forKey: Keys.meetingAutoDetectBrowserEnabled)+ }set {objectWillChange.send()self.defaults.set(newValue, forKey: Keys.meetingAutoDetectBrowserEnabled)diff --git a/Sources/Fluid/Services/AppServices.swift b/Sources/Fluid/Services/AppServices.swiftindex 34102865..2018c4a9 100644--- a/Sources/Fluid/Services/AppServices.swift+++ b/Sources/Fluid/Services/AppServices.swift@@ -134,10 +134,15 @@ final class AppServices: ObservableObject {self.setupMeetingCoordinatorForwarding()// The auto-detected episode itself stays consumed until the meeting's own evidence ends// (window/URL gone ≥60s) — not merely because our recording stopped — so only the nudge- // needs to be dismissed here.+ // and the end-of-meeting watch are dropped here.coordinator.$state.receive(on: DispatchQueue.main)- .sink { state in+ .sink { [weak self, weak coordinator] state in+ // Deliveries are queued, so read the state as it is now before calling a recording over.+ switch coordinator?.state {+ case .preparing, .recording, .recordingDegraded: break+ default: self?._meetingAutoDetector?.recordingStopped()+ }guard !MeetingOverlayVisibility.isVisible(for: state) else { return }MeetingStillRecordingNudgeController.shared.hide()}@@ -167,7 +172,8 @@ final class AppServices: ObservableObject {isNativeDetectionEnabled: { SettingsStore.shared.meetingAutoDetectEnabled },isBrowserDetectionEnabled: {SettingsStore.shared.meetingAutoDetectEnabled && SettingsStore.shared.meetingAutoDetectBrowserEnabled- }+ },+ lastSpeechAt: { [weak self] in self?._meetingSessionCoordinator?.lastLiveSpeechAt })self._meetingAutoDetector = detectorself.wireMeetingAutoDetector(detector)@@ -189,6 +195,9 @@ final class AppServices: ObservableObject {detector.onStillRecordingNudge = {MeetingStillRecordingNudgeController.shared.present()}+ detector.onStillRecordingNudgeWithdrawn = {+ MeetingStillRecordingNudgeController.shared.hide()+ }detector.onSuggestDisablingAutoDetect = {MeetingAutoDetectDismissalAdvisor.shared.shouldSuggest = true}@@ -210,6 +219,9 @@ final class AppServices: ObservableObject {MeetingDetectionPromptController.shared.onTimeout = { [weak self] episodeID inself?._meetingAutoDetector?.timeoutDismissed(episodeID: episodeID)}+ MeetingStillRecordingNudgeController.shared.onDismiss = { [weak self] in+ self?._meetingAutoDetector?.stillRecordingNudgeDismissed()+ }MeetingStillRecordingNudgeController.shared.onStop = { [weak self] inguard let self else { return }Task { @MainActor in _ = try? await self.meetingSessionCoordinator.stopAndTranscribe() }diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swiftindex 4fc59db5..5992fab4 100644--- a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift@@ -93,6 +93,13 @@ nonisolated struct MeetingLiveTranscriptSnapshot: Sendable, Equatable {}}+ /// True when this snapshot holds words the earlier one did not: somebody is talking. A caption+ /// that only went away, or captions becoming available, is not speech.+ func hasNewWords(since earlier: MeetingLiveTranscriptSnapshot) -> Bool {+ if self.utterances != earlier.utterances, !self.utterances.isEmpty { return true }+ return self.partials.contains { speaker, partial in earlier.partials[speaker]?.text != partial.text }+ }+func settingAvailability(_ availability: MeetingLiveAvailability) -> MeetingLiveTranscriptSnapshot {var copy = selfcopy.availability = availabilitydiff --git a/Sources/Fluid/Services/Meeting/MeetingAppRegistry.swift b/Sources/Fluid/Services/Meeting/MeetingAppRegistry.swiftindex 64cc1549..7e84255d 100644--- a/Sources/Fluid/Services/Meeting/MeetingAppRegistry.swift+++ b/Sources/Fluid/Services/Meeting/MeetingAppRegistry.swift@@ -39,6 +39,13 @@ nonisolated enum MeetingAppRegistry {"com.microsoft.edgemac.app.",]+ /// A browser web app such as Google Meet's runs inside its browser, which is the process that+ /// actually holds the microphone. Nil for anything that is not such a web app.+ static func parentBrowser(ofWebApp bundleIdentifier: String) -> String? {+ guard let prefix = self.pwaBundlePrefixes.first(where: { bundleIdentifier.hasPrefix($0) }) else { return nil }+ return String(prefix.dropLast(".app.".count))+ }+static func tier(forBundleIdentifier bundleIdentifier: String) -> MeetingDetectionTier? {if self.nativeBundleIdentifiers.contains(bundleIdentifier) {return .nativeTier1@@ -60,6 +67,63 @@ nonisolated enum MeetingAppRegistry {self.tier(forBundleIdentifier: bundleIdentifier) == .browserTier2}+ // MARK: - Source picker order++ /// Call apps people record by hand that detection does not cover. They only shape the order+ /// of the source pickers; nothing here is detected or prompted for.+ static let otherCallAppBundleIdentifiers: [String] = [+ "com.apple.FaceTime",+ "com.tinyspeck.slackmacgap",+ "com.hnc.Discord",+ "net.whatsapp.WhatsApp",+ "ru.keepcoder.Telegram",+ "org.whispersystems.signal-desktop",+ "com.skype.skype",+ ]++ private static let pickerCallAppOrder: [String] = [+ "us.zoom.xos",+ "com.microsoft.teams2",+ "com.microsoft.teams",+ "com.cisco.webexmeetingsapp",+ "Cisco-Systems.Spark",+ ] + otherCallAppBundleIdentifiers++ private static let pickerBrowserOrder: [String] = [+ "com.google.Chrome",+ "com.apple.Safari",+ "company.thebrowser.Browser",+ "com.microsoft.edgemac",+ "com.brave.Browser",+ ]++ /// Where an app belongs among the usual meeting sources, lower first: call apps, then browser+ /// web apps such as Google Meet's, then browsers. Nil for anything that is not a usual source.+ static func pickerRank(forBundleIdentifier bundleIdentifier: String) -> Int? {+ if let index = self.pickerCallAppOrder.firstIndex(of: bundleIdentifier) { return index }+ if self.pwaBundlePrefixes.contains(where: { bundleIdentifier.hasPrefix($0) }) { return self.pickerCallAppOrder.count }+ if let index = self.pickerBrowserOrder.firstIndex(of: bundleIdentifier) { return self.pickerCallAppOrder.count + 1 + index }+ return nil+ }++ /// Splits a source list for a picker: the usual meeting sources first in a fixed order, then+ /// everything else by name with background items (menu bar helpers, agents) at the very end.+ static func pickerSections<Item>(+ _ items: [Item],+ bundleIdentifier: (Item) -> String,+ name: (Item) -> String,+ isBackgroundItem: (Item) -> Bool+ ) -> (usual: [Item], others: [Item]) {+ func byName(_ lhs: Item, _ rhs: Item) -> Bool {+ name(lhs).localizedCaseInsensitiveCompare(name(rhs)) == .orderedAscending+ }+ let ranked = items.compactMap { item in self.pickerRank(forBundleIdentifier: bundleIdentifier(item)).map { (item, $0) } }+ let usual = ranked.sorted { $0.1 != $1.1 ? $0.1 < $1.1 : byName($0.0, $1.0) }.map(\.0)+ let rest = items.filter { self.pickerRank(forBundleIdentifier: bundleIdentifier($0)) == nil }+ let others = rest.filter { !isBackgroundItem($0) }.sorted(by: byName) + rest.filter(isBackgroundItem).sorted(by: byName)+ return (usual, others)+ }+private static let zoomMeetingTitles: Set<String> = [// en"Zoom", "Zoom Meeting", "Zoom Webinar",diff --git a/Sources/Fluid/Services/Meeting/MeetingAutoDetectSignals.swift b/Sources/Fluid/Services/Meeting/MeetingAutoDetectSignals.swiftindex f0e90151..292bd42b 100644--- a/Sources/Fluid/Services/Meeting/MeetingAutoDetectSignals.swift+++ b/Sources/Fluid/Services/Meeting/MeetingAutoDetectSignals.swift@@ -82,20 +82,25 @@ nonisolated struct AudioProcessActivitySnapshot: Sendable, Equatable {var queryState: QueryState}-/// Maps HAL process objects to the registered native application that owns them. Bundle IDs from+/// Maps HAL process objects to the registered application that owns them. Native meeting apps by+/// default; browsers only when asked, to read whether a browser still holds the microphone. Bundle IDs from/// HAL are advisory: helpers frequently report their own (or stale) IDs. Ownership is accepted/// only when the live executable is contained in the owning app bundle after symlink resolution./// Ambiguous, missing, or malformed data is deliberately rejected.nonisolated enum MeetingAudioProcessResolver {// nil means unavailable; an empty result means available with no values.- // swiftlint:disable:next discouraged_optional_collection- static func activeOwnerInputByPID(snapshot: AudioProcessActivitySnapshot) -> [Int32: Bool]? {+ // swiftlint:disable discouraged_optional_collection+ static func activeOwnerInputByPID(+ snapshot: AudioProcessActivitySnapshot,+ owning isOwner: (String) -> Bool = MeetingAppRegistry.isNativeMeetingApp(bundleIdentifier:)+ ) -> [Int32: Bool]? {+ // swiftlint:enable discouraged_optional_collectionguard snapshot.queryState == .valid else { return nil }var matches: [Int32: Bool] = [:]for process in snapshot.processes where process.isInputRunning || process.isOutputRunning {guard let path = canonicalPath(process.executablePath), process.processID > 0 else { return nil }let candidates = snapshot.owners.filter { owner in- guard MeetingAppRegistry.isNativeMeetingApp(bundleIdentifier: owner.bundleIdentifier),+ guard isOwner(owner.bundleIdentifier),let ownerPath = canonicalPath(owner.bundlePath), ownerPath.hasSuffix(".app")else { return false }guard path.hasPrefix(ownerPath + "/Contents/") else { return false }@@ -647,8 +652,9 @@ final class CoreAudioMicActivitySignal: MicActivitySignalProviding {final class CoreAudioProcessActivityProvider: AudioProcessActivityProviding {func snapshot() async -> AudioProcessActivitySnapshot {let owners = NSWorkspace.shared.runningApplications.compactMap { app -> MeetingProcessOwner? in+ // Browsers are listed too: their microphone tells when a web meeting is over.guard let bundle = app.bundleIdentifier,- MeetingAppRegistry.isNativeMeetingApp(bundleIdentifier: bundle),+ MeetingAppRegistry.tier(forBundleIdentifier: bundle) != nil,!app.isTerminated, app.processIdentifier > 0,let path = app.bundleURL?.path else { return nil }return MeetingProcessOwner(processID: app.processIdentifier, bundleIdentifier: bundle, bundlePath: path)diff --git a/Sources/Fluid/Services/Meeting/MeetingAutoDetector.swift b/Sources/Fluid/Services/Meeting/MeetingAutoDetector.swiftindex b76cb091..e5db4312 100644--- a/Sources/Fluid/Services/Meeting/MeetingAutoDetector.swift+++ b/Sources/Fluid/Services/Meeting/MeetingAutoDetector.swift@@ -15,6 +15,12 @@ final class MeetingAutoDetector {static let frontmostLeadSeconds: TimeInterval = 15static let windowLossGraceSeconds: TimeInterval = 5static let micReleaseEpisodeEndSeconds: TimeInterval = 60+ /// How long the meeting app must have let go of its audio, or been gone, before we ask whether+ /// the meeting ended. Short blips (a device switch, a crash and relaunch) stay under it.+ static let endSignalGraceSeconds: TimeInterval = 20+ /// People still talking means the meeting is not over for them, whatever the app did. The+ /// question waits until nobody has said anything for this long.+ static let speechQuietSeconds: TimeInterval = 45static let dismissalSuppressionSeconds: TimeInterval = 30 * 60static let rollingDismissalWindowSeconds: TimeInterval = 14 * 24 * 3600static let dismissalCountThreshold = 3@@ -56,6 +62,8 @@ final class MeetingAutoDetector {var onPromptRequested: ((PromptRequest) -> Void)?var onStillRecordingNudge: (() -> Void)?+ /// The call came back after we asked whether it ended. Take the question down.+ var onStillRecordingNudgeWithdrawn: (() -> Void)?var onSuggestDisablingAutoDetect: (() -> Void)?var onEpisodeInvalidated: ((UUID) -> Void)?var onHealthChanged: ((Health) -> Void)?@@ -95,10 +103,27 @@ final class MeetingAutoDetector {var windowID: UInt32?var confirmedAt: Datevar consumed = false- var stillRecordingNudgeShown = falsevar duplicateEpisodeRejectionLogged = false}+ /// The meeting app behind our own live recording. Kept apart from the episode, which is+ /// retired by rules written for the next start prompt and can go while we still record.+ private struct WatchedRecording {+ var pid: Int32+ var bundleIdentifier: String+ var tier: MeetingDetectionTier+ var incarnation: UInt64?+ /// The app's own audio was seen running during this recording, so seeing it stop means something.+ var sawProcessAudio = false+ var appGoneAt: Date?+ /// Browser meetings only: when the browser was first seen without the microphone.+ var browserMicReleasedAt: Date?+ var browserMicUnknown = false+ var asked = false+ /// The user waved the question away. It stays away for the rest of this recording.+ var silenced = false+ }+private let workspaceEvents: any WorkspaceEventsProvidingprivate let micActivity: any MicActivitySignalProvidingprivate let audioProcessActivity: any AudioProcessActivityProviding@@ -108,6 +133,7 @@ final class MeetingAutoDetector {private let clock: any MeetingClockProvidingprivate let isNativeDetectionEnabled: () -> Boolprivate let isBrowserDetectionEnabled: () -> Bool+ private let lastSpeechAt: () -> Date?private let rejectionLogger: (String) -> Voidprivate var lastLoggedRejectionByPID: [Int32: String] = [:]@@ -121,6 +147,7 @@ final class MeetingAutoDetector {}private var activeConsumedEpisodeKey: String?+ private var watchedRecording: WatchedRecording?private var dismissedBundleUntil: [String: Date] = [:]private var dismissalTimestamps: [Date] = []private var pollTask: Task<Void, Never>?@@ -142,6 +169,7 @@ final class MeetingAutoDetector {clock: any MeetingClockProviding,isNativeDetectionEnabled: @escaping () -> Bool,isBrowserDetectionEnabled: @escaping () -> Bool,+ lastSpeechAt: @escaping () -> Date? = { nil },rejectionLogger: @escaping (String) -> Void = { DebugLogger.shared.log($0, source: "MeetingAutoDetector") }) {self.workspaceEvents = workspaceEvents@@ -153,6 +181,7 @@ final class MeetingAutoDetector {self.clock = clockself.isNativeDetectionEnabled = isNativeDetectionEnabledself.isBrowserDetectionEnabled = isBrowserDetectionEnabled+ self.lastSpeechAt = lastSpeechAtself.rejectionLogger = rejectionLogger}@@ -222,6 +251,9 @@ final class MeetingAutoDetector {private func shouldCollectEvidence(at now: Date) -> Bool {if !self.episodesByKey.isEmpty { return true }+ // A browser we were recording is gone. Keep reading tabs so a relaunched one that is back+ // on the meeting can be recognised.+ if let watched = self.watchedRecording, watched.tier == .browserTier2, !self.isStillRunning(watched) { return true }return self.records.values.contains { record inrecord.hasLiveWindow || record.windowLostAt != nil|| record.audioEvidenceAt.map { now.timeIntervalSince($0) <= Self.confirmDeadlineSeconds } == true@@ -332,6 +364,7 @@ final class MeetingAutoDetector {guard !Task.isCancelled,expectedRunGeneration.map({ self.runGeneration == $0 && self.pollTask != nil && self.isNativeDetectionEnabled() }) ?? trueelse { return }+ self.noteWatchedBrowserMicrophone(snapshot, at: now)guard let activeInputByPID = MeetingAudioProcessResolver.activeOwnerInputByPID(snapshot: snapshot) else {if !self.audioQueryUnknown {DebugLogger.shared.warning("audio-query-unavailable native confirmation paused", source: "MeetingAutoDetector")@@ -359,7 +392,12 @@ final class MeetingAutoDetector {// to make output-only activity meaningful. Zoom's muted output-only path remains// supported because Zoom also requires an explicit meeting-window title.let hasEstablishedEpisode = self.episodesByKey.values.contains { $0.pid == pid }- if isActive, !hasInput, record.bundleIdentifier != "us.zoom.xos", !hasEstablishedEpisode {+ // The process behind our own recording stays established after its episode retires, so+ // a muted call that resumes still reads as audio. Only that process: a relaunched copy+ // playing a notification sound is not a call. We are busy recording, so this cannot+ // raise a start prompt.+ let isBehindOurRecording = self.watchedRecording.map { $0.pid == pid && $0.incarnation == record.incarnation } == true+ if isActive, !hasInput, record.bundleIdentifier != "us.zoom.xos", !hasEstablishedEpisode, !isBehindOurRecording {self.handleAudioProcessActivity(false, pid: pid, at: now)continue}@@ -367,9 +405,82 @@ final class MeetingAutoDetector {}}+ /// A web meeting is over when the browser lets go of the microphone, whichever tab is in front.+ /// Only a browser we saw holding the microphone during this recording can be read this way.+ private func noteWatchedBrowserMicrophone(_ snapshot: AudioProcessActivitySnapshot, at now: Date) {+ guard var watched = self.watchedRecording, watched.tier == .browserTier2 else { return }+ let inputByPID = MeetingAudioProcessResolver.activeOwnerInputByPID(+ snapshot: snapshot,+ owning: MeetingAppRegistry.isBrowserApp(bundleIdentifier:)+ )+ var inUse: Bool?+ if let inputByPID {+ func holdsMicrophone(_ bundleIdentifier: String, _ pid: Int32) -> Bool? {+ Self.browserHoldsMicrophone(bundleIdentifier: bundleIdentifier, pid: pid, owners: snapshot.owners, inputByPID: inputByPID)+ }+ if !self.isStillRunning(watched) {+ // The microphone alone could be a voice recorder page. It has to be on a meeting tab.+ self.follow(&watched, to: self.records.values.filter {+ $0.bundleIdentifier == watched.bundleIdentifier && $0.tier == .browserTier2+ && $0.hasLiveWindow && holdsMicrophone($0.bundleIdentifier, $0.pid) == true+ })+ }+ inUse = holdsMicrophone(watched.bundleIdentifier, watched.pid)+ }+ switch inUse {+ case true?:+ watched.browserMicUnknown = false+ watched.sawProcessAudio = true+ watched.browserMicReleasedAt = nil+ case false?:+ watched.browserMicUnknown = false+ if watched.sawProcessAudio, watched.browserMicReleasedAt == nil { watched.browserMicReleasedAt = now }+ case nil:+ // Not readable is not a release. The quiet has to be seen again from the start.+ watched.browserMicUnknown = true+ watched.browserMicReleasedAt = nil+ }+ self.watchedRecording = watched+ }++ /// Whether a browser holds the microphone, or nil when that cannot be told. A web app records+ /// through the browser it runs in, and with two copies of that browser open there is no+ /// telling which one it is.+ private static func browserHoldsMicrophone(+ bundleIdentifier: String,+ pid: Int32,+ owners: [MeetingProcessOwner],+ inputByPID: [Int32: Bool]+ ) -> Bool? {+ guard let browser = MeetingAppRegistry.parentBrowser(ofWebApp: bundleIdentifier) else { return inputByPID[pid] == true }+ let browsers = owners.filter { $0.bundleIdentifier == browser }+ guard browsers.count == 1, let owner = browsers.first else { return nil }+ return inputByPID[owner.processID] == true+ }++ private func isStillRunning(_ watched: WatchedRecording) -> Bool {+ guard let record = self.records[watched.pid] else { return false }+ return watched.incarnation == nil || record.incarnation == watched.incarnation+ }++ /// The app behind the recording crashed or was restarted and is in a call again under a new+ /// process. Follow it, so the question can be taken back. Only one clear match of the same+ /// app is ever adopted.+ private func follow(_ watched: inout WatchedRecording, to relaunched: [CandidateRecord]) {+ guard relaunched.count == 1, let record = relaunched.first else { return }+ watched.pid = record.pid+ watched.incarnation = record.incarnation+ watched.sawProcessAudio = true+ watched.appGoneAt = nil+ DebugLogger.shared.log("end-of-meeting-watch-followed bundle=\(record.bundleIdentifier)", source: "MeetingAutoDetector")+ }+func handleAudioProcessActivity(_ isActive: Bool, pid: Int32, at now: Date) {guard var record = self.records[pid], record.tier == .nativeTier1 else { return }record.processAudioObserved = true+ if isActive, self.watchedRecording?.pid == pid, self.watchedRecording?.incarnation == record.incarnation {+ self.watchedRecording?.sawProcessAudio = true+ }if isActive, record.processAudioWasActive {// A continuous stream is still fresh evidence. Refreshing here allows a late window// snapshot/activation to confirm without synthesizing duplicate episodes.@@ -638,6 +749,24 @@ final class MeetingAutoDetector {self.episodesByKey[key] = episodeself.activeConsumedEpisodeKey = keyself.dismissalTimestamps.removeAll()+ let record = self.records[episode.pid]+ self.watchedRecording = WatchedRecording(+ pid: episode.pid,+ bundleIdentifier: episode.bundleIdentifier,+ tier: episode.tier,+ incarnation: record?.incarnation,+ sawProcessAudio: record?.processAudioWasActive == true+ )+ }++ /// Our recording is over, however it ended. Nothing is left to ask about.+ func recordingStopped() {+ self.watchedRecording = nil+ }++ /// The user closed the "Meeting ended?" question without stopping.+ func stillRecordingNudgeDismissed() {+ self.watchedRecording?.silenced = true}/// Atomic gate re-check + single-shot consume. Returns false if the episode is unknown,@@ -716,11 +845,7 @@ final class MeetingAutoDetector {self.records[pid] = record}- // Evaluated before eviction below: the active episode must still be present to nudge on- // the same tick its window-gone-60s threshold is crossed.- if let activeKey = self.activeConsumedEpisodeKey, let activeEpisode = self.episodesByKey[activeKey] {- self.evaluateStillRecordingNudge(key: activeKey, episode: activeEpisode, at: now)- }+ self.evaluateEndOfMeeting(at: now)// Uniform episode-end eviction (window/URL evidence gone ≥60s, or the app quit) applies// even to a consumed episode still backing our own live recording — that IS episode end,@@ -752,15 +877,61 @@ final class MeetingAutoDetector {}}- private func evaluateStillRecordingNudge(key: String, episode: Episode, at now: Date) {- guard !episode.stillRecordingNudgeShown else { return }- guard let record = self.records[episode.pid] else { return }- guard record.windowEvidenceAt == nil, let windowLostAt = record.windowLostAt else { return }- guard now.timeIntervalSince(windowLostAt) >= Self.micReleaseEpisodeEndSeconds else { return }- var updated = episode- updated.stillRecordingNudgeShown = true- self.episodesByKey[key] = updated- self.onStillRecordingNudge?()+ /// Asks "Meeting ended?" once the app behind our recording looks done: it quit, it let go of+ /// its audio, or its meeting window has been gone for a while. It only ever asks.+ private func evaluateEndOfMeeting(at now: Date) {+ guard var watched = self.watchedRecording, !watched.silenced else { return }+ if watched.tier == .nativeTier1, !self.isStillRunning(watched) {+ self.follow(&watched, to: self.records.values.filter {+ $0.bundleIdentifier == watched.bundleIdentifier && $0.tier == .nativeTier1 && $0.processAudioWasActive && $0.hasLiveWindow+ })+ }+ let askAt: Date?+ var audioUnknown = false+ if let record = self.records[watched.pid], self.isStillRunning(watched) {+ watched.appGoneAt = nil+ var moments: [Date] = []+ if record.tier == .browserTier2 {+ // We only ever read the front tab, so a meeting tab that is no longer in front says+ // nothing: the call may be running behind another tab. The microphone decides.+ audioUnknown = watched.browserMicUnknown+ if let releasedAt = watched.browserMicReleasedAt {+ moments.append(releasedAt.addingTimeInterval(Self.endSignalGraceSeconds))+ }+ } else {+ audioUnknown = self.audioQueryUnknown+ if record.windowEvidenceAt == nil, let windowLostAt = record.windowLostAt {+ moments.append(windowLostAt.addingTimeInterval(Self.micReleaseEpisodeEndSeconds))+ }+ // An unknown audio query is not a release, and an app whose audio we never saw running+ // gives no release to read. Teams and Webex keep a window open all day, so for them+ // this is the only sign the call is over.+ if watched.sawProcessAudio, !self.audioQueryUnknown, let inactiveAt = record.processAudioInactiveAt {+ moments.append(inactiveAt.addingTimeInterval(Self.endSignalGraceSeconds))+ }+ }+ askAt = moments.min()+ } else {+ let goneAt = watched.appGoneAt ?? now+ watched.appGoneAt = goneAt+ askAt = goneAt.addingTimeInterval(Self.endSignalGraceSeconds)+ }+ // Without live captions there is no speech to wait for, and the app's own signal decides.+ let stillTalking = self.lastSpeechAt().map { now.timeIntervalSince($0) < Self.speechQuietSeconds } == true+ let shouldAsk = askAt.map { now >= $0 } == true && !stillTalking && !watched.asked+ // Every sign of the end is gone again: the call resumed. An audio query we cannot read is+ // not that, so it changes nothing. The question can then come back at the next real end.+ let shouldWithdraw = askAt == nil && watched.asked && !(audioUnknown && watched.sawProcessAudio)+ if shouldAsk { watched.asked = true }+ if shouldWithdraw { watched.asked = false }+ self.watchedRecording = watched+ if shouldAsk {+ DebugLogger.shared.log("end-of-meeting-asked", source: "MeetingAutoDetector")+ self.onStillRecordingNudge?()+ } else if shouldWithdraw {+ DebugLogger.shared.log("end-of-meeting-withdrawn", source: "MeetingAutoDetector")+ self.onStillRecordingNudgeWithdrawn?()+ }}// MARK: - Disarm on lock / sleep / fast-user-switch — mic bits are unreliable across these.@@ -777,6 +948,9 @@ final class MeetingAutoDetector {self.lastMicReleaseAt = nilself.episodesByKey = [:]self.activeConsumedEpisodeKey = nil+ // With the records gone the app would look like it quit. Stop watching instead of guessing.+ // A question already on screen stays there for the user to answer.+ self.watchedRecording = nilself.lastBrowserPollAt = [:]for episodeID in unconsumedIDs {self.onEpisodeInvalidated?(episodeID)diff --git a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swiftindex 95c7243f..149e4ab4 100644--- a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift+++ b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift@@ -111,6 +111,8 @@ final class MeetingSessionCoordinator: ObservableObject {@Published private(set) var latestCompletedSession: MeetingSession?@Published private(set) var trackHealth: [MeetingAudioTrackKind: MeetingTrackHealth] = [:]@Published private(set) var liveTranscript: MeetingLiveTranscriptSnapshot = .empty+ /// When live captions last heard words in the current recording. Nil without live captions.+ private(set) var lastLiveSpeechAt: Date?/// Sustained application-audio silence, in seconds, before the silence watchdog degrades the session.private static let silenceWatchdogThresholdSeconds: TimeInterval = 90@@ -447,6 +449,7 @@ final class MeetingSessionCoordinator: ObservableObject {self.liveTranscriptionCoordinator != nil,self.liveTranscript.accepts(snapshot, generation: generation, activeGeneration: self.captureGeneration)else { return }+ if snapshot.hasNewWords(since: self.liveTranscript) { self.lastLiveSpeechAt = Date() }self.liveTranscript = snapshot}}@@ -454,6 +457,7 @@ final class MeetingSessionCoordinator: ObservableObject {}self.liveTranscriptionCoordinator = liveTranscriptionCoordinatorself.liveTranscript = .empty+ self.lastLiveSpeechAt = nilliveTranscriptionCoordinator.start(mode: configuration.mode, languageCode: configuration.languageCode)do {diff --git a/Sources/Fluid/Services/Meeting/MeetingSummaryProvider.swift b/Sources/Fluid/Services/Meeting/MeetingSummaryProvider.swiftindex 296d311e..e31696be 100644--- a/Sources/Fluid/Services/Meeting/MeetingSummaryProvider.swift+++ b/Sources/Fluid/Services/Meeting/MeetingSummaryProvider.swift@@ -19,6 +19,19 @@ nonisolated enum MeetingSummaryOnDevice {/// The on-device model reads the whole transcript in one request.static let maximumTranscriptBytes = 96_000++ /// A model that recommends more memory than this is a large one. The provider does not offer+ /// it on a Mac with less than this, and here it comes with a warning on a Mac with exactly this much.+ static let comfortableMemoryGB = 16++ static var thisMacMemoryGB: Int {+ Int((Double(ProcessInfo.processInfo.physicalMemory) / 1_073_741_824).rounded())+ }++ static func memoryWarning(recommendedMemoryGB: Int?, memoryGB: Int) -> String? {+ guard (recommendedMemoryGB ?? 0) > self.comfortableMemoryGB, memoryGB <= self.comfortableMemoryGB else { return nil }+ return "Recommended only for Macs with more than \(self.comfortableMemoryGB) GB of memory."+ }}@MainActordiff --git a/Sources/Fluid/UI/MeetingDetectionPrompt.swift b/Sources/Fluid/UI/MeetingDetectionPrompt.swiftindex f2415071..f9a21eac 100644--- a/Sources/Fluid/UI/MeetingDetectionPrompt.swift+++ b/Sources/Fluid/UI/MeetingDetectionPrompt.swift@@ -614,20 +614,21 @@ private struct MeetingDetectionPromptContent: View {}}-/// "Still recording?" nudge — passive, pill-adjacent, shown once per recording session while our-/// own recording's originating meeting evidence has been gone for a while.+/// "Meeting ended?" nudge — passive, pill-adjacent, shown while the meeting behind our own+/// recording looks over. It stays until the user answers, the call resumes, or the recording stops:+/// someone who walked away should still find it when they come back.@MainActorfinal class MeetingStillRecordingNudgeController: ObservableObject {static let shared = MeetingStillRecordingNudgeController()- private static let panelSize = NSSize(width: 260, height: 64)- private static let autoDismissSeconds: TimeInterval = 20+ static let panelSize = NSSize(width: 332, height: 56)@Published private(set) var isPresented = falsevar onStop: (() -> Void)?+ /// The user closed the question without stopping.+ var onDismiss: (() -> Void)?private var panel: MeetingFloatingCaptionsPanel?- private var autoDismissTask: Task<Void, Never>?private init() {}@@ -636,26 +637,37 @@ final class MeetingStillRecordingNudgeController: ObservableObject {self.isPresented = truelet panel = self.panelOrCreate()if let pillFrame = MeetingRecordingPillController.shared.currentOverlayFrame ?? self.pillFrameFallback() {- var frame = pillFrame- frame.origin.y += pillFrame.height + 8- frame.size = Self.panelSize- panel.setFrame(frame, display: false)+ let screen = NSScreen.screens.first { $0.frame.intersects(pillFrame) }?.visibleFrame+ panel.setFrame(Self.frame(abovePill: pillFrame, within: screen), display: false)}panel.orderFrontRegardless()- self.autoDismissTask?.cancel()- self.autoDismissTask = Task { [weak self] in- try? await Task.sleep(nanoseconds: UInt64(Self.autoDismissSeconds * 1_000_000_000))- guard !Task.isCancelled else { return }- self?.hide()+ }++ /// Centered just above the recording pill, pulled back inside the screen when the pill sits+ /// near an edge.+ static func frame(abovePill pillFrame: NSRect, within screen: NSRect?) -> NSRect {+ var frame = NSRect(+ x: pillFrame.midX - Self.panelSize.width / 2,+ y: pillFrame.maxY + 8,+ width: Self.panelSize.width,+ height: Self.panelSize.height+ )+ if let screen, screen.width >= frame.width {+ frame.origin.x = min(max(frame.origin.x, screen.minX), screen.maxX - frame.width)}+ return frame}func hide() {- self.autoDismissTask?.cancel()self.isPresented = falseself.panel?.orderOut(nil)}+ func dismiss() {+ self.onDismiss?()+ self.hide()+ }+private func pillFrameFallback() -> NSRect? {let screen = OverlayScreenResolver.screenForCurrentPointer() ?? NSScreen.mainguard let screen else { return nil }@@ -699,16 +711,31 @@ private struct MeetingStillRecordingNudgeContent: View {Text("Meeting ended?").font(self.theme.typography.bodySmall).foregroundStyle(self.theme.palette.primaryText)- Spacer()+ .lineLimit(1)+ .fixedSize()+ Spacer(minLength: 0)Button("Stop & Transcribe") {self.controller.onStop?()self.controller.hide()}.fluidButton(.compact, size: .small)+ Button {+ self.controller.dismiss()+ } label: {+ Image(systemName: "xmark")+ .font(.system(size: 10, weight: .semibold))+ .foregroundStyle(self.theme.palette.secondaryText)+ .frame(width: 20, height: 20)+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ .help("Keep recording")+ .accessibilityLabel("Keep recording")}- .padding(.horizontal, 12)+ .padding(.leading, 12)+ .padding(.trailing, 8).padding(.vertical, 10)- .frame(width: 260, height: 64)+ .frame(width: MeetingStillRecordingNudgeController.panelSize.width, height: MeetingStillRecordingNudgeController.panelSize.height).background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(self.theme.palette.contentBackground.opacity(0.96))diff --git a/Sources/Fluid/UI/MeetingRecordingSettingsSheet.swift b/Sources/Fluid/UI/MeetingRecordingSettingsSheet.swiftindex 9bc59b6d..efac4e9a 100644--- a/Sources/Fluid/UI/MeetingRecordingSettingsSheet.swift+++ b/Sources/Fluid/UI/MeetingRecordingSettingsSheet.swift@@ -360,11 +360,11 @@ struct MeetingRecordingSettingsSheet: View {}private var meetingApplications: [MeetingApplicationOption] {- self.applications.filter { MeetingAppRegistry.tier(forBundleIdentifier: $0.identity.bundleIdentifier) != nil }+ self.applications.pickerSections.usual}private var otherApplications: [MeetingApplicationOption] {- self.applications.filter { MeetingAppRegistry.tier(forBundleIdentifier: $0.identity.bundleIdentifier) == nil }+ self.applications.pickerSections.others}private var selectedApplicationName: String {diff --git a/Sources/Fluid/UI/MeetingSummaryView.swift b/Sources/Fluid/UI/MeetingSummaryView.swiftindex 85839ea8..31c2a8d2 100644--- a/Sources/Fluid/UI/MeetingSummaryView.swift+++ b/Sources/Fluid/UI/MeetingSummaryView.swift@@ -236,9 +236,22 @@ struct MeetingSummaryView: View {onDismiss: { self.showModelPicker = false })}+ if self.usesOnDevice, let memoryWarning = self.memoryWarning {+ Label(memoryWarning, systemImage: "exclamationmark.triangle")+ .font(self.theme.typography.caption)+ .foregroundStyle(self.theme.palette.warning)+ .fixedSize(horizontal: false, vertical: true)+ }}}+ private var memoryWarning: String? {+ MeetingSummaryOnDevice.memoryWarning(+ recommendedMemoryGB: self.onDeviceModel?.recommendedMemoryGB,+ memoryGB: MeetingSummaryOnDevice.thisMacMemoryGB+ )+ }+private var kindPicker: some View {VStack(alignment: .leading, spacing: 6) {Text("Summary type").font(self.theme.typography.caption)diff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swiftindex 7553dc4c..300a921a 100644--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift@@ -14,6 +14,21 @@ nonisolated struct MeetingApplicationOption: Identifiable, Equatable, Sendable {}}+extension [MeetingApplicationOption] {+ /// The usual meeting sources first, then the rest with background helpers last.+ @MainActor+ var pickerSections: (usual: [MeetingApplicationOption], others: [MeetingApplicationOption]) {+ MeetingAppRegistry.pickerSections(+ self,+ bundleIdentifier: { $0.identity.bundleIdentifier },+ name: { $0.identity.displayName },+ isBackgroundItem: { option in+ option.identity.processID.flatMap { NSRunningApplication(processIdentifier: $0) }?.activationPolicy != .regular+ }+ )+ }+}+struct MeetingMicrophoneOption: Identifiable, Equatable {let id: Stringlet identity: MeetingMicrophoneIdentity@@ -2088,11 +2103,11 @@ private struct MeetingSetupCanvas: View {}private var meetingApplications: [MeetingApplicationOption] {- self.applications.filter { MeetingAppRegistry.tier(forBundleIdentifier: $0.identity.bundleIdentifier) != nil }+ self.applications.pickerSections.usual}private var otherApplications: [MeetingApplicationOption] {- self.applications.filter { MeetingAppRegistry.tier(forBundleIdentifier: $0.identity.bundleIdentifier) == nil }+ self.applications.pickerSections.others}var body: some View {diff --git a/Tests/FluidDictationIntegrationTests/MeetingAutoDetectorTests.swift b/Tests/FluidDictationIntegrationTests/MeetingAutoDetectorTests.swiftindex 595fb8b2..8872576d 100644--- a/Tests/FluidDictationIntegrationTests/MeetingAutoDetectorTests.swift+++ b/Tests/FluidDictationIntegrationTests/MeetingAutoDetectorTests.swift@@ -84,6 +84,7 @@ private final class FakeActivityGate: DetectionActivityGate {private final class ToggleFlags {var nativeEnabled = truevar browserEnabled = true+ var lastSpeechAt: Date?}@MainActor@@ -96,6 +97,7 @@ private final class DetectorHarness {let workspace = FakeWorkspaceEvents()var prompts: [MeetingAutoDetector.PromptRequest] = []var nudges = 0+ var withdrawals = 0var invalidated: [UUID] = []let detector: MeetingAutoDetector@@ -121,10 +123,12 @@ private final class DetectorHarness {clock: self.clock,isNativeDetectionEnabled: { flags.nativeEnabled },isBrowserDetectionEnabled: { flags.browserEnabled },+ lastSpeechAt: { flags.lastSpeechAt },rejectionLogger: rejectionLogger)self.detector.onPromptRequested = { [weak self] request in self?.prompts.append(request) }self.detector.onStillRecordingNudge = { [weak self] in self?.nudges += 1 }+ self.detector.onStillRecordingNudgeWithdrawn = { [weak self] in self?.withdrawals += 1 }self.detector.onEpisodeInvalidated = { [weak self] episodeID in self?.invalidated.append(episodeID) }}@@ -143,6 +147,43 @@ private final class DetectorHarness {self.detector.handleMicEdge(.init(isActive: true), at: self.clock.now())return self.prompts.last?.episodeID}++ /// A Google Meet call in Chrome, confirmed from the front tab.+ @discardableResult+ func confirmChromeMeet(pid: Int32 = 8) -> UUID? {+ self.workspace.frontmostProcessID = pid+ self.detector.handleBackfill([.init(kind: .launched, bundleIdentifier: "com.google.Chrome", processID: pid)])+ self.detector.handleBrowserTabURL(.init(host: "meet.google.com", path: "/abc-defg-hij"), pid: pid, bundleIdentifier: "com.google.Chrome", at: self.clock.now())+ self.detector.handleMicEdge(.init(isActive: true), at: self.clock.now())+ return self.prompts.last?.episodeID+ }++ /// What the audio system reports for Chrome: its helper holds the microphone, or nothing does.+ func pollChrome(microphoneInUse: Bool, pid: Int32 = 8, readable: Bool = true) async {+ let chrome = MeetingProcessOwner(processID: pid, bundleIdentifier: "com.google.Chrome", bundlePath: "/Applications/Google Chrome.app")+ let helper = AudioProcessDescriptor(+ processID: 4242,+ bundleIdentifier: "com.google.Chrome.helper",+ executablePath: "/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper",+ isInputRunning: microphoneInUse,+ isOutputRunning: true+ )+ self.audioProcessActivity.snapshotOverride = AudioProcessActivitySnapshot(+ processes: [helper],+ owners: [chrome],+ queryState: readable ? .valid : .unknown+ )+ await self.detector.pollAudioProcessActivity(at: self.clock.now())+ }++ /// Teams keeps a window open all day, so only its audio says whether a call is on.+ @discardableResult+ func confirmTeams(pid: Int32 = 300) -> UUID? {+ self.detector.handleWorkspaceEvent(.init(kind: .activated, bundleIdentifier: "com.microsoft.teams2", processID: pid), at: self.clock.now())+ self.detector.handleWindowSnapshot([.init(processID: pid, windowID: 950, title: nil, layer: 0)], at: self.clock.now())+ self.detector.handleMicEdge(.init(isActive: true), at: self.clock.now())+ return self.prompts.last?.episodeID+ }}@MainActor@@ -1203,8 +1244,676 @@ final class MeetingAutoDetectorTests: XCTestCase {XCTAssertEqual(h.nudges, 1, "the nudge fires once per session")}+ func testTeamsAsksOnceItsAudioStopsEvenThoughItsWindowStaysOpen() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmTeams())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.advance(600)+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0, "a call that is still using audio is not over")++ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds - 2)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0, "a short gap in the app's audio is not the end of the call")++ h.advance(4)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ h.advance(120)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1, "the episode retiring must not ask a second time")+ }++ func testAudioThatComesBackBeforeTheGraceEndsNeverAsks() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmTeams())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())++ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.advance(10)+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.advance(60)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)+ }++ func testAnAppWhoseAudioWasNeverSeenRunningDoesNotAskWhenItReadsAsIdle() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmTeams())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))++ // The per-app audio query never showed this app running, so "not running" tells us nothing.+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.advance(300)+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)+ }++ func testAnUnreadableAudioQueryIsNotTakenAsTheCallEnding() async throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmTeams())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())++ h.audioProcessActivity.snapshotOverride = AudioProcessActivitySnapshot(processes: [], owners: [], queryState: .unknown)+ await h.detector.pollAudioProcessActivity(at: h.clock.now())+ h.advance(120)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)+ }++ func testQuittingTheMeetingAppAsksAfterTheGrace() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))++ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "us.zoom.xos", processID: 100), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)++ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ // Another app that happens to get the same process ID is not our meeting coming back.+ h.detector.handleWorkspaceEvent(.init(kind: .launched, bundleIdentifier: "com.microsoft.teams2", processID: 100), at: h.clock.now())+ h.advance(60)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)+ }++ func testTheQuestionWaitsWhilePeopleAreStillTalking() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmTeams())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())++ // The call dropped but the people in the room carry on.+ for _ in 0..<10 {+ h.advance(30)+ h.flags.lastSpeechAt = h.clock.now().addingTimeInterval(-5)+ h.detector.tick(at: h.clock.now())+ }+ XCTAssertEqual(h.nudges, 0)++ h.advance(MeetingAutoDetector.speechQuietSeconds - 10)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0, "45 seconds of quiet are not up yet")++ h.advance(10)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)+ }++ func testTalkingAloneNeverAsksAndQuietAloneNeverAsks() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmTeams())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())++ // A long silence in a call that is still connected is just a quiet meeting.+ h.flags.lastSpeechAt = h.clock.now()+ h.advance(1800)+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)+ }++ /// Starts a Teams recording, lets the call drop, and waits until the question is asked.+ private func teamsRecordingThatAsked() throws -> DetectorHarness {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmTeams())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)+ return h+ }++ func testTheQuestionIsTakenBackWhenTheCallResumesAndAskedAgainAtTheNextEnd() throws {+ let h = try self.teamsRecordingThatAsked()+ h.advance(30)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0, "the call is still down, so the question stays")++ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)++ h.advance(600)+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 2)+ }++ func testAZoomWindowComingBackTakesTheQuestionBack() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleWindowSnapshot([], at: h.clock.now())+ h.advance(65)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ h.detector.handleWindowSnapshot([.init(processID: 100, windowID: 900, title: "Zoom Meeting", layer: 0)], at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)+ }++ func testADismissedQuestionStaysAwayForTheRestOfThatRecordingOnly() throws {+ let h = try self.teamsRecordingThatAsked()+ h.detector.stillRecordingNudgeDismissed()++ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0, "there is nothing on screen to take back")+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 10)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ // The next recording of the same call starts fresh.+ h.detector.recordingStopped()+ try h.detector.adoptStartedEpisode(episodeID: XCTUnwrap(h.prompts.last?.episodeID))+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.handleAudioProcessActivity(false, pid: 300, at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 2)+ }++ func testAnUnreadableAudioQueryDoesNotTakeTheQuestionBack() async throws {+ let h = try self.teamsRecordingThatAsked()+ h.audioProcessActivity.snapshotOverride = AudioProcessActivitySnapshot(processes: [], owners: [], queryState: .unknown)+ await h.detector.pollAudioProcessActivity(at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0)+ }++ func testAQuitAppIsNotBroughtBackByAnotherAppWithItsProcessID() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "us.zoom.xos", processID: 100), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ h.detector.handleWorkspaceEvent(.init(kind: .launched, bundleIdentifier: "com.microsoft.teams2", processID: 100), at: h.clock.now())+ h.advance(60)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0)+ XCTAssertEqual(h.nudges, 1)+ }++ func testScreenLockLeavesAQuestionAlreadyAskedOnScreen() throws {+ let h = try self.teamsRecordingThatAsked()+ h.detector.disarmAndClearTransientState()+ h.advance(120)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0)+ XCTAssertEqual(h.nudges, 1)+ }++ func testTheQuestionSitsCenteredAboveThePillAndStaysOnScreen() {+ let size = MeetingStillRecordingNudgeController.panelSize+ let screen = NSRect(x: 0, y: 0, width: 1440, height: 900)++ let middle = MeetingStillRecordingNudgeController.frame(abovePill: NSRect(x: 678, y: 64, width: 84, height: 32), within: screen)+ XCTAssertEqual(middle.midX, 720)+ XCTAssertEqual(middle.minY, 104)+ XCTAssertEqual(middle.size, size)++ let leftEdge = MeetingStillRecordingNudgeController.frame(abovePill: NSRect(x: 4, y: 64, width: 84, height: 32), within: screen)+ XCTAssertEqual(leftEdge.minX, 0)+ let rightEdge = MeetingStillRecordingNudgeController.frame(abovePill: NSRect(x: 1350, y: 64, width: 84, height: 32), within: screen)+ XCTAssertEqual(rightEdge.maxX, 1440)++ let unknownScreen = MeetingStillRecordingNudgeController.frame(abovePill: NSRect(x: 4, y: 64, width: 84, height: 32), within: nil)+ XCTAssertEqual(unknownScreen.midX, 46)+ }++ func testADismissedQuestionTellsTheDetectorAndStopDoesNot() {+ let controller = MeetingStillRecordingNudgeController.shared+ let earlierDismiss = controller.onDismiss+ defer { controller.onDismiss = earlierDismiss }+ var dismissals = 0+ controller.onDismiss = { dismissals += 1 }++ controller.hide()+ XCTAssertEqual(dismissals, 0, "taking the question down is not the user closing it")+ controller.dismiss()+ XCTAssertEqual(dismissals, 1)+ XCTAssertFalse(controller.isPresented)+ }++ // MARK: - Web meetings end with the browser's microphone, not with the front tab++ func testSwitchingTabsDuringAWebMeetingNeverAsks() async throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmChromeMeet())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ await h.pollChrome(microphoneInUse: true)++ // The user reads a doc in another tab for ten minutes while the call goes on.+ h.detector.handleBrowserTabURL(.init(host: "docs.google.com", path: "/document/d/1"), pid: 8, bundleIdentifier: "com.google.Chrome", at: h.clock.now())+ for _ in 0..<10 {+ h.advance(60)+ await h.pollChrome(microphoneInUse: true)+ h.detector.tick(at: h.clock.now())+ }+ XCTAssertEqual(h.nudges, 0)+ }++ func testAWebMeetingAsksOnceTheBrowserLetsGoOfTheMicrophone() async throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmChromeMeet())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ await h.pollChrome(microphoneInUse: true)++ // Left the call. The Meet tab still shows the same address, so the tab says nothing.+ await h.pollChrome(microphoneInUse: false)+ h.advance(MeetingAutoDetector.endSignalGraceSeconds - 2)+ await h.pollChrome(microphoneInUse: false)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)++ h.advance(4)+ await h.pollChrome(microphoneInUse: false)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ // Rejoined: the question goes away.+ await h.pollChrome(microphoneInUse: true)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)+ }++ func testABrowserWhoseMicrophoneWeNeverSawNeverAsks() async throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmChromeMeet())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))++ // Safari records through a system process we cannot tie to it, so its microphone always reads as off.+ h.detector.handleBrowserTabURL(nil, pid: 8, bundleIdentifier: "com.google.Chrome", at: h.clock.now())+ for _ in 0..<5 {+ h.advance(60)+ await h.pollChrome(microphoneInUse: false)+ h.detector.tick(at: h.clock.now())+ }+ XCTAssertEqual(h.nudges, 0)+ }++ func testAnUnreadableMicrophoneQueryNeitherAsksNorTakesTheQuestionBackForAWebMeeting() async throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmChromeMeet())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ await h.pollChrome(microphoneInUse: true)++ for _ in 0..<5 {+ h.advance(30)+ await h.pollChrome(microphoneInUse: false, readable: false)+ h.detector.tick(at: h.clock.now())+ }+ XCTAssertEqual(h.nudges, 0, "not readable is not a release")++ await h.pollChrome(microphoneInUse: false)+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ await h.pollChrome(microphoneInUse: false)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ await h.pollChrome(microphoneInUse: false, readable: false)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0)+ }++ func testQuittingTheBrowserStillAsks() async throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmChromeMeet())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))++ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "com.google.Chrome", processID: 8), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)+ }++ func testBrowserMicrophoneIsReadOnlyWhenAskedForAndNeverCountsAsANativeMeeting() {+ let chrome = MeetingProcessOwner(processID: 8, bundleIdentifier: "com.google.Chrome", bundlePath: "/Applications/Google Chrome.app")+ let zoom = MeetingProcessOwner(processID: 100, bundleIdentifier: "us.zoom.xos", bundlePath: "/Applications/zoom.us.app")+ let helper = AudioProcessDescriptor(+ processID: 4242,+ bundleIdentifier: nil,+ executablePath: "/Applications/Google Chrome.app/Contents/Frameworks/Helpers/Google Chrome Helper",+ isInputRunning: true,+ isOutputRunning: true+ )+ let snapshot = AudioProcessActivitySnapshot(processes: [helper], owners: [chrome, zoom], queryState: .valid)+ XCTAssertEqual(MeetingAudioProcessResolver.activeOwnerInputByPID(snapshot: snapshot), [:])+ XCTAssertEqual(+ MeetingAudioProcessResolver.activeOwnerInputByPID(snapshot: snapshot, owning: MeetingAppRegistry.isBrowserApp(bundleIdentifier:)),+ [8: true]+ )+ }++ // MARK: - The call comes back in ways the first version missed++ func testAMutedTeamsCallThatResumesAfterALongGapTakesTheQuestionBack() async throws {+ let h = try self.teamsRecordingThatAsked()+ // Long enough for the start-prompt episode to retire.+ h.advance(120)+ h.detector.tick(at: h.clock.now())++ // Rejoined on mute: Teams plays the call but is not using the microphone.+ let teams = MeetingProcessOwner(processID: 300, bundleIdentifier: "com.microsoft.teams2", bundlePath: "/Applications/Microsoft Teams.app")+ let helper = AudioProcessDescriptor(+ processID: 301,+ bundleIdentifier: nil,+ executablePath: "/Applications/Microsoft Teams.app/Contents/Helpers/Teams Helper",+ isInputRunning: false,+ isOutputRunning: true+ )+ h.audioProcessActivity.snapshotOverride = AudioProcessActivitySnapshot(processes: [helper], owners: [teams], queryState: .valid)+ await h.detector.pollAudioProcessActivity(at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)+ XCTAssertEqual(h.prompts.count, 1, "sound without a microphone still never raises a new start prompt")+ }++ func testAMeetingAppThatRestartsAndRejoinsIsFollowed() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "us.zoom.xos", processID: 100), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ // Zoom is back under a new process but not in a call yet: nothing changes.+ h.detector.handleWorkspaceEvent(.init(kind: .activated, bundleIdentifier: "us.zoom.xos", processID: 101), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0)++ h.detector.handleWindowSnapshot([.init(processID: 101, windowID: 901, title: "Zoom Meeting", layer: 0)], at: h.clock.now())+ h.detector.handleAudioProcessActivity(true, pid: 101, at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)++ // From here the new process is the one that is watched.+ h.advance(300)+ h.detector.handleAudioProcessActivity(false, pid: 101, at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 2)+ }++ func testADifferentMeetingAppInACallIsNeverTakenForTheOneThatQuit() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "us.zoom.xos", processID: 100), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ h.detector.handleWorkspaceEvent(.init(kind: .activated, bundleIdentifier: "com.microsoft.teams2", processID: 300), at: h.clock.now())+ h.detector.handleWindowSnapshot([.init(processID: 300, windowID: 950, title: nil, layer: 0)], at: h.clock.now())+ h.detector.handleAudioProcessActivity(true, pid: 300, at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0)+ }++ func testABrowserThatRestartsAndRejoinsIsFollowed() async throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmChromeMeet())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))+ await h.pollChrome(microphoneInUse: true)+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "com.google.Chrome", processID: 8), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ h.detector.handleWorkspaceEvent(.init(kind: .launched, bundleIdentifier: "com.google.Chrome", processID: 9), at: h.clock.now())+ await h.pollChrome(microphoneInUse: false, pid: 9)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0, "the browser is open again but not in a call")++ // A voice recorder page uses the microphone too. That is not the meeting coming back.+ h.detector.handleBrowserTabURL(.init(host: "voicerecorder.example", path: "/"), pid: 9, bundleIdentifier: "com.google.Chrome", at: h.clock.now())+ await h.pollChrome(microphoneInUse: true, pid: 9)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0)++ h.detector.handleBrowserTabURL(.init(host: "meet.google.com", path: "/abc-defg-hij"), pid: 9, bundleIdentifier: "com.google.Chrome", at: h.clock.now())+ await h.pollChrome(microphoneInUse: true, pid: 9)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)+ }++ func testARelaunchedTeamsPlayingASoundIsNotTakenForTheCallComingBack() async throws {+ let h = try self.teamsRecordingThatAsked()+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "com.microsoft.teams2", processID: 300), at: h.clock.now())+ h.detector.handleWorkspaceEvent(.init(kind: .activated, bundleIdentifier: "com.microsoft.teams2", processID: 302), at: h.clock.now())+ h.detector.handleWindowSnapshot([.init(processID: 302, windowID: 951, title: nil, layer: 0)], at: h.clock.now())++ func poll(microphoneInUse: Bool) async {+ let teams = MeetingProcessOwner(processID: 302, bundleIdentifier: "com.microsoft.teams2", bundlePath: "/Applications/Microsoft Teams.app")+ let helper = AudioProcessDescriptor(+ processID: 303,+ bundleIdentifier: nil,+ executablePath: "/Applications/Microsoft Teams.app/Contents/Helpers/Teams Helper",+ isInputRunning: microphoneInUse,+ isOutputRunning: true+ )+ h.audioProcessActivity.snapshotOverride = AudioProcessActivitySnapshot(processes: [helper], owners: [teams], queryState: .valid)+ await h.detector.pollAudioProcessActivity(at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ }++ // A notification chime: sound, no microphone.+ await poll(microphoneInUse: false)+ XCTAssertEqual(h.withdrawals, 0)++ // Back in the call with the microphone on.+ await poll(microphoneInUse: true)+ XCTAssertEqual(h.withdrawals, 1)+ }++ func testAGoogleMeetWebAppEndsOnItsBrowsersMicrophone() async throws {+ let h = DetectorHarness()+ let webApp = "com.google.Chrome.app.kjgfgldnnfoeklkmfkjfagphfepbbdan"+ XCTAssertEqual(MeetingAppRegistry.parentBrowser(ofWebApp: webApp), "com.google.Chrome")+ XCTAssertEqual(MeetingAppRegistry.parentBrowser(ofWebApp: "com.microsoft.edgemac.app.abc"), "com.microsoft.edgemac")+ XCTAssertNil(MeetingAppRegistry.parentBrowser(ofWebApp: "com.google.Chrome"))++ h.workspace.frontmostProcessID = 20+ h.detector.handleBackfill([.init(kind: .launched, bundleIdentifier: webApp, processID: 20)])+ h.detector.handleBrowserTabURL(.init(host: "meet.google.com", path: "/abc-defg-hij"), pid: 20, bundleIdentifier: webApp, at: h.clock.now())+ h.detector.handleMicEdge(.init(isActive: true), at: h.clock.now())+ let episodeID = try XCTUnwrap(h.prompts.last?.episodeID)+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))++ // The web app has its own process, but Chrome (pid 8) is what holds the microphone.+ await h.pollChrome(microphoneInUse: true, pid: 8)+ await h.pollChrome(microphoneInUse: false, pid: 8)+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ await h.pollChrome(microphoneInUse: false, pid: 8)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ await h.pollChrome(microphoneInUse: true, pid: 8)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)+ }++ /// Starts a recording of Google Meet's web app (pid 20), which records through Chrome (pid 8).+ private func meetWebAppRecording(_ h: DetectorHarness, pid: Int32 = 20) throws {+ let webApp = "com.google.Chrome.app.kjgfgldnnfoeklkmfkjfagphfepbbdan"+ h.workspace.frontmostProcessID = pid+ h.detector.handleBackfill([.init(kind: .launched, bundleIdentifier: webApp, processID: pid)])+ h.detector.handleBrowserTabURL(.init(host: "meet.google.com", path: "/abc-defg-hij"), pid: pid, bundleIdentifier: webApp, at: h.clock.now())+ h.detector.handleMicEdge(.init(isActive: true), at: h.clock.now())+ XCTAssertTrue(try h.detector.startTapped(episodeID: XCTUnwrap(h.prompts.last?.episodeID)))+ }++ func testTwoCopiesOfTheBrowserLeaveAWebAppsMicrophoneUnknownNotReleased() async throws {+ let h = DetectorHarness()+ try self.meetWebAppRecording(h)+ await h.pollChrome(microphoneInUse: true, pid: 8)++ // A second Chrome from another folder opens. Which one the web app runs in can no longer be told.+ let stable = MeetingProcessOwner(processID: 8, bundleIdentifier: "com.google.Chrome", bundlePath: "/Applications/Google Chrome.app")+ let other = MeetingProcessOwner(processID: 18, bundleIdentifier: "com.google.Chrome", bundlePath: "/Users/me/Apps/Google Chrome.app")+ let helper = AudioProcessDescriptor(+ processID: 4242,+ bundleIdentifier: nil,+ executablePath: "/Applications/Google Chrome.app/Contents/Frameworks/Helpers/Google Chrome Helper",+ isInputRunning: true,+ isOutputRunning: true+ )+ h.audioProcessActivity.snapshotOverride = AudioProcessActivitySnapshot(processes: [helper], owners: [stable, other], queryState: .valid)+ for _ in 0..<5 {+ h.advance(30)+ await h.detector.pollAudioProcessActivity(at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ }+ XCTAssertEqual(h.nudges, 0, "the call is still on")+ }++ func testARelaunchedMeetWebAppIsFollowedThroughItsBrowser() async throws {+ let h = DetectorHarness()+ let webApp = "com.google.Chrome.app.kjgfgldnnfoeklkmfkjfagphfepbbdan"+ try self.meetWebAppRecording(h)+ await h.pollChrome(microphoneInUse: true, pid: 8)+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: webApp, processID: 20), at: h.clock.now())+ h.detector.tick(at: h.clock.now())+ h.advance(MeetingAutoDetector.endSignalGraceSeconds + 1)+ await h.pollChrome(microphoneInUse: false, pid: 8)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 1)++ // The web app is opened again, on the meeting, and Chrome has the microphone.+ h.detector.handleWorkspaceEvent(.init(kind: .launched, bundleIdentifier: webApp, processID: 21), at: h.clock.now())+ await h.pollChrome(microphoneInUse: true, pid: 8)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 0, "open again, but not on a meeting yet")++ h.detector.handleBrowserTabURL(.init(host: "meet.google.com", path: "/abc-defg-hij"), pid: 21, bundleIdentifier: webApp, at: h.clock.now())+ await h.pollChrome(microphoneInUse: true, pid: 8)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.withdrawals, 1)+ }++ func testNothingIsAskedOnceOurRecordingHasStopped() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))++ // The user stopped our recording mid-call. The call ending later is no longer our business.+ h.detector.recordingStopped()+ h.detector.handleWindowSnapshot([], at: h.clock.now())+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "us.zoom.xos", processID: 100), at: h.clock.now())+ h.advance(120)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)+ }++ func testAMeetingNobodyRecordedNeverAsks() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ h.detector.timeoutDismissed(episodeID: episodeID)++ h.detector.handleWindowSnapshot([], at: h.clock.now())+ h.detector.handleWorkspaceEvent(.init(kind: .terminated, bundleIdentifier: "us.zoom.xos", processID: 100), at: h.clock.now())+ h.advance(120)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)+ }++ func testScreenLockStopsTheWatchInsteadOfReadingItAsTheAppQuitting() throws {+ let h = DetectorHarness()+ let episodeID = try XCTUnwrap(h.confirmZoom())+ XCTAssertTrue(h.detector.startTapped(episodeID: episodeID))++ h.detector.disarmAndClearTransientState()+ h.advance(120)+ h.detector.tick(at: h.clock.now())+ XCTAssertEqual(h.nudges, 0)+ }+// MARK: - Registry / URL matcher sanity+ func testSourcePickerPutsTheUsualMeetingAppsFirstAndBackgroundHelpersLast() {+ struct App: Equatable {+ var bundle: String+ var name: String+ var background = false+ }+ let apps = [+ App(bundle: "com.apple.controlcenter", name: "Control Center", background: true),+ App(bundle: "com.apple.Safari", name: "Safari"),+ App(bundle: "com.apple.Music", name: "Music"),+ App(bundle: "com.tinyspeck.slackmacgap", name: "Slack"),+ App(bundle: "com.apple.AirPlayUIAgent", name: "AirPlayUIAgent", background: true),+ App(bundle: "com.google.Chrome", name: "Google Chrome"),+ App(bundle: "com.google.Chrome.app.kjgfgldnnfoeklkmfkjfagphfepbbdan", name: "Google Meet"),+ App(bundle: "com.apple.finder", name: "Finder"),+ App(bundle: "com.microsoft.teams2", name: "Microsoft Teams"),+ App(bundle: "us.zoom.xos", name: "zoom.us"),+ App(bundle: "com.apple.FaceTime", name: "FaceTime"),+ ]+ let sections = MeetingAppRegistry.pickerSections(apps, bundleIdentifier: \.bundle, name: \.name, isBackgroundItem: \.background)+ XCTAssertEqual(+ sections.usual.map(\.name),+ ["zoom.us", "Microsoft Teams", "FaceTime", "Slack", "Google Meet", "Google Chrome", "Safari"]+ )+ XCTAssertEqual(sections.others.map(\.name), ["Finder", "Music", "AirPlayUIAgent", "Control Center"])+ XCTAssertEqual(sections.usual.count + sections.others.count, apps.count, "nothing is dropped from the list")+ }++ func testAppsThatOnlyShapeThePickerAreNeverDetected() {+ for bundle in MeetingAppRegistry.otherCallAppBundleIdentifiers {+ XCTAssertNil(MeetingAppRegistry.tier(forBundleIdentifier: bundle), bundle)+ XCTAssertNotNil(MeetingAppRegistry.pickerRank(forBundleIdentifier: bundle), bundle)+ }+ XCTAssertNil(MeetingAppRegistry.pickerRank(forBundleIdentifier: "com.apple.Music"))+ }++ func testBrowserMeetingsAreDetectedUntilTheUserTurnsThatOff() {+ let key = "MeetingAutoDetectBrowserEnabled"+ let defaults = UserDefaults.standard+ let earlier = defaults.object(forKey: key)+ defer {+ if let earlier { defaults.set(earlier, forKey: key) } else { defaults.removeObject(forKey: key) }+ }++ defaults.removeObject(forKey: key)+ XCTAssertTrue(SettingsStore.shared.meetingAutoDetectBrowserEnabled, "never chosen means on")+ SettingsStore.shared.meetingAutoDetectBrowserEnabled = false+ XCTAssertFalse(SettingsStore.shared.meetingAutoDetectBrowserEnabled, "a stored off stays off")+ SettingsStore.shared.meetingAutoDetectBrowserEnabled = true+ XCTAssertTrue(SettingsStore.shared.meetingAutoDetectBrowserEnabled)+ }+func testRegistryTierLookup() {XCTAssertEqual(MeetingAppRegistry.tier(forBundleIdentifier: "us.zoom.xos"), .nativeTier1)XCTAssertEqual(MeetingAppRegistry.tier(forBundleIdentifier: "com.google.Chrome"), .browserTier2)diff --git a/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift b/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swiftindex 870c2c3c..7de86cbb 100644--- a/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift+++ b/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift@@ -42,6 +42,7 @@ final class MeetingModelPreparationQueueTests: XCTestCase {if self.isOpen { return }await withCheckedContinuation { self.continuation = $0 }}+func open() {self.isOpen = trueself.continuation?.resume()@@ -166,6 +167,25 @@ final class MeetingLiveTranscriptSnapshotTests: XCTestCase {XCTAssertNotEqual(current.availability, .available)}+ func testNewWordsCountAsSpeechAndCaptionHousekeepingDoesNot() {+ let empty = MeetingLiveTranscriptSnapshot.empty+ let partial = MeetingLivePartial(id: UUID(), text: "so the", start: 1)+ let talking = empty.settingPartial(partial, for: .them)+ XCTAssertTrue(talking.hasNewWords(since: empty))+ XCTAssertFalse(talking.hasNewWords(since: talking))++ var longer = partial+ longer.text = "so the plan"+ XCTAssertTrue(talking.settingPartial(longer, for: .them).hasNewWords(since: talking))++ let finished = talking.inserting(self.utterance(.them, "so the plan", start: 1, end: 2)).settingPartial(nil, for: .them)+ XCTAssertTrue(finished.hasNewWords(since: talking))++ XCTAssertFalse(talking.settingPartial(nil, for: .them).hasNewWords(since: talking), "a caption going away is not speech")+ XCTAssertFalse(finished.settingAvailability(.available).hasNewWords(since: finished))+ XCTAssertFalse(finished.markingFinalized(UUID()).hasNewWords(since: finished))+ }+private func utterance(_ speaker: MeetingLiveSpeaker, _ text: String, start: TimeInterval, end: TimeInterval) -> MeetingLiveUtterance {MeetingLiveUtterance(id: UUID(), speaker: speaker, text: text, start: start, end: end)}diff --git a/Tests/FluidDictationIntegrationTests/MeetingSummaryInputTests.swift b/Tests/FluidDictationIntegrationTests/MeetingSummaryInputTests.swiftindex 02cbfd89..1a2f7140 100644--- a/Tests/FluidDictationIntegrationTests/MeetingSummaryInputTests.swift+++ b/Tests/FluidDictationIntegrationTests/MeetingSummaryInputTests.swift@@ -340,4 +340,21 @@ final class MeetingSummaryActivityTests: XCTestCase {XCTAssertEqual(activity.handbacks, 0)XCTAssertNotNil(gate.beginProcessing())}++ func testALargeSummaryModelComesWithAWarningOnASixteenGBMacOnly() {+ // The 9B recommends 24 GB.+ XCTAssertEqual(+ MeetingSummaryOnDevice.memoryWarning(recommendedMemoryGB: 24, memoryGB: 16),+ "Recommended only for Macs with more than 16 GB of memory."+ )+ XCTAssertNil(MeetingSummaryOnDevice.memoryWarning(recommendedMemoryGB: 24, memoryGB: 18))+ XCTAssertNil(MeetingSummaryOnDevice.memoryWarning(recommendedMemoryGB: 24, memoryGB: 64))+ }++ func testASmallSummaryModelNeverWarns() {+ for memoryGB in [8, 16, 24] {+ XCTAssertNil(MeetingSummaryOnDevice.memoryWarning(recommendedMemoryGB: 8, memoryGB: memoryGB))+ XCTAssertNil(MeetingSummaryOnDevice.memoryWarning(recommendedMemoryGB: nil, memoryGB: memoryGB))+ }+ }}