37 lines
1.5 KiB
Swift
37 lines
1.5 KiB
Swift
#if os(iOS)
|
|
import AppIntents
|
|
import Commanding
|
|
|
|
/// 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
|
|
|
|
/// The localized title of the intent, resolved from the widget target's string catalog and shown wherever the system surfaces
|
|
/// the intent.
|
|
static let title: LocalizedStringResource = "intent.toggle-recording.title"
|
|
/// The localized description of the intent, resolved from the widget target's string catalog.
|
|
static let description = IntentDescription("intent.toggle-recording.description")
|
|
/// Whether running the intent brings the app to the foreground; kept `false` so the button acts straight from the Live Activity,
|
|
/// in the app's background process, without opening the app.
|
|
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()
|
|
}
|
|
|
|
}
|
|
#endif
|