Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat(mobile): Show a Live Activity while a meeting records (#2362)
Chad Pihae0a2b4829723
diff --git a/.github/workflows/mobile-ci.yml b/.github/workflows/mobile-ci.ymlindex 7726bc9bc..7248338bd 100644--- a/.github/workflows/mobile-ci.yml+++ b/.github/workflows/mobile-ci.yml@@ -97,10 +97,10 @@ jobs:OPENWHISPR_APP_ENV: productionnative-transport:- name: Mobile native provider transport+ name: Mobile native Swift testsneeds: changesif: needs.changes.outputs.mobile == 'true'- # Compiles the Foundation-only Swift transport, which needs Xcode's toolchain.+ # Compiles the Foundation-only Swift sources and their tests, which need Xcode's toolchain.runs-on: macos-latesttimeout-minutes: 15steps:@@ -109,6 +109,8 @@ jobs:persist-credentials: false- name: Run native provider transport testsrun: python3 openwhispr-mobile/modules/background-uploader/tests/run-provider-transport-tests.py+ - name: Run Live Activity resolver tests+ run: sh openwhispr-mobile/modules/live-activity/tests/run-resolver-tests.shmobile-status:name: Mobile CIdiff --git a/openwhispr-mobile/modules/live-activity/ios/EndMeetingIntent.swift b/openwhispr-mobile/modules/live-activity/ios/EndMeetingIntent.swiftnew file mode 100644index 000000000..e8f024697--- /dev/null+++ b/openwhispr-mobile/modules/live-activity/ios/EndMeetingIntent.swift@@ -0,0 +1,23 @@+import AppIntents+import Foundation++/// End button on the meeting Live Activity. Runs in the app's process+/// (LiveActivityIntent), which background audio keeps alive while a meeting records.+/// Compiled into both the app and the widget target, so it only posts the Darwin+/// notification; LiveActivityController does the work.+@available(iOS 17.0, *)+struct EndMeetingIntent: LiveActivityIntent {+ static var title: LocalizedStringResource = "End meeting recording"+ static var description = IntentDescription("Stops the OpenWhispr meeting recording.")+ // Only meaningful from the meeting card; keep it out of the Shortcuts app.+ static var isDiscoverable: Bool = false++ func perform() async throws -> some IntentResult {+ let bundleId = Bundle.main.bundleIdentifier ?? "com.gizmolabs.openwhispr"+ let name = "\(bundleId).endMeetingRequested" as CFString+ CFNotificationCenterPostNotification(+ CFNotificationCenterGetDarwinNotifyCenter(),+ CFNotificationName(name), nil, nil, true)+ return .result()+ }+}diff --git a/openwhispr-mobile/modules/live-activity/ios/LiveActivityController.swift b/openwhispr-mobile/modules/live-activity/ios/LiveActivityController.swiftindex 0ab81037c..fd402fb78 100644--- a/openwhispr-mobile/modules/live-activity/ios/LiveActivityController.swift+++ b/openwhispr-mobile/modules/live-activity/ios/LiveActivityController.swift@@ -6,11 +6,13 @@ import os.logimport ActivityKit#endif-/// Owns the session-scoped recording Live Activity. The activity exists while-/// "dictation mode" is enabled: started in a foreground window (the in-app toggle-/// or the keyboard cold-handoff), updated per dictation from the background, and-/// ended when dictation mode is turned off. All ActivityKit work is iOS 16.2+-/// guarded and dispatched to the main queue.+/// Owns the single recording Live Activity. Two sources share it: keyboard+/// "dictation mode" (updated from the background via Darwin notifications) and an+/// in-app meeting (driven from JS). Every trigger goes through LiveActivityResolver,+/// so a meeting always wins and hands the activity back when it ends. One activity+/// instead of two because `Activity.request` only succeeds in the foreground while+/// `update` works from the background, which is where a lock-screen End tap lands.+/// All state is main-queue only.final class LiveActivityController {static let shared = LiveActivityController()@@ -21,10 +23,23 @@ final class LiveActivityController {private var bundleId: String { Bundle.main.bundleIdentifier ?? "com.gizmolabs.openwhispr" }private var statusNotificationName: String { "\(bundleId).keyboardStatusChanged" }private var dictationModeNotificationName: String { "\(bundleId).dictationModeChanged" }+ private var endMeetingNotificationName: String { "\(bundleId).endMeetingRequested" }private var sharedDefaults: UserDefaults? { UserDefaults(suiteName: "group.\(bundleId)") }private var isObserving = falseprivate var foregroundObserverToken: NSObjectProtocol?+ /// Non-nil while MeetingRecordScreen has a meeting recording or processing.+ private var meeting: MeetingSnapshot?+ /// Held from a lock-screen End until the meeting clears, since background audio+ /// stops keeping the app alive once the mic stops.+ private var backgroundTask: UIBackgroundTaskIdentifier = .invalid+ private var endMeetingHandler: (() -> Void)?+ /// Tail of the ActivityKit operation queue. Independent Tasks per reconcile could+ /// land out of order (a lock-screen End's "Processing notes…" arriving after the+ /// hand-back to dictation would stick forever), so each operation resolves and+ /// applies only after the previous one finishes.+ private var opChain: Task<Void, Never>?+// MARK: - Dictation mode (the user-controlled gate)func isDictationModeEnabled() -> Bool {@@ -51,150 +66,276 @@ final class LiveActivityController {sharedDefaults?.string(forKey: "keyboard_recording_active") == "1"}- // MARK: - Observation (per-dictation background updates)+ // MARK: - Observation- /// Observe keyboard recording status changes to flip the activity's phase.- /// Same CFNotificationCenter Darwin pattern as AppGroupStorageModule.func startObserving() {- guard !isObserving else { return }- isObserving = true+ onMain {+ guard !self.isObserving else { return }+ self.isObserving = true- let center = CFNotificationCenterGetDarwinNotifyCenter()- let observer = Unmanaged.passUnretained(self).toOpaque()- CFNotificationCenterAddObserver(- center,- observer,- { (_, observer, _, _, _) in- guard let observer else { return }- let controller = Unmanaged<LiveActivityController>.fromOpaque(observer).takeUnretainedValue()- DispatchQueue.main.async { controller.handleKeyboardStatusChanged() }- },- statusNotificationName as CFString,- nil,- .deliverImmediately- )+ self.addDarwinObserver(self.statusNotificationName) { $0.reconcile() }+ self.addDarwinObserver(self.dictationModeNotificationName) { $0.reconcile() }+ self.addDarwinObserver(self.endMeetingNotificationName) { $0.handleEndMeetingRequested() }+ // Cold-handoff safety net: the URL handler can call startSession() while the+ // scene is still .inactive, so Activity.request fails. Re-attempt the start+ // the moment the app is genuinely foreground-active. Request-only: an existing+ // card showing the right mode and phase is left untouched so a running keyboard+ // timer isn't reset; a wrong one heals.+ self.foregroundObserverToken = NotificationCenter.default.addObserver(+ forName: UIApplication.didBecomeActiveNotification,+ object: nil,+ queue: .main+ ) { _ in+ // The controller is a process-lifetime singleton, like the Darwin boxes.+ self.reconcile(requestOnly: true)+ }+ self.log.info("Observing keyboard, dictation-mode, and end-meeting notifications")+ }+ }++ private func addDarwinObserver(+ _ name: String, handler: @escaping (LiveActivityController) -> Void+ ) {+ let box = Unmanaged.passRetained(DarwinHandlerBox(controller: self, handler: handler))CFNotificationCenterAddObserver(- center,- observer,+ CFNotificationCenterGetDarwinNotifyCenter(),+ box.toOpaque(),{ (_, observer, _, _, _) inguard let observer else { return }- let controller = Unmanaged<LiveActivityController>.fromOpaque(observer).takeUnretainedValue()- DispatchQueue.main.async { controller.handleDictationModeChanged() }+ let box = Unmanaged<DarwinHandlerBox>.fromOpaque(observer).takeUnretainedValue()+ DispatchQueue.main.async { box.handler(box.controller) }},- dictationModeNotificationName as CFString,+ name as CFString,nil,.deliverImmediately)- // Cold-handoff safety net: the URL handler can call startSession() while the- // scene is still .inactive, so Activity.request fails. Re-attempt the start- // the moment the app is genuinely foreground-active (idempotent — startOnMain- // no-ops if an activity already exists).- foregroundObserverToken = NotificationCenter.default.addObserver(- forName: UIApplication.didBecomeActiveNotification,- object: nil,- queue: .main- ) { [weak self] _ in- guard #available(iOS 16.2, *), let self else { return }- if self.isDictationModeEnabled() || self.isRecordingActive() { self.startOnMain() }- }- log.info("Observing keyboard recording status")- }-- private func handleKeyboardStatusChanged() {- DispatchQueue.main.async { [weak self] in- guard #available(iOS 16.2, *) else { return }- self?.updateOnMain()- }- }-- private func handleDictationModeChanged() {- DispatchQueue.main.async { [weak self] in- guard #available(iOS 16.2, *), let self else { return }- if self.isDictationModeEnabled() {- self.startOnMain()- } else {- LiveActivityController.endOnMain()+ }++ // MARK: - JS runtime lifecycle++ func setEndMeetingHandler(_ handler: @escaping () -> Void) {+ onMain { self.endMeetingHandler = handler }+ }++ /// The JS runtime just (re)started, so no meeting can exist yet. Anything left+ /// from before (dev reload, crash, background relaunch) is an orphan.+ func resetForNewJSRuntime() {+ onMain {+ self.meeting = nil+ self.endBackgroundWork()+ if self.isShowingMeeting() { self.reconcile() }+ }+ }++ // MARK: - Meeting (driven from MeetingRecordScreen)++ func startMeeting(title: String?, startedAt: Date) {+ onMain {+ // A task still held from the previous meeting's lock-screen End must not+ // leak into this one.+ self.endBackgroundWork()+ self.meeting = MeetingSnapshot(title: title, startedAt: startedAt, phase: .recording)+ self.reconcile()+ }+ }++ func setMeetingProcessing(recordedSeconds: Int) {+ onMain {+ guard let current = self.meeting else { return }+ self.meeting = MeetingSnapshot(+ title: current.title, startedAt: current.startedAt,+ phase: .processing(recordedSeconds: max(0, recordedSeconds)))+ self.reconcile()+ }+ }++ func endMeeting() {+ onMain {+ self.meeting = nil+ // Release the background task only once the hand-back has landed, and only+ // if it is still this meeting's: a newer meeting may have begun its own.+ let heldTask = self.backgroundTask+ self.reconcile {+ if self.backgroundTask == heldTask { self.endBackgroundWork() }}}}- // MARK: - Lifecycle+ private func handleEndMeetingRequested() {+ guard let current = meeting else {+ // Orphaned card (its meeting's process is gone): clear it.+ reconcile()+ return+ }+ guard case .recording = current.phase else { return }+ beginBackgroundWork()+ let recordedSeconds = max(0, Int(Date().timeIntervalSince(current.startedAt)))+ meeting = MeetingSnapshot(+ title: current.title, startedAt: current.startedAt,+ phase: .processing(recordedSeconds: recordedSeconds))+ reconcile()+ endMeetingHandler?()+ }- /// Start the session activity if dictation mode is on and none is running.- /// Must be called while the app is foreground (in-app toggle or cold-handoff).+ // MARK: - Session (keyboard handoff API)++ /// Start the session activity if the resolver says one should show and none is+ /// running (a running one is only corrected if its mode or phase is wrong). Must+ /// be called while the app is foreground.func startSession() {- DispatchQueue.main.async { [weak self] in- guard #available(iOS 16.2, *) else { return }- self?.startOnMain()- }+ onMain { self.reconcile(requestOnly: true) }}+ /// Ends the dictation session card. A meeting owns the card while it runs, so+ /// this is ignored until the meeting ends.func endSession() {- DispatchQueue.main.async {- guard #available(iOS 16.2, *) else { return }- LiveActivityController.endOnMain()+ onMain {+ guard self.meeting == nil else { return }+ self.endAll(completion: nil)}}- @available(iOS 16.2, *)- private func startOnMain() {+ // MARK: - Background work++ private func beginBackgroundWork() {+ guard backgroundTask == .invalid else { return }+ backgroundTask = UIApplication.shared.beginBackgroundTask(+ withName: "OpenWhisprMeetingFinish"+ ) { [weak self] in+ self?.endBackgroundWork()+ }+ }++ private func endBackgroundWork() {+ guard backgroundTask != .invalid else { return }+ UIApplication.shared.endBackgroundTask(backgroundTask)+ backgroundTask = .invalid+ }++ // MARK: - Resolve + apply++ private func onMain(_ work: @escaping () -> Void) {+ if Thread.isMainThread { work() } else { DispatchQueue.main.async(execute: work) }+ }++ /// Main only. The operation runs on the main actor once every earlier one is done.+ private func enqueue(_ operation: @escaping @MainActor () async -> Void) {+ let previous = opChain+ opChain = Task { @MainActor in+ await previous?.value+ await operation()+ }+ }++ /// Resolves when the operation runs, not when it is queued, so it acts on the+ /// latest state and on the activities left by the operations before it.+ private func reconcile(requestOnly: Bool = false, completion: (() -> Void)? = nil) {#if canImport(ActivityKit)- guard isDictationModeEnabled() || isRecordingActive() else {- log.info("Dictation mode off and not recording; skipping start")+ if #available(iOS 16.2, *) {+ enqueue {+ await self.reconcileActivity(requestOnly: requestOnly)+ completion?()+ }return}- guard ActivityAuthorizationInfo().areActivitiesEnabled else {- log.info("Live Activities disabled by the user; skipping")+ #endif+ completion?()+ }++ private func endAll(completion: (() -> Void)?) {+ #if canImport(ActivityKit)+ if #available(iOS 16.2, *) {+ enqueue {+ await self.endAllActivities()+ completion?()+ }return}- guard Activity<RecordingActivityAttributes>.activities.isEmpty else {- log.info("Session activity already running; skipping start")+ #endif+ completion?()+ }++ private func isShowingMeeting() -> Bool {+ #if canImport(ActivityKit)+ if #available(iOS 16.2, *) {+ return Activity<RecordingActivityAttributes>.activities.contains {+ $0.content.state.mode == .meeting+ }+ }+ #endif+ return false+ }++ #if canImport(ActivityKit)+ @available(iOS 16.2, *)+ @MainActor+ private func reconcileActivity(requestOnly: Bool) async {+ let now = Date()+ guard+ let state = LiveActivityResolver.resolve(+ meeting: meeting,+ keyboardRecording: isRecordingActive(),+ dictationMode: isDictationModeEnabled(),+ now: now)+ else {+ await endAllActivities()+ return+ }+ let content = ActivityContent(+ state: state, staleDate: LiveActivityResolver.staleDate(for: state, now: now))++ // Ended activities can linger in `.activities` on the lock screen (e.g. past+ // the 8-hour ActivityKit cap), so only a live one can be updated in place —+ // otherwise fall through and request a fresh activity.+ if let activity = Activity<RecordingActivityAttributes>.activities.first(where: {+ $0.activityState == .active || $0.activityState == .stale+ }) {+ // Only `startedAt` differs on a card already showing the right mode and phase,+ // and updating it would reset a running keyboard timer.+ let shown = activity.content.state+ if requestOnly && shown.mode == state.mode && shown.phase == state.phase { return }+ await activity.update(content)+ return+ }++ // `request` fails from the background anyway; .inactive still tries, since a+ // cold handoff calls startSession() before the scene becomes active.+ guard UIApplication.shared.applicationState != .background else {+ log.info("App is in the background; not requesting a Live Activity")+ return+ }+ guard ActivityAuthorizationInfo().areActivitiesEnabled else {+ log.info("Live Activities disabled by the user; skipping")return}- let isRecording = sharedDefaults?.string(forKey: "keyboard_recording_active") == "1"- let state = RecordingActivityAttributes.ContentState(- phase: isRecording ? .recording : .idle, startedAt: Date())do {_ = try Activity.request(- attributes: RecordingActivityAttributes(),- content: ActivityContent(state: state, staleDate: Date(timeIntervalSinceNow: 60 * 60)),- pushType: nil)- log.info("Session Live Activity started")+ attributes: RecordingActivityAttributes(), content: content, pushType: nil)+ log.info("Live Activity started (\(state.mode.rawValue, privacy: .public))")} catch {+ // Expected while the scene is still .inactive; the foreground observer retries.log.error("Failed to start Live Activity: \(error.localizedDescription, privacy: .public)")}- #endif}@available(iOS 16.2, *)- private func updateOnMain() {- #if canImport(ActivityKit)- let isRecording = isRecordingActive()- // A recording-only pill (dictation mode off) has nothing to show once the- // recording stops — end it instead of leaving an idle pill lingering. With- // dictation mode on, the session pill persists as idle between dictations.- if !isRecording && !isDictationModeEnabled() {- LiveActivityController.endOnMain()- return- }- guard let activity = Activity<RecordingActivityAttributes>.activities.first else { return }- let state = RecordingActivityAttributes.ContentState(- phase: isRecording ? .recording : .idle, startedAt: Date())- Task {- await activity.update(- ActivityContent(state: state, staleDate: Date(timeIntervalSinceNow: 60 * 60)))+ @MainActor+ private func endAllActivities() async {+ for activity in Activity<RecordingActivityAttributes>.activities {+ await activity.end(nil, dismissalPolicy: .immediate)}- #endif}+ #endif+}- @available(iOS 16.2, *)- private static func endOnMain() {- #if canImport(ActivityKit)- Task {- for activity in Activity<RecordingActivityAttributes>.activities {- await activity.end(nil, dismissalPolicy: .immediate)- }- }- #endif+/// Carries a Darwin observer's handler through the C callback's context pointer.+/// Retained for the process lifetime, like the controller singleton itself.+private final class DarwinHandlerBox {+ let controller: LiveActivityController+ let handler: (LiveActivityController) -> Void++ init(controller: LiveActivityController, handler: @escaping (LiveActivityController) -> Void) {+ self.controller = controller+ self.handler = handler}}diff --git a/openwhispr-mobile/modules/live-activity/ios/LiveActivityModule.swift b/openwhispr-mobile/modules/live-activity/ios/LiveActivityModule.swiftindex 0e9ebcc60..850ebd503 100644--- a/openwhispr-mobile/modules/live-activity/ios/LiveActivityModule.swift+++ b/openwhispr-mobile/modules/live-activity/ios/LiveActivityModule.swift@@ -5,8 +5,15 @@ public class LiveActivityModule: Module {public func definition() -> ModuleDefinition {Name("LiveActivity")- OnCreate {- LiveActivityController.shared.startObserving()+ Events("onEndMeetingRequested")++ OnCreate { [weak self] in+ let controller = LiveActivityController.shared+ controller.setEndMeetingHandler { [weak self] in+ self?.sendEvent("onEndMeetingRequested", [:])+ }+ controller.startObserving()+ controller.resetForNewJSRuntime()}Function("startSession") {@@ -24,5 +31,18 @@ public class LiveActivityModule: Module {Function("isDictationModeEnabled") { () -> Bool inLiveActivityController.shared.isDictationModeEnabled()}++ Function("startMeeting") { (title: String?, startedAtMs: Double) in+ LiveActivityController.shared.startMeeting(+ title: title, startedAt: Date(timeIntervalSince1970: startedAtMs / 1000))+ }++ Function("setMeetingProcessing") { (recordedSeconds: Int) in+ LiveActivityController.shared.setMeetingProcessing(recordedSeconds: recordedSeconds)+ }++ Function("endMeeting") {+ LiveActivityController.shared.endMeeting()+ }}}diff --git a/openwhispr-mobile/modules/live-activity/ios/LiveActivityResolver.swift b/openwhispr-mobile/modules/live-activity/ios/LiveActivityResolver.swiftnew file mode 100644index 000000000..5e0a17473--- /dev/null+++ b/openwhispr-mobile/modules/live-activity/ios/LiveActivityResolver.swift@@ -0,0 +1,58 @@+import Foundation++/// The in-app meeting as the controller tracks it.+public struct MeetingSnapshot: Equatable {+ public enum Phase: Equatable {+ case recording+ case processing(recordedSeconds: Int)+ }++ public var title: String?+ public var startedAt: Date+ public var phase: Phase++ public init(title: String?, startedAt: Date, phase: Phase) {+ self.title = title+ self.startedAt = startedAt+ self.phase = phase+ }+}++/// Decides what the single recording Live Activity shows. A meeting always wins so+/// keyboard/dictation-mode events can never overwrite or end it mid-meeting; when the+/// meeting clears, the activity falls back to the dictation session (or ends).+public enum LiveActivityResolver {+ public static func resolve(+ meeting: MeetingSnapshot?,+ keyboardRecording: Bool,+ dictationMode: Bool,+ now: Date+ ) -> RecordingActivityContentState? {+ if let meeting {+ switch meeting.phase {+ case .recording:+ return RecordingActivityContentState(+ mode: .meeting, phase: .recording, startedAt: meeting.startedAt, title: meeting.title)+ case .processing(let recordedSeconds):+ return RecordingActivityContentState(+ mode: .meeting, phase: .processing, startedAt: meeting.startedAt, title: meeting.title,+ recordedSeconds: recordedSeconds)+ }+ }+ if keyboardRecording {+ return RecordingActivityContentState(phase: .recording, startedAt: now)+ }+ if dictationMode {+ return RecordingActivityContentState(phase: .idle, startedAt: now)+ }+ return nil+ }++ /// Without push updates the stale date can never move later, so a meeting is+ /// stale only at ActivityKit's cap.+ public static func staleDate(for state: RecordingActivityContentState, now: Date) -> Date {+ state.mode == .meeting+ ? state.startedAt.addingTimeInterval(RecordingActivityContentState.maxActivityDuration)+ : now.addingTimeInterval(60 * 60)+ }+}diff --git a/openwhispr-mobile/modules/live-activity/ios/RecordingActivityAttributes.swift b/openwhispr-mobile/modules/live-activity/ios/RecordingActivityAttributes.swiftindex 90ed715de..0b5a10ef1 100644--- a/openwhispr-mobile/modules/live-activity/ios/RecordingActivityAttributes.swift+++ b/openwhispr-mobile/modules/live-activity/ios/RecordingActivityAttributes.swift@@ -3,25 +3,12 @@ import ActivityKitimport Foundation/// Shared contract between the app (requests/updates the activity) and the widget-/// extension (renders it). The activity is session-scoped: `ContentState.phase`-/// flips between recording and idle across the session; `startedAt` drives the-/// self-counting timer for the current recording.+/// extension (renders it). The state lives in RecordingActivityContentState.swift+/// (Foundation-only, unit-tested); these aliases keep existing call sites compiling.@available(iOS 16.1, *)public struct RecordingActivityAttributes: ActivityAttributes {- public enum Phase: String, Codable, Hashable {- case recording- case idle- }-- public struct ContentState: Codable, Hashable {- public var phase: Phase- public var startedAt: Date-- public init(phase: Phase, startedAt: Date) {- self.phase = phase- self.startedAt = startedAt- }- }+ public typealias ContentState = RecordingActivityContentState+ public typealias Phase = RecordingActivityPhasepublic init() {}}diff --git a/openwhispr-mobile/modules/live-activity/ios/RecordingActivityContentState.swift b/openwhispr-mobile/modules/live-activity/ios/RecordingActivityContentState.swiftnew file mode 100644index 000000000..ddb82a4ab--- /dev/null+++ b/openwhispr-mobile/modules/live-activity/ios/RecordingActivityContentState.swift@@ -0,0 +1,69 @@+import Foundation++/// Which recording owns the single Live Activity.+public enum RecordingActivityMode: String, Codable, Hashable {+ case dictation+ case meeting+}++/// `idle` is dictation-only (session up, not recording); `processing` is meeting-only.+public enum RecordingActivityPhase: String, Codable, Hashable {+ case recording+ case idle+ case processing+}++/// Foundation-only so the resolver tests can compile it with plain `swiftc` on macOS;+/// `RecordingActivityAttributes` (ActivityKit) aliases it as its `ContentState`.+public struct RecordingActivityContentState: Codable, Hashable {+ /// ActivityKit ends every Live Activity 8 hours after it starts.+ public static let maxActivityDuration: TimeInterval = 8 * 60 * 60++ public var mode: RecordingActivityMode+ public var phase: RecordingActivityPhase+ public var startedAt: Date+ public var title: String?+ public var recordedSeconds: Int?++ public init(+ mode: RecordingActivityMode = .dictation,+ phase: RecordingActivityPhase,+ startedAt: Date,+ title: String? = nil,+ recordedSeconds: Int? = nil+ ) {+ self.mode = mode+ self.phase = phase+ self.startedAt = startedAt+ self.title = title+ self.recordedSeconds = recordedSeconds+ }++ // An activity started by a build that predates meetings carries only+ // `phase` + `startedAt`; it must keep decoding after an app update.+ public init(from decoder: Decoder) throws {+ let container = try decoder.container(keyedBy: CodingKeys.self)+ mode = try container.decodeIfPresent(RecordingActivityMode.self, forKey: .mode) ?? .dictation+ phase = try container.decode(RecordingActivityPhase.self, forKey: .phase)+ startedAt = try container.decode(Date.self, forKey: .startedAt)+ title = try container.decodeIfPresent(String.self, forKey: .title)+ recordedSeconds = try container.decodeIfPresent(Int.self, forKey: .recordedSeconds)+ }++ /// Meeting card headline.+ public var displayTitle: String {+ if phase == .processing { return "Processing notes…" }+ return title ?? "Taking notes…"+ }++ /// "42:10" or "1:02:03".+ public var recordedDurationLabel: String {+ let total = max(0, recordedSeconds ?? 0)+ let hours = total / 3600+ let minutes = (total % 3600) / 60+ let seconds = total % 60+ return hours > 0+ ? String(format: "%d:%02d:%02d", hours, minutes, seconds)+ : String(format: "%d:%02d", minutes, seconds)+ }+}diff --git a/openwhispr-mobile/modules/live-activity/src/__tests__/index.test.ts b/openwhispr-mobile/modules/live-activity/src/__tests__/index.test.tsnew file mode 100644index 000000000..6bcf4faa6--- /dev/null+++ b/openwhispr-mobile/modules/live-activity/src/__tests__/index.test.ts@@ -0,0 +1,103 @@+const mockNative = {+ startSession: jest.fn(),+ endSession: jest.fn(),+ setDictationMode: jest.fn(),+ isDictationModeEnabled: jest.fn(() => true),+ startMeeting: jest.fn(),+ setMeetingProcessing: jest.fn(),+ endMeeting: jest.fn(),+};+const mockRemove = jest.fn();+const mockAddListener = jest.fn((_event: string, _listener: () => void) => ({+ remove: mockRemove,+}));+let mockPlatformOS = 'ios';++jest.mock('expo', () => ({+ requireNativeModule: jest.fn(() => mockNative),+ EventEmitter: jest.fn().mockImplementation(() => ({ addListener: mockAddListener })),+}));+jest.mock('react-native', () => ({+ Platform: {+ get OS() {+ return mockPlatformOS;+ },+ },+}));++type Wrapper = typeof import('../index');++function load(os: 'ios' | 'android'): Wrapper {+ mockPlatformOS = os;+ let loaded: Wrapper | undefined;+ jest.isolateModules(() => {+ loaded = jest.requireActual<Wrapper>('../index');+ });+ return loaded as Wrapper;+}++beforeEach(() => {+ jest.clearAllMocks();+});++describe('LiveActivity meeting API on iOS', () => {+ it('passes the trimmed title and epoch-ms start to the native module', () => {+ const { LiveActivity } = load('ios');+ LiveActivity.startMeeting({ title: ' Weekly sync ', startedAt: 1_700_000_000_000 });+ expect(mockNative.startMeeting).toHaveBeenCalledWith('Weekly sync', 1_700_000_000_000);+ });++ it('normalizes a blank title to null', () => {+ const { LiveActivity, normalizeMeetingTitle } = load('ios');+ expect(normalizeMeetingTitle(' ')).toBeNull();+ expect(normalizeMeetingTitle(undefined)).toBeNull();+ LiveActivity.startMeeting({ title: ' ', startedAt: 5 });+ expect(mockNative.startMeeting).toHaveBeenCalledWith(null, 5);+ });++ it('caps a long title at 200 characters with an ellipsis', () => {+ const { normalizeMeetingTitle } = load('ios');+ const exact = 'a'.repeat(200);+ expect(normalizeMeetingTitle(exact)).toBe(exact);+ const capped = normalizeMeetingTitle(` ${'b'.repeat(500)} `);+ expect(capped).toHaveLength(200);+ expect(capped).toBe(`${'b'.repeat(199)}…`);+ expect(normalizeMeetingTitle('😀'.repeat(300))).toBe(`${'😀'.repeat(199)}…`);+ });++ it('floors and clamps recorded seconds', () => {+ const { LiveActivity } = load('ios');+ LiveActivity.setMeetingProcessing({ recordedSeconds: 42.9 });+ LiveActivity.setMeetingProcessing({ recordedSeconds: -3 });+ expect(mockNative.setMeetingProcessing).toHaveBeenNthCalledWith(1, 42);+ expect(mockNative.setMeetingProcessing).toHaveBeenNthCalledWith(2, 0);+ });++ it('forwards endMeeting', () => {+ const { LiveActivity } = load('ios');+ LiveActivity.endMeeting();+ expect(mockNative.endMeeting).toHaveBeenCalledTimes(1);+ });++ it('subscribes to onEndMeetingRequested', () => {+ const { LiveActivity } = load('ios');+ const listener = jest.fn();+ const subscription = LiveActivity.addEndMeetingListener(listener);+ expect(mockAddListener).toHaveBeenCalledWith('onEndMeetingRequested', listener);+ subscription.remove();+ expect(mockRemove).toHaveBeenCalledTimes(1);+ });+});++describe('LiveActivity meeting API off iOS', () => {+ it('is a no-op and returns an inert subscription', () => {+ const { LiveActivity } = load('android');+ LiveActivity.startMeeting({ title: 'x', startedAt: 1 });+ LiveActivity.setMeetingProcessing({ recordedSeconds: 1 });+ LiveActivity.endMeeting();+ const subscription = LiveActivity.addEndMeetingListener(jest.fn());+ expect(() => subscription.remove()).not.toThrow();+ expect(mockNative.startMeeting).not.toHaveBeenCalled();+ expect(mockAddListener).not.toHaveBeenCalled();+ });+});diff --git a/openwhispr-mobile/modules/live-activity/src/index.ts b/openwhispr-mobile/modules/live-activity/src/index.tsindex 3e91c6056..9577b46d0 100644--- a/openwhispr-mobile/modules/live-activity/src/index.ts+++ b/openwhispr-mobile/modules/live-activity/src/index.ts@@ -1,23 +1,58 @@-import { requireNativeModule } from 'expo';+import { EventEmitter, requireNativeModule } from 'expo';import { Platform } from 'react-native';+type EventSubscription = {+ remove(): void;+};+interface LiveActivityNativeModule {startSession(): void;endSession(): void;setDictationMode(enabled: boolean): void;isDictationModeEnabled(): boolean;+ startMeeting(title: string | null, startedAtMs: number): void;+ setMeetingProcessing(recordedSeconds: number): void;+ endMeeting(): void;}+type LiveActivityEvents = {+ onEndMeetingRequested: () => void;+};+const NativeModule: LiveActivityNativeModule | null =Platform.OS === 'ios' ? requireNativeModule('LiveActivity') : null;+const NativeModuleEvents = NativeModule+ ? new EventEmitter<LiveActivityEvents>(NativeModule as any)+ : null;++const INERT_SUBSCRIPTION: EventSubscription = { remove: () => {} };++// ActivityKit caps the whole content state at 4 KB; a pasted calendar title must+// not push the card past it.+const MAX_MEETING_TITLE_LENGTH = 200;++/** A blank calendar title renders the default "Taking notes…" headline. */+export function normalizeMeetingTitle(title: string | null | undefined): string | null {+ const trimmed = title?.trim();+ if (!trimmed) return null;+ // Code points, so the cut never splits an emoji's surrogate pair.+ const chars = Array.from(trimmed);+ return chars.length > MAX_MEETING_TITLE_LENGTH+ ? `${chars+ .slice(0, MAX_MEETING_TITLE_LENGTH - 1)+ .join('')+ .trimEnd()}…`+ : trimmed;+}+export const LiveActivity = {/** Start the session Live Activity (no-op unless dictation mode is on, app is* foreground, iOS 16.2+, and none is already running). */startSession(): void {NativeModule?.startSession();},- /** End the session Live Activity immediately. */+ /** End the session Live Activity immediately. Ignored while a meeting owns it. */endSession(): void {NativeModule?.endSession();},@@ -30,4 +65,21 @@ export const LiveActivity = {isDictationModeEnabled(): boolean {return NativeModule?.isDictationModeEnabled() ?? false;},+ /** Show the meeting card. Must be called while the app is foreground (the+ * meeting screen), since iOS only starts Live Activities from the foreground. */+ startMeeting({ title, startedAt }: { title: string | null; startedAt: number }): void {+ NativeModule?.startMeeting(normalizeMeetingTitle(title), startedAt);+ },+ /** Switch the meeting card to "Processing notes…". */+ setMeetingProcessing({ recordedSeconds }: { recordedSeconds: number }): void {+ NativeModule?.setMeetingProcessing(Math.max(0, Math.floor(recordedSeconds)));+ },+ /** Release the card back to the dictation session, or end it. */+ endMeeting(): void {+ NativeModule?.endMeeting();+ },+ /** Fires when the user taps End on the lock screen / Dynamic Island. */+ addEndMeetingListener(listener: () => void): EventSubscription {+ return NativeModuleEvents?.addListener('onEndMeetingRequested', listener) ?? INERT_SUBSCRIPTION;+ },};diff --git a/openwhispr-mobile/modules/live-activity/tests/LiveActivityResolverTests.swift b/openwhispr-mobile/modules/live-activity/tests/LiveActivityResolverTests.swiftnew file mode 100644index 000000000..d70a4e728--- /dev/null+++ b/openwhispr-mobile/modules/live-activity/tests/LiveActivityResolverTests.swift@@ -0,0 +1,107 @@+import Foundation++@main+struct LiveActivityResolverTests {+ static var failures = 0++ static func check(_ condition: Bool, _ message: String, line: Int = #line) {+ if !condition {+ failures += 1+ print("FAIL (line \(line)): \(message)")+ }+ }++ static func main() throws {+ let now = Date(timeIntervalSince1970: 1_000_000)+ let start = Date(timeIntervalSince1970: 999_000)+ let recording = MeetingSnapshot(title: "Weekly sync", startedAt: start, phase: .recording)+ let processing = MeetingSnapshot(+ title: nil, startedAt: start, phase: .processing(recordedSeconds: 2530))++ // A meeting wins over every keyboard/dictation combination.+ for keyboard in [false, true] {+ for dictation in [false, true] {+ check(+ LiveActivityResolver.resolve(+ meeting: recording, keyboardRecording: keyboard, dictationMode: dictation, now: now)+ == RecordingActivityContentState(+ mode: .meeting, phase: .recording, startedAt: start, title: "Weekly sync"),+ "recording meeting wins (keyboard=\(keyboard), dictation=\(dictation))")+ check(+ LiveActivityResolver.resolve(+ meeting: processing, keyboardRecording: keyboard, dictationMode: dictation, now: now)+ == RecordingActivityContentState(+ mode: .meeting, phase: .processing, startedAt: start, recordedSeconds: 2530),+ "processing meeting wins (keyboard=\(keyboard), dictation=\(dictation))")+ }+ }++ // Without a meeting: keyboard recording > dictation idle > nothing.+ let keyboardOnly = RecordingActivityContentState(phase: .recording, startedAt: now)+ check(+ LiveActivityResolver.resolve(meeting: nil, keyboardRecording: true, dictationMode: false, now: now)+ == keyboardOnly, "keyboard recording without dictation mode")+ check(+ LiveActivityResolver.resolve(meeting: nil, keyboardRecording: true, dictationMode: true, now: now)+ == keyboardOnly, "keyboard recording with dictation mode")+ check(+ LiveActivityResolver.resolve(meeting: nil, keyboardRecording: false, dictationMode: true, now: now)+ == RecordingActivityContentState(phase: .idle, startedAt: now), "dictation idle")+ check(+ LiveActivityResolver.resolve(meeting: nil, keyboardRecording: false, dictationMode: false, now: now)+ == nil, "nothing to show ends the activity")++ // Stale dates.+ let meetingState = RecordingActivityContentState(+ mode: .meeting, phase: .recording, startedAt: start)+ check(+ LiveActivityResolver.staleDate(for: meetingState, now: now)+ == start.addingTimeInterval(8 * 60 * 60), "meeting stale date is startedAt + 8h")+ check(+ LiveActivityResolver.staleDate(for: keyboardOnly, now: now)+ == now.addingTimeInterval(60 * 60), "dictation stale date is now + 1h")++ // Display copy.+ check(+ RecordingActivityContentState(mode: .meeting, phase: .recording, startedAt: start).displayTitle+ == "Taking notes…", "untitled meeting")+ check(+ RecordingActivityContentState(+ mode: .meeting, phase: .recording, startedAt: start, title: "Weekly sync"+ ).displayTitle == "Weekly sync", "titled meeting")+ check(+ RecordingActivityContentState(+ mode: .meeting, phase: .processing, startedAt: start, title: "Weekly sync"+ ).displayTitle == "Processing notes…", "processing title")+ let label = { (seconds: Int?) in+ RecordingActivityContentState(+ mode: .meeting, phase: .processing, startedAt: start, recordedSeconds: seconds+ ).recordedDurationLabel+ }+ check(label(2530) == "42:10", "m:ss label")+ check(label(5) == "0:05", "sub-minute label")+ check(label(3723) == "1:02:03", "h:mm:ss label")+ check(label(nil) == "0:00", "missing duration label")+ check(label(-4) == "0:00", "negative duration clamps")++ // A legacy payload (pre-meeting build) still decodes as dictation.+ let legacy = Data(#"{"phase":"idle","startedAt":0}"#.utf8)+ let decoded = try JSONDecoder().decode(RecordingActivityContentState.self, from: legacy)+ check(+ decoded.mode == .dictation && decoded.phase == .idle && decoded.title == nil+ && decoded.recordedSeconds == nil, "legacy payload decodes as dictation")++ // Round trip keeps every field.+ let full = RecordingActivityContentState(+ mode: .meeting, phase: .processing, startedAt: start, title: "Sync", recordedSeconds: 61)+ let roundTripped = try JSONDecoder().decode(+ RecordingActivityContentState.self, from: JSONEncoder().encode(full))+ check(roundTripped == full, "round trip")++ if failures > 0 {+ print("\(failures) failure(s)")+ exit(1)+ }+ print("All live-activity resolver tests passed")+ }+}diff --git a/openwhispr-mobile/modules/live-activity/tests/run-resolver-tests.sh b/openwhispr-mobile/modules/live-activity/tests/run-resolver-tests.shnew file mode 100755index 000000000..36dbaabdf--- /dev/null+++ b/openwhispr-mobile/modules/live-activity/tests/run-resolver-tests.sh@@ -0,0 +1,12 @@+#!/bin/sh+# Compiles the Foundation-only Live Activity sources with the test executable and runs it.+# ActivityKit is iOS-only, so only the pure files are compiled here.+set -eu+MODULE_DIR="$(cd "$(dirname "$0")/.." && pwd)"+OUT_DIR="$(mktemp -d)"+trap 'rm -rf "$OUT_DIR"' EXIT+swiftc -swift-version 5 -o "$OUT_DIR/tests" \+ "$MODULE_DIR/ios/RecordingActivityContentState.swift" \+ "$MODULE_DIR/ios/LiveActivityResolver.swift" \+ "$MODULE_DIR/tests/LiveActivityResolverTests.swift"+"$OUT_DIR/tests"diff --git a/openwhispr-mobile/plugins/activity-extension/ios/OpenWhisprActivity.swift b/openwhispr-mobile/plugins/activity-extension/ios/OpenWhisprActivity.swiftindex 8e538721c..e4fb158b3 100644--- a/openwhispr-mobile/plugins/activity-extension/ios/OpenWhisprActivity.swift+++ b/openwhispr-mobile/plugins/activity-extension/ios/OpenWhisprActivity.swift@@ -3,6 +3,12 @@ import AppIntentsimport WidgetKitimport SwiftUI+private let recordingRed = Color(red: 1.0, green: 0.27, blue: 0.23)+private let brandBlue = Color(red: 0.141, green: 0.341, blue: 0.839)+// Timer text reserves the width of the widest value in its range, and a meeting+// activity never outlives ActivityKit's cap, so it never needs "23:59:59".+private let meetingTimerSpan = RecordingActivityContentState.maxActivityDuration+// MARK: - Brand markstruct BrandMark: View {@@ -52,15 +58,24 @@ struct BrandBadge: View {struct ElapsedText: View {let startedAt: Datevar color: Color = .white+ var span: TimeInterval = 60 * 60 * 24var body: some View {- Text(timerInterval: startedAt...startedAt.addingTimeInterval(60 * 60 * 24), countsDown: false)+ Text(timerInterval: startedAt...startedAt.addingTimeInterval(span), countsDown: false).monospacedDigit().font(.system(size: 15, weight: .semibold)).foregroundColor(color)}}+struct RecordingDot: View {+ var size: CGFloat = 7++ var body: some View {+ Circle().fill(recordingRed).frame(width: size, height: size)+ }+}+// MARK: - Power button (turn dictation mode off)struct PowerButton: View {@@ -86,6 +101,26 @@ struct PowerButton: View {}}+// MARK: - End button (stop the meeting recording)++/// Same translucent material as PowerButton. Omitted before iOS 17, where+/// `Button(intent:)` doesn't exist; tapping the card still opens the app.+struct EndButton: View {+ var body: some View {+ if #available(iOS 17.0, *) {+ Button(intent: EndMeetingIntent()) {+ Text("End")+ .font(.system(size: 15, weight: .semibold))+ .foregroundColor(.white)+ .padding(.horizontal, 18)+ .padding(.vertical, 8)+ .background(Capsule().fill(Color.white.opacity(0.16)))+ }+ .buttonStyle(.plain)+ }+ }+}+// MARK: - Lock screen / bannerstruct RecordingLockScreenView: View {@@ -100,9 +135,7 @@ struct RecordingLockScreenView: View {.foregroundColor(.white)if state.phase == .recording {HStack(spacing: 5) {- Circle()- .fill(Color(red: 1.0, green: 0.27, blue: 0.23))- .frame(width: 7, height: 7)+ RecordingDot()Text("Recording").font(.system(size: 13)).foregroundColor(.white.opacity(0.6))@@ -124,6 +157,53 @@ struct RecordingLockScreenView: View {}}+struct MeetingLockScreenView: View {+ let state: RecordingActivityAttributes.ContentState++ var body: some View {+ HStack(spacing: 12) {+ BrandBadge(size: 40)+ VStack(alignment: .leading, spacing: 2) {+ Text(state.displayTitle)+ .font(.system(size: 15, weight: .semibold))+ .foregroundColor(.white)+ .lineLimit(1)+ MeetingSubtitle(state: state, size: 13)+ }+ Spacer(minLength: 8)+ if state.phase == .recording {+ EndButton()+ }+ }+ .padding(.horizontal, 16)+ .padding(.vertical, 12)+ }+}++struct MeetingSubtitle: View {+ let state: RecordingActivityAttributes.ContentState+ var size: CGFloat++ var body: some View {+ if state.phase == .processing {+ Text("Recorded \(state.recordedDurationLabel)")+ .font(.system(size: size))+ .foregroundColor(.white.opacity(0.6))+ } else {+ HStack(spacing: 5) {+ RecordingDot(size: size * 0.54)+ (Text("Recording · ")+ + Text(+ timerInterval: state.startedAt...state.startedAt.addingTimeInterval(meetingTimerSpan),+ countsDown: false))+ .monospacedDigit()+ .font(.system(size: size))+ .foregroundColor(.white.opacity(0.6))+ }+ }+ }+}+// MARK: - Widget@main@@ -136,47 +216,100 @@ struct OpenWhisprActivityBundle: WidgetBundle {struct RecordingLiveActivity: Widget {var body: some WidgetConfiguration {ActivityConfiguration(for: RecordingActivityAttributes.self) { context in- RecordingLockScreenView(state: context.state)- .activityBackgroundTint(Color.black.opacity(0.6))- .activitySystemActionForegroundColor(.white)+ Group {+ if context.state.mode == .meeting {+ MeetingLockScreenView(state: context.state)+ } else {+ RecordingLockScreenView(state: context.state)+ }+ }+ .activityBackgroundTint(Color.black.opacity(0.6))+ .activitySystemActionForegroundColor(.white)} dynamicIsland: { context in- DynamicIsland {- DynamicIslandExpandedRegion(.leading) {- HStack(spacing: 10) {- BrandBadge(size: 34)- VStack(alignment: .leading, spacing: 1) {- Text("OpenWhispr")- .font(.system(size: 14, weight: .semibold))- .foregroundColor(.white)- .lineLimit(1)- .minimumScaleFactor(0.7)- Text(context.state.phase == .recording ? "Recording" : "Active")- .font(.system(size: 12))- .foregroundColor(.white.opacity(0.6))- .lineLimit(1)- .minimumScaleFactor(0.7)- }+ if context.state.mode == .meeting {+ return meetingIsland(context.state)+ }+ return dictationIsland(context.state)+ }+ }++ private func dictationIsland(_ state: RecordingActivityAttributes.ContentState) -> DynamicIsland {+ DynamicIsland {+ DynamicIslandExpandedRegion(.leading) {+ HStack(spacing: 10) {+ BrandBadge(size: 34)+ VStack(alignment: .leading, spacing: 1) {+ Text("OpenWhispr")+ .font(.system(size: 14, weight: .semibold))+ .foregroundColor(.white)+ .lineLimit(1)+ .minimumScaleFactor(0.7)+ Text(state.phase == .recording ? "Recording" : "Active")+ .font(.system(size: 12))+ .foregroundColor(.white.opacity(0.6))+ .lineLimit(1)+ .minimumScaleFactor(0.7)+ }+ }+ }+ DynamicIslandExpandedRegion(.trailing) {+ HStack(spacing: 8) {+ if state.phase == .recording {+ ElapsedText(startedAt: state.startedAt, color: .white.opacity(0.7))}+ PowerButton(size: 30)}- DynamicIslandExpandedRegion(.trailing) {- HStack(spacing: 8) {- if context.state.phase == .recording {- ElapsedText(startedAt: context.state.startedAt, color: .white.opacity(0.7))- }- PowerButton(size: 30)+ }+ } compactLeading: {+ BrandBadge(size: 22)+ } compactTrailing: {+ if state.phase == .recording {+ ElapsedText(startedAt: state.startedAt)+ .frame(maxWidth: 44)+ }+ } minimal: {+ BrandBadge(size: 22)+ }+ .keylineTint(brandBlue)+ }++ private func meetingIsland(_ state: RecordingActivityAttributes.ContentState) -> DynamicIsland {+ DynamicIsland {+ DynamicIslandExpandedRegion(.leading) {+ HStack(spacing: 10) {+ BrandBadge(size: 34)+ VStack(alignment: .leading, spacing: 1) {+ Text(state.displayTitle)+ .font(.system(size: 14, weight: .semibold))+ .foregroundColor(.white)+ .lineLimit(1)+ .minimumScaleFactor(0.7)+ MeetingSubtitle(state: state, size: 12)}}- } compactLeading: {- BrandBadge(size: 22)- } compactTrailing: {- if context.state.phase == .recording {- ElapsedText(startedAt: context.state.startedAt)- .frame(maxWidth: 44)+ }+ DynamicIslandExpandedRegion(.trailing) {+ if state.phase == .recording {+ EndButton()}- } minimal: {- BrandBadge(size: 22)}- .keylineTint(Color(red: 0.141, green: 0.341, blue: 0.839))+ } compactLeading: {+ BrandBadge(size: 22)+ } compactTrailing: {+ if state.phase == .recording {+ // Meetings run past an hour, and "1:02:03" is wider than the 44 pt slot.+ ElapsedText(startedAt: state.startedAt, color: recordingRed, span: meetingTimerSpan)+ .lineLimit(1)+ .minimumScaleFactor(0.6)+ .frame(maxWidth: 44)+ } else {+ Image(systemName: "waveform")+ .font(.system(size: 12, weight: .semibold))+ .foregroundColor(.white.opacity(0.6))+ }+ } minimal: {+ BrandBadge(size: 22)}+ .keylineTint(brandBlue)}}diff --git a/openwhispr-mobile/plugins/activity-extension/withActivityExtension.js b/openwhispr-mobile/plugins/activity-extension/withActivityExtension.jsindex 72aabcd29..92905c50b 100644--- a/openwhispr-mobile/plugins/activity-extension/withActivityExtension.js+++ b/openwhispr-mobile/plugins/activity-extension/withActivityExtension.js@@ -15,31 +15,23 @@ const {const EXTENSION_NAME = 'OpenWhisprActivity';const EXTENSION_BUNDLE_ID_SUFFIX = 'activity';const DEPLOYMENT_TARGET = '16.2';-// Swift sources compiled into the widget target. RecordingActivityAttributes.swift-// is copied from the live-activity module so there is a single source of truth.+// Swift sources compiled into the widget target. Everything except+// OpenWhisprActivity.swift is copied from the live-activity module so there is a+// single source of truth.const TARGET_SOURCES = ['OpenWhisprActivity.swift','RecordingActivityAttributes.swift',+ 'RecordingActivityContentState.swift','ToggleDictationModeIntent.swift',+ 'EndMeetingIntent.swift',];-const ATTRIBUTES_SOURCE = path.join(- __dirname,- '..',- '..',- 'modules',- 'live-activity',- 'ios',+const MODULE_IOS_DIR = path.join(__dirname, '..', '..', 'modules', 'live-activity', 'ios');+const SHARED_MODULE_SOURCES = ['RecordingActivityAttributes.swift',-);-const INTENT_SOURCE = path.join(- __dirname,- '..',- '..',- 'modules',- 'live-activity',- 'ios',+ 'RecordingActivityContentState.swift','ToggleDictationModeIntent.swift',-);+ 'EndMeetingIntent.swift',+];function resolveActivityEnvironment(cfg) {const configured = cfg.extra?.openWhispr ?? resolveOpenWhisprEnvironment();@@ -78,10 +70,10 @@ function writeExtensionSupportFiles(platformProjectRoot, environment) {path.join(pluginSourceDir, 'OpenWhisprActivity.swift'),path.join(extensionDir, 'OpenWhisprActivity.swift'),);- // Single source of truth: copy the attributes file from the module.- fs.copyFileSync(ATTRIBUTES_SOURCE, path.join(extensionDir, 'RecordingActivityAttributes.swift'));- // Single source of truth: copy the LiveActivityIntent from the module.- fs.copyFileSync(INTENT_SOURCE, path.join(extensionDir, 'ToggleDictationModeIntent.swift'));+ // Single source of truth: the shared state, attributes, and intents live in the module.+ for (const fileName of SHARED_MODULE_SOURCES) {+ fs.copyFileSync(path.join(MODULE_IOS_DIR, fileName), path.join(extensionDir, fileName));+ }const infoPlist = readPlist(path.join(pluginSourceDir, 'Info.plist'));writePlist(path.join(extensionDir, 'Info.plist'), infoPlist);diff --git a/openwhispr-mobile/src/hooks/__tests__/useMeetingLiveActivity.test.ts b/openwhispr-mobile/src/hooks/__tests__/useMeetingLiveActivity.test.tsnew file mode 100644index 000000000..6828081be--- /dev/null+++ b/openwhispr-mobile/src/hooks/__tests__/useMeetingLiveActivity.test.ts@@ -0,0 +1,169 @@+import { renderHook, type RenderHookResult } from '@testing-library/react-native';+import { useMeetingLiveActivity, type MeetingActivityPhase } from '@/hooks/useMeetingLiveActivity';++const mockStartMeeting = jest.fn();+const mockSetMeetingProcessing = jest.fn();+const mockEndMeeting = jest.fn();+const mockRemove = jest.fn();+let mockEndListener: (() => void) | undefined;++jest.mock('../../../modules/live-activity/src', () => ({+ LiveActivity: {+ startMeeting: (input: unknown) => mockStartMeeting(input),+ setMeetingProcessing: (input: unknown) => mockSetMeetingProcessing(input),+ endMeeting: () => mockEndMeeting(),+ addEndMeetingListener: (listener: () => void) => {+ mockEndListener = listener;+ return { remove: mockRemove };+ },+ },+}));++type Props = {+ phase: MeetingActivityPhase;+ title: string | null;+ startedAt: number | null;+ onEndRequested: () => void;+};++type Setup = RenderHookResult<void, Props> & {+ onEndRequested: jest.Mock;+ update: (next: Partial<Props>) => void;+};++function setup(initial: Partial<Props> = {}): Setup {+ const onEndRequested = jest.fn();+ const props: Props = {+ phase: 'idle',+ title: null,+ startedAt: null,+ onEndRequested,+ ...initial,+ };+ const hook = renderHook((p: Props) => useMeetingLiveActivity(p), { initialProps: props });+ return {+ ...hook,+ onEndRequested,+ update: (next: Partial<Props>) => hook.rerender({ ...props, ...next }),+ };+}++beforeEach(() => {+ jest.clearAllMocks();+ mockEndListener = undefined;+ jest.spyOn(Date, 'now').mockReturnValue(1_000_000);+});++afterEach(() => {+ jest.restoreAllMocks();+});++describe('useMeetingLiveActivity', () => {+ it('starts the meeting card when recording begins', () => {+ const { update } = setup();+ update({ phase: 'recording', title: 'Weekly sync', startedAt: 990_000 });+ expect(mockStartMeeting).toHaveBeenCalledWith({ title: 'Weekly sync', startedAt: 990_000 });+ });++ it('falls back to now when no start time is known', () => {+ const { update } = setup();+ update({ phase: 'recording' });+ expect(mockStartMeeting).toHaveBeenCalledWith({ title: null, startedAt: 1_000_000 });+ });++ it('does not restart the card when the title changes mid-recording', () => {+ const { update } = setup();+ update({ phase: 'recording', title: 'A', startedAt: 990_000 });+ update({ phase: 'recording', title: 'B', startedAt: 990_000 });+ expect(mockStartMeeting).toHaveBeenCalledTimes(1);+ });++ it('reports the recorded duration when processing starts', () => {+ const { update } = setup();+ update({ phase: 'recording', startedAt: 958_000 });+ update({ phase: 'processing' });+ expect(mockSetMeetingProcessing).toHaveBeenCalledWith({ recordedSeconds: 42 });+ });++ it('ignores processing that was never preceded by a recording', () => {+ const { update } = setup();+ update({ phase: 'processing' });+ expect(mockSetMeetingProcessing).not.toHaveBeenCalled();+ });++ it('ends the meeting when processing finishes back to idle', () => {+ const { update } = setup();+ update({ phase: 'recording', startedAt: 990_000 });+ update({ phase: 'processing' });+ update({ phase: 'idle' });+ expect(mockEndMeeting).toHaveBeenCalledTimes(1);+ });++ it('recording → idle ends the meeting', () => {+ const { update } = setup();+ update({ phase: 'recording', startedAt: 990_000 });+ update({ phase: 'idle' });+ expect(mockEndMeeting).toHaveBeenCalledTimes(1);+ });++ it('ends the meeting on unmount mid-meeting', () => {+ const { update, unmount } = setup();+ update({ phase: 'recording', startedAt: 990_000 });+ unmount();+ expect(mockEndMeeting).toHaveBeenCalledTimes(1);+ });++ it('does not end anything on unmount when no meeting ran', () => {+ const { unmount } = setup();+ unmount();+ expect(mockEndMeeting).not.toHaveBeenCalled();+ });++ it('forwards a lock-screen End while recording', () => {+ const { update, onEndRequested } = setup();+ update({ phase: 'recording', startedAt: 990_000 });+ mockEndListener?.();+ expect(onEndRequested).toHaveBeenCalledTimes(1);+ });++ it('End fired twice while recording calls onEndRequested once', () => {+ const { update, onEndRequested } = setup();+ update({ phase: 'recording', startedAt: 990_000 });+ mockEndListener?.();+ mockEndListener?.();+ expect(onEndRequested).toHaveBeenCalledTimes(1);+ });++ it('allows End again for the next meeting', () => {+ const { update, onEndRequested } = setup();+ update({ phase: 'recording', startedAt: 990_000 });+ mockEndListener?.();+ update({ phase: 'idle' });+ update({ phase: 'recording', startedAt: 995_000 });+ mockEndListener?.();+ expect(onEndRequested).toHaveBeenCalledTimes(2);+ });++ it('ignores End while processing or idle', () => {+ const { update, onEndRequested } = setup();+ mockEndListener?.();+ update({ phase: 'recording', startedAt: 990_000 });+ update({ phase: 'processing' });+ mockEndListener?.();+ expect(onEndRequested).not.toHaveBeenCalled();+ });++ it('calls the latest onEndRequested callback', () => {+ const { update } = setup();+ const latest = jest.fn();+ update({ phase: 'recording', startedAt: 990_000, onEndRequested: latest });+ mockEndListener?.();+ expect(latest).toHaveBeenCalledTimes(1);+ });++ it('removes the End listener on unmount', () => {+ const { unmount } = setup();+ unmount();+ expect(mockRemove).toHaveBeenCalledTimes(1);+ });+});diff --git a/openwhispr-mobile/src/hooks/useAppInit.ts b/openwhispr-mobile/src/hooks/useAppInit.tsindex 4137466c3..455673d7f 100644--- a/openwhispr-mobile/src/hooks/useAppInit.ts+++ b/openwhispr-mobile/src/hooks/useAppInit.ts@@ -1,4 +1,5 @@import { useEffect } from 'react';+import { startMeetingRecoveryOnce } from '@/lib/meetingRecovery';import { useDictionaryStore } from '@/store/useDictionaryStore';import { useSnippetsStore } from '@/store/useSnippetsStore';import { useNotesStore } from '@/store/useNotesStore';@@ -33,4 +34,10 @@ export function useAppInit() {loadConfig,loadTranscripts,]);++ // After notes load and before any meeting can start: recover meeting notes whose+ // process died mid-recording or mid-pipeline.+ useEffect(() => {+ if (isNotesInitialized) startMeetingRecoveryOnce();+ }, [isNotesInitialized]);}diff --git a/openwhispr-mobile/src/hooks/useMeetingLiveActivity.ts b/openwhispr-mobile/src/hooks/useMeetingLiveActivity.tsnew file mode 100644index 000000000..87e3f0c86--- /dev/null+++ b/openwhispr-mobile/src/hooks/useMeetingLiveActivity.ts@@ -0,0 +1,71 @@+import { useEffect, useRef } from 'react';+import { LiveActivity } from '../../modules/live-activity/src';++export type MeetingActivityPhase = 'idle' | 'recording' | 'processing';++interface UseMeetingLiveActivityOptions {+ phase: MeetingActivityPhase;+ title: string | null;+ /** Epoch ms. Read only when `phase` enters 'recording'. */+ startedAt: number | null;+ /** Called when the user taps End on the lock screen while recording. */+ onEndRequested: () => void;+}++/**+ * Mirrors a meeting's phase into the iOS Live Activity and forwards the+ * lock-screen End button. A no-op off iOS (the module is inert there).+ */+export function useMeetingLiveActivity({+ phase,+ title,+ startedAt,+ onEndRequested,+}: UseMeetingLiveActivityOptions): void {+ const latestRef = useRef({ phase, title, startedAt, onEndRequested });+ // Non-null while this hook has a meeting card up.+ const activeStartedAtRef = useRef<number | null>(null);+ // One End per meeting: iOS or a racing in-app Stop can deliver it twice before+ // the screen re-renders into 'processing'.+ const endRequestedRef = useRef(false);++ // Declared first so later effects in the same commit read fresh values.+ useEffect(() => {+ latestRef.current = { phase, title, startedAt, onEndRequested };+ });++ useEffect(() => {+ if (phase === 'recording') {+ if (activeStartedAtRef.current != null) return;+ const start = latestRef.current.startedAt ?? Date.now();+ activeStartedAtRef.current = start;+ endRequestedRef.current = false;+ LiveActivity.startMeeting({ title: latestRef.current.title, startedAt: start });+ return;+ }+ if (activeStartedAtRef.current == null) return;+ if (phase === 'processing') {+ LiveActivity.setMeetingProcessing({+ recordedSeconds: (Date.now() - activeStartedAtRef.current) / 1000,+ });+ return;+ }+ activeStartedAtRef.current = null;+ LiveActivity.endMeeting();+ }, [phase]);++ useEffect(() => {+ const subscription = LiveActivity.addEndMeetingListener(() => {+ if (latestRef.current.phase !== 'recording' || endRequestedRef.current) return;+ endRequestedRef.current = true;+ latestRef.current.onEndRequested();+ });+ return () => {+ subscription.remove();+ if (activeStartedAtRef.current != null) {+ activeStartedAtRef.current = null;+ LiveActivity.endMeeting();+ }+ };+ }, []);+}diff --git a/openwhispr-mobile/src/lib/__tests__/meetingRecovery.test.ts b/openwhispr-mobile/src/lib/__tests__/meetingRecovery.test.tsnew file mode 100644index 000000000..2d947b596--- /dev/null+++ b/openwhispr-mobile/src/lib/__tests__/meetingRecovery.test.ts@@ -0,0 +1,255 @@+jest.mock('expo-sqlite/localStorage/install', () => ({}));+jest.mock('@/data', () => ({ notesRepository: { getAllNotes: jest.fn(() => []) } }));+jest.mock('@/store/useNotesStore', () => ({ useNotesStore: { getState: jest.fn() } }));+jest.mock('@/lib/sentry', () => ({ Sentry: { captureException: jest.fn() } }));+jest.mock('@/lib/transcriptAudio', () => ({+ isManagedMeetingAudioUri: (noteId: number, uri?: string | null) =>+ uri === `file:///docs/meeting-${noteId}.wav`,+}));++import type { AppStateStatus } from 'react-native';+import type { Note } from '@/data';+import {+ MEETING_RESUME_MARKER_PREFIX,+ createdBeforeRuntime,+ recoverOrphanedMeetings,+ waitForAppActive,+ type MeetingRecoveryDeps,+} from '@/lib/meetingRecovery';++function note(overrides: Partial<Note> & { id: number }): Note {+ return {+ noteType: 'meeting',+ transcriptionStatus: 'transcribing',+ sourceFile: `file:///docs/meeting-${overrides.id}.wav`,+ ...overrides,+ } as Note;+}++interface Harness {+ deps: MeetingRecoveryDeps;+ store: Map<string, string>;+ calls: string[];+}++function makeDeps(notes: Note[], initialStorage: Record<string, string> = {}): Harness {+ const store = new Map(Object.entries(initialStorage));+ const calls: string[] = [];+ const deps: MeetingRecoveryDeps = {+ listNotes: jest.fn(() => notes),+ markFailed: jest.fn((id: number) => {+ calls.push(`failed:${id}`);+ }),+ waitUntilActive: jest.fn(() => Promise.resolve()),+ resume: jest.fn(async (id: number) => {+ calls.push(`resume:${id}`);+ }),+ storage: {+ getItem: (key: string) => store.get(key) ?? null,+ setItem: (key: string, value: string) => {+ calls.push(`set:${key}`);+ store.set(key, value);+ },+ removeItem: (key: string) => {+ calls.push(`remove:${key}`);+ store.delete(key);+ },+ },+ reportError: jest.fn(),+ };+ return { deps, store, calls };+}++const marker = (id: number): string => `${MEETING_RESUME_MARKER_PREFIX}${id}`;++describe('recoverOrphanedMeetings', () => {+ it.each(['transcribing', 'diarizing'])(+ 'marks a %s orphan failed, then resumes it once behind a marker',+ async (status) => {+ const { deps, store, calls } = makeDeps([note({ id: 1, transcriptionStatus: status })]);+ await recoverOrphanedMeetings(deps);+ expect(calls).toEqual(['failed:1', `set:${marker(1)}`, 'resume:1', `remove:${marker(1)}`]);+ expect(store.has(marker(1))).toBe(false);+ },+ );++ it('does not resume a second time when the marker survived a crash', async () => {+ const { deps, store } = makeDeps([note({ id: 2 })], { [marker(2)]: '1' });+ await recoverOrphanedMeetings(deps);+ expect(deps.markFailed).toHaveBeenCalledWith(2);+ expect(deps.resume).not.toHaveBeenCalled();+ expect(store.has(marker(2))).toBe(false);+ });++ it('fails a note left in recording without resuming', async () => {+ const { deps } = makeDeps([note({ id: 3, transcriptionStatus: 'recording' })]);+ await recoverOrphanedMeetings(deps);+ expect(deps.markFailed).toHaveBeenCalledWith(3);+ expect(deps.resume).not.toHaveBeenCalled();+ });++ it('fails without resuming when there is no managed meeting WAV', async () => {+ const { deps } = makeDeps([+ note({ id: 4, sourceFile: null }),+ note({ id: 5, sourceFile: 'file:///elsewhere/meeting-5.wav' }),+ ]);+ await recoverOrphanedMeetings(deps);+ expect(deps.markFailed).toHaveBeenCalledWith(4);+ expect(deps.markFailed).toHaveBeenCalledWith(5);+ expect(deps.resume).not.toHaveBeenCalled();+ });++ it('leaves settled and non-meeting notes alone', async () => {+ const { deps } = makeDeps([+ note({ id: 6, transcriptionStatus: 'done' }),+ note({ id: 7, transcriptionStatus: 'failed' }),+ note({ id: 8, transcriptionStatus: 'idle' }),+ note({ id: 9, transcriptionStatus: null }),+ note({ id: 10, noteType: 'personal', transcriptionStatus: 'transcribing' }),+ ]);+ await recoverOrphanedMeetings(deps);+ expect(deps.markFailed).not.toHaveBeenCalled();+ expect(deps.resume).not.toHaveBeenCalled();+ });++ it('a failing resume is reported and the sweep continues', async () => {+ const { deps, store } = makeDeps([note({ id: 11 }), note({ id: 12 })]);+ const boom = new Error('pipeline crashed');+ (deps.resume as jest.Mock).mockImplementationOnce(async () => {+ throw boom;+ });+ await recoverOrphanedMeetings(deps);+ expect(deps.reportError).toHaveBeenCalledWith(boom, 11);+ expect(deps.resume).toHaveBeenCalledWith(12);+ expect(store.has(marker(11))).toBe(false);+ expect(store.has(marker(12))).toBe(false);+ });++ it('skips the resume when marking failed throws', async () => {+ const { deps, calls } = makeDeps([note({ id: 13 })]);+ const illegal = new Error('Illegal transcription status transition');+ (deps.markFailed as jest.Mock).mockImplementationOnce(() => {+ throw illegal;+ });+ await recoverOrphanedMeetings(deps);+ expect(deps.reportError).toHaveBeenCalledWith(illegal, 13);+ expect(deps.resume).not.toHaveBeenCalled();+ expect(calls).toEqual([`remove:${marker(13)}`]);+ });++ it('marks failed immediately but sets the marker and resumes only once active', async () => {+ const { deps, calls } = makeDeps([note({ id: 17 })]);+ let becomeActive: () => void = () => {};+ (deps.waitUntilActive as jest.Mock).mockImplementationOnce(+ () => new Promise<void>((resolve) => (becomeActive = resolve)),+ );+ const sweep = recoverOrphanedMeetings(deps);+ await Promise.resolve();+ expect(calls).toEqual(['failed:17']);+ becomeActive();+ await sweep;+ expect(calls).toEqual(['failed:17', `set:${marker(17)}`, 'resume:17', `remove:${marker(17)}`]);+ });++ it('resumes one note at a time', async () => {+ const { deps } = makeDeps([note({ id: 14 }), note({ id: 15 })]);+ let releaseFirst: () => void = () => {};+ (deps.resume as jest.Mock).mockImplementationOnce(+ () => new Promise<void>((resolve) => (releaseFirst = resolve)),+ );+ const sweep = recoverOrphanedMeetings(deps);+ await Promise.resolve();+ expect(deps.resume).toHaveBeenCalledTimes(1);+ releaseFirst();+ await sweep;+ expect(deps.resume).toHaveBeenCalledTimes(2);+ });++ it('reads the note list once, before any resume', async () => {+ const { deps } = makeDeps([note({ id: 16 })]);+ await recoverOrphanedMeetings(deps);+ expect(deps.listNotes).toHaveBeenCalledTimes(1);+ });+});++interface FakeAppState {+ appState: { currentState: AppStateStatus; addEventListener: jest.Mock };+ remove: jest.Mock;+ emit: (state: AppStateStatus) => void;+}++function fakeAppState(currentState: AppStateStatus): FakeAppState {+ let listener: ((state: AppStateStatus) => void) | null = null;+ const remove = jest.fn(() => {+ listener = null;+ });+ const appState = {+ currentState,+ addEventListener: jest.fn((_type: 'change', next: (state: AppStateStatus) => void) => {+ listener = next;+ return { remove };+ }),+ };+ return { appState, remove, emit: (state: AppStateStatus) => listener?.(state) };+}++describe('waitForAppActive', () => {+ it('resolves at once without subscribing when already active', async () => {+ const { appState } = fakeAppState('active');+ await waitForAppActive(appState);+ expect(appState.addEventListener).not.toHaveBeenCalled();+ });++ it('waits past background and inactive, then unsubscribes', async () => {+ const { appState, remove, emit } = fakeAppState('background');+ let settled = false;+ const waiting = waitForAppActive(appState).then(() => {+ settled = true;+ });+ emit('inactive');+ emit('background');+ await Promise.resolve();+ expect(settled).toBe(false);+ emit('active');+ await waiting;+ expect(settled).toBe(true);+ expect(remove).toHaveBeenCalledTimes(1);+ });+});++describe('createdBeforeRuntime', () => {+ // 2026-09-25T10:00:00.500Z+ const runtimeStartedAtMs = Date.UTC(2026, 8, 25, 10, 0, 0, 500);++ it('keeps notes SQLite stamped before the runtime started', () => {+ expect(createdBeforeRuntime({ createdAt: '2026-09-25 09:59:59' }, runtimeStartedAtMs)).toBe(+ true,+ );+ expect(+ createdBeforeRuntime({ createdAt: '2026-09-24T22:00:00.000Z' }, runtimeStartedAtMs),+ ).toBe(true);+ });++ it('drops notes created during this runtime, including its first second', () => {+ expect(createdBeforeRuntime({ createdAt: '2026-09-25 10:00:00' }, runtimeStartedAtMs)).toBe(+ false,+ );+ expect(createdBeforeRuntime({ createdAt: '2026-09-25 10:05:00' }, runtimeStartedAtMs)).toBe(+ false,+ );+ });++ it('keeps a note with no creation stamp', () => {+ expect(createdBeforeRuntime({ createdAt: null }, runtimeStartedAtMs)).toBe(true);+ });++ it('keeps a note whose creation stamp cannot be parsed', () => {+ expect(createdBeforeRuntime({ createdAt: 'not a date' }, runtimeStartedAtMs)).toBe(true);+ });++ it('reads offset stamps instead of treating them as now', () => {+ expect(+ createdBeforeRuntime({ createdAt: '2026-09-25T09:59:59+00:00' }, runtimeStartedAtMs),+ ).toBe(true);+ });+});diff --git a/openwhispr-mobile/src/lib/__tests__/parseNoteTimestamp.test.ts b/openwhispr-mobile/src/lib/__tests__/parseNoteTimestamp.test.tsnew file mode 100644index 000000000..61f7ad406--- /dev/null+++ b/openwhispr-mobile/src/lib/__tests__/parseNoteTimestamp.test.ts@@ -0,0 +1,61 @@+import { parseNoteTimestamp, tryParseNoteTimestamp } from '@/lib/parseNoteTimestamp';++describe('tryParseNoteTimestamp', () => {+ it('reads SQLite datetime("now") stamps as UTC', () => {+ expect(tryParseNoteTimestamp('2026-09-25 10:15:30')?.toISOString()).toBe(+ '2026-09-25T10:15:30.000Z',+ );+ });++ it('reads ISO stamps with a Z designator', () => {+ expect(tryParseNoteTimestamp('2026-09-25T10:15:30.250Z')?.toISOString()).toBe(+ '2026-09-25T10:15:30.250Z',+ );+ });++ it('keeps an explicit UTC offset instead of appending Z', () => {+ expect(tryParseNoteTimestamp('2026-09-25T10:15:30+00:00')?.toISOString()).toBe(+ '2026-09-25T10:15:30.000Z',+ );+ });++ it('applies a non-zero offset', () => {+ expect(tryParseNoteTimestamp('2026-09-25T12:15:30+02:00')?.toISOString()).toBe(+ '2026-09-25T10:15:30.000Z',+ );+ });++ it('passes Dates and epoch numbers through', () => {+ const date = new Date('2026-09-25T10:15:30Z');+ expect(tryParseNoteTimestamp(date)).toBe(date);+ expect(tryParseNoteTimestamp(date.getTime())?.getTime()).toBe(date.getTime());+ });++ it('returns null for missing or unparsable stamps', () => {+ expect(tryParseNoteTimestamp(null)).toBeNull();+ expect(tryParseNoteTimestamp(undefined)).toBeNull();+ expect(tryParseNoteTimestamp('')).toBeNull();+ expect(tryParseNoteTimestamp('not a date')).toBeNull();+ });+});++describe('parseNoteTimestamp', () => {+ beforeEach(() => {+ jest.useFakeTimers().setSystemTime(new Date('2030-01-01T00:00:00Z'));+ });++ afterEach(() => {+ jest.useRealTimers();+ });++ it('falls back to now for missing or unparsable stamps', () => {+ expect(parseNoteTimestamp(null).toISOString()).toBe('2030-01-01T00:00:00.000Z');+ expect(parseNoteTimestamp('not a date').toISOString()).toBe('2030-01-01T00:00:00.000Z');+ });++ it('parses offset stamps rather than falling back to now', () => {+ expect(parseNoteTimestamp('2026-09-25T10:15:30+00:00').toISOString()).toBe(+ '2026-09-25T10:15:30.000Z',+ );+ });+});diff --git a/openwhispr-mobile/src/lib/meetingRecovery.ts b/openwhispr-mobile/src/lib/meetingRecovery.tsnew file mode 100644index 000000000..eef660eaf--- /dev/null+++ b/openwhispr-mobile/src/lib/meetingRecovery.ts@@ -0,0 +1,149 @@+import 'expo-sqlite/localStorage/install';+import { AppState, type AppStateStatus } from 'react-native';+import type { Note } from '@/data';+import { notesRepository } from '@/data';+import { canTransition } from '@/lib/diarization/transcriptionStatus';+import { tryParseNoteTimestamp } from '@/lib/parseNoteTimestamp';+import { Sentry } from '@/lib/sentry';+import { isManagedMeetingAudioUri } from '@/lib/transcriptAudio';+import { useNotesStore } from '@/store/useNotesStore';+import type { TranscriptionStatus } from '@/types';++export const MEETING_RESUME_MARKER_PREFIX = 'meetingResumeAttempted:';++const RUNTIME_STARTED_AT_MS = Date.now();++// In a fresh process nothing is running a meeting pipeline, so a meeting note in+// any of these states was orphaned when its previous process died.+const ORPHANED_STATUSES: ReadonlySet<string> = new Set(['recording', 'transcribing', 'diarizing']);++export interface MeetingRecoveryDeps {+ listNotes(): Note[];+ markFailed(noteId: number): void;+ /** Settles once a resume can run without iOS suspending it. */+ waitUntilActive(): Promise<void>;+ resume(noteId: number): Promise<void>;+ storage: {+ getItem(key: string): string | null;+ setItem(key: string, value: string): void;+ removeItem(key: string): void;+ };+ reportError(error: unknown, noteId: number): void;+}++/**+ * Recovers meeting notes whose process died mid-recording or mid-pipeline (e.g. iOS+ * terminated the app after a lock-screen End). Each orphan is marked failed, which+ * surfaces the note's Retry button; one with its recording still on disk is also+ * resumed, once. The marker is set before the resume and cleared when it settles,+ * so a resume that itself kills the app is not retried on the next launch.+ */+export async function recoverOrphanedMeetings(deps: MeetingRecoveryDeps): Promise<void> {+ const orphans = deps+ .listNotes()+ .filter(+ (note) =>+ note.noteType === 'meeting' &&+ note.transcriptionStatus != null &&+ ORPHANED_STATUSES.has(note.transcriptionStatus),+ );++ for (const note of orphans) {+ const markerKey = `${MEETING_RESUME_MARKER_PREFIX}${note.id}`;+ const alreadyAttempted = deps.storage.getItem(markerKey) != null;+ const resumable =+ note.transcriptionStatus !== 'recording' &&+ isManagedMeetingAudioUri(note.id, note.sourceFile) &&+ !alreadyAttempted;++ try {+ if (canTransition(note.transcriptionStatus as TranscriptionStatus, 'failed')) {+ deps.markFailed(note.id);+ }+ } catch (error) {+ deps.reportError(error, note.id);+ deps.storage.removeItem(markerKey);+ continue;+ }++ if (!resumable) {+ if (alreadyAttempted) deps.storage.removeItem(markerKey);+ continue;+ }++ // Before the marker: the note is already failed, so a background launch+ // killed while waiting leaves it failed with Retry and no stale marker.+ await deps.waitUntilActive();+ deps.storage.setItem(markerKey, '1');+ try {+ // Sequential on purpose: each resume runs on-device ASR + diarization.+ await deps.resume(note.id);+ } catch (error) {+ deps.reportError(error, note.id);+ }+ deps.storage.removeItem(markerKey);+ }+}++interface AppStateLike {+ currentState: AppStateStatus;+ addEventListener(type: 'change', listener: (state: AppStateStatus) => void): { remove(): void };+}++/**+ * Resolves once the app is foreground-active. A background launch (a finished+ * background upload, a Live Activity button) would otherwise start an on-device+ * pipeline that iOS suspends moments later.+ */+export function waitForAppActive(appState: AppStateLike): Promise<void> {+ if (appState.currentState === 'active') return Promise.resolve();+ return new Promise((resolve) => {+ const subscription = appState.addEventListener('change', (state) => {+ if (state !== 'active') return;+ subscription.remove();+ resolve();+ });+ });+}++/**+ * A note created during this JS runtime has a live pipeline, so it is never an+ * orphan. SQLite stamps `created_at` to the second, so the cutoff is the start of+ * the second the runtime started in.+ */+export function createdBeforeRuntime(+ note: Pick<Note, 'createdAt'>,+ runtimeStartedAtMs: number,+): boolean {+ // The column defaults to datetime('now'), so a missing or unreadable stamp is+ // legacy data; recovering it beats leaving it stuck mid-pipeline.+ const createdAt = tryParseNoteTimestamp(note.createdAt);+ if (!createdAt) return true;+ const cutoffMs = Math.floor(runtimeStartedAtMs / 1000) * 1000;+ return createdAt.getTime() < cutoffMs;+}++let hasStarted = false;++/** Runs the sweep once per JS runtime. Call after the notes store is initialized. */+export function startMeetingRecoveryOnce(): void {+ if (hasStarted) return;+ hasStarted = true;+ recoverOrphanedMeetings({+ listNotes: () =>+ notesRepository+ .getAllNotes()+ .filter((note) => createdBeforeRuntime(note, RUNTIME_STARTED_AT_MS)),+ markFailed: (noteId) => useNotesStore.getState().transitionStatus(noteId, 'failed'),+ waitUntilActive: () => waitForAppActive(AppState),+ resume: (noteId) => useNotesStore.getState().retryMeetingTranscription(noteId),+ storage: localStorage,+ reportError: (error, noteId) =>+ Sentry.captureException(error, {+ tags: { feature: 'meeting-recovery' },+ extra: { noteId },+ }),+ }).catch((error) => {+ Sentry.captureException(error, { tags: { feature: 'meeting-recovery' } });+ });+}diff --git a/openwhispr-mobile/src/lib/parseNoteTimestamp.ts b/openwhispr-mobile/src/lib/parseNoteTimestamp.tsindex 76bbad9bf..91104ad32 100644--- a/openwhispr-mobile/src/lib/parseNoteTimestamp.ts+++ b/openwhispr-mobile/src/lib/parseNoteTimestamp.ts@@ -1,11 +1,20 @@-export function parseNoteTimestamp(updatedAt: string | number | Date | null | undefined): Date {- if (updatedAt instanceof Date) return updatedAt;- if (typeof updatedAt === 'number') return new Date(updatedAt);- if (!updatedAt) return new Date();- // SQLite's datetime('now') returns "YYYY-MM-DD HH:MM:SS" with a space.- // Hermes (iOS) rejects that format; convert space → T and ensure UTC marker.- const iso = updatedAt.replace(' ', 'T');- const withZ = iso.endsWith('Z') ? iso : iso + 'Z';- const date = new Date(withZ);- return isNaN(date.getTime()) ? new Date() : date;+// A trailing Z or ±HH:MM / ±HHMM offset already pins the zone.+const TIMEZONE_DESIGNATOR = /(?:[zZ]|[+-]\d{2}:?\d{2})$/;++/** Parses a note timestamp, or returns null when it is missing or unparsable. */+export function tryParseNoteTimestamp(+ timestamp: string | number | Date | null | undefined,+): Date | null {+ if (timestamp instanceof Date) return timestamp;+ if (typeof timestamp === 'number') return new Date(timestamp);+ if (!timestamp) return null;+ // SQLite's datetime('now') returns "YYYY-MM-DD HH:MM:SS" with a space and no zone.+ // Hermes (iOS) rejects that format; convert space → T and mark it UTC.+ const iso = timestamp.replace(' ', 'T');+ const date = new Date(TIMEZONE_DESIGNATOR.test(iso) ? iso : iso + 'Z');+ return isNaN(date.getTime()) ? null : date;+}++export function parseNoteTimestamp(timestamp: string | number | Date | null | undefined): Date {+ return tryParseNoteTimestamp(timestamp) ?? new Date();}diff --git a/openwhispr-mobile/src/screens/MeetingRecordScreen.tsx b/openwhispr-mobile/src/screens/MeetingRecordScreen.tsxindex 008e144dc..ce4102c57 100644--- a/openwhispr-mobile/src/screens/MeetingRecordScreen.tsx+++ b/openwhispr-mobile/src/screens/MeetingRecordScreen.tsx@@ -25,6 +25,7 @@ import { useAuthStore } from '@/store/useAuthStore';import { canRunCloudMeeting } from '@/lib/accountAccess';import { useProcessingModeStore } from '@/store/useProcessingModeStore';import { useCloudMeeting } from '@/hooks/useCloudMeeting';+import { useMeetingLiveActivity, type MeetingActivityPhase } from '@/hooks/useMeetingLiveActivity';import { CloudMeetingRecording } from '@/components/notes/CloudMeetingRecording';import { canTransition } from '@/lib/diarization/transcriptionStatus';import { Sentry } from '@/lib/sentry';@@ -48,6 +49,9 @@ export const MeetingRecordScreen = (): React.JSX.Element => {const [noteId, setNoteId] = useState<number | null>(null);const [count, setCount] = useState<number | undefined>(undefined);const [elapsedSeconds, setElapsedSeconds] = useState(0);+ // Wall-clock start of the current meeting (local or cloud), for the Live Activity timer.+ // recordingStartedAtRef is local-only and is cleared as soon as processing starts.+ const [meetingStartedAt, setMeetingStartedAt] = useState<number | null>(null);const [rawNotes, setRawNotes] = useState('');const [calendarEvents, setCalendarEvents] = useState<GoogleCalendarEvent[]>([]);const [selectedCalendarEventId, setSelectedCalendarEventId] = useState<number | null>(null);@@ -208,7 +212,9 @@ export const MeetingRecordScreen = (): React.JSX.Element => {setRawNotes(note.content);lastSavedRawNotesRef.current = note.content;setNoteId(note.id);- recordingStartedAtRef.current = Date.now();+ const startedAt = Date.now();+ recordingStartedAtRef.current = startedAt;+ setMeetingStartedAt(startedAt);setPhase('recording');};@@ -312,6 +318,7 @@ export const MeetingRecordScreen = (): React.JSX.Element => {setRawNotes(note.content);lastSavedRawNotesRef.current = note.content;setNoteId(note.id);+ setMeetingStartedAt(Date.now());setPhase('cloud-recording');};@@ -341,6 +348,22 @@ export const MeetingRecordScreen = (): React.JSX.Element => {}};+ const meetingActivityPhase: MeetingActivityPhase =+ phase === 'recording' || phase === 'cloud-recording'+ ? 'recording'+ : phase === 'processing'+ ? 'processing'+ : 'idle';+ useMeetingLiveActivity({+ phase: meetingActivityPhase,+ title: selectedMeetingContext?.title ?? null,+ startedAt: meetingStartedAt,+ onEndRequested: () => {+ const stop = phase === 'cloud-recording' ? finishCloud : finish;+ stop().catch(Sentry.captureException);+ },+ });+if (phase === 'prompt') {return (<SpeakerCountPrompt