SPB Git

Repository Public License

RecordingActivity.swift 1.8 KB 49 lines swift

1//2//  ORIX Audio3//  File: Shared/RecordingActivity.swift4//  Description: Live Activity attributes and the Lock Screen intents, shared by the app and the widget extension.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//9import ActivityKit10import AppIntents11import Foundation1213struct RecordingActivityAttributes: ActivityAttributes {14    struct ContentState: Codable, Hashable {15        var isPaused: Bool16        /// Recorded time at `updatedAt`, in seconds. While recording, the display counts up from `updatedAt − elapsed`.17        var elapsed: Double18        var updatedAt: Date19        var markerCount: Int20        var statusText: String21    }22    var title: String23}2425/// The app registers closures here at launch. In the widget extension process they stay nil, so the intents do nothing there26/// (a `LiveActivityIntent` always runs in the app's process).27enum RecordingIntentBridge {28    @MainActor static var togglePause: (() -> Void)?29    @MainActor static var addMarker: (() -> Void)?30}3132struct ToggleRecordingPauseIntent: LiveActivityIntent {33    static let title: LocalizedStringResource = "Pause or Resume Recording"34    static let description = IntentDescription("Pauses or resumes the recording in progress.")35    func perform() async throws -> some IntentResult {36        await MainActor.run { RecordingIntentBridge.togglePause?() }37        return .result()38    }39}4041struct AddRecordingMarkerIntent: LiveActivityIntent {42    static let title: LocalizedStringResource = "Add Recording Marker"43    static let description = IntentDescription("Adds a marker at the current position of the recording in progress.")44    func perform() async throws -> some IntentResult {45        await MainActor.run { RecordingIntentBridge.addMarker?() }46        return .result()47    }48}49
Files main
Menu

Theme