Files
attendi/Widgets/Attendi/Sources/Intents/DiscardRecordingIntent.swift
T

37 lines
1.5 KiB
Swift

#if os(iOS)
import AppIntents
import Commanding
/// The intent behind the discard button of the recording Live Activity, which throws the recording away.
///
/// 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/discard`` through the process-wide
/// ``RecordingCommander``, mirroring a press of the feature's discard button.
struct DiscardRecordingIntent: 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.discard-recording.title"
/// The localized description of the intent, resolved from the widget target's string catalog.
static let description = IntentDescription("intent.discard-recording.description")
/// Whether running the intent brings the app to the foreground; `true`, so discarding the recording opens the app from the
/// Live Activity.
static let openAppWhenRun = true
// MARK: Methods
/// Sends the discard command to the recording flow.
///
/// - Returns: An empty result, since the discard ends the Live Activity itself.
@MainActor
func perform() async throws -> some IntentResult {
RecordingCommander.shared.send(.discard)
return .result()
}
}
#endif