30 lines
1.1 KiB
Swift
30 lines
1.1 KiB
Swift
import Commanding
|
|
import AppIntents
|
|
|
|
/// The intent behind the main button of the recording Live Activity, which pauses or resumes the recording.
|
|
///
|
|
/// The intent is compiled into both the app and the widget extension: the widget references it from the activity's buttons, and the
|
|
/// system executes it in the app's process — where it sends ``RecordingCommand/toggle`` through the process-wide
|
|
/// ``RecordingCommander``, mirroring a press of the feature's main button.
|
|
struct ToggleRecordingIntent: LiveActivityIntent {
|
|
|
|
// MARK: Constants
|
|
|
|
static let title: LocalizedStringResource = "Pause or Resume Recording"
|
|
static let description = IntentDescription("Pauses or resumes the ongoing recording.")
|
|
static let openAppWhenRun = false
|
|
|
|
// MARK: Methods
|
|
|
|
/// Sends the toggle command to the recording flow.
|
|
///
|
|
/// - Returns: An empty result, since the outcome surfaces through the Live Activity's own content update.
|
|
@MainActor
|
|
func perform() async throws -> some IntentResult {
|
|
RecordingCommander.shared.send(.toggle)
|
|
|
|
return .result()
|
|
}
|
|
|
|
}
|