30 lines
1.0 KiB
Swift
30 lines
1.0 KiB
Swift
import Commanding
|
|||
|
|
import AppIntents
|
||
|
|
|
||
|
|
/// 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
|
||
|
|
|
||
|
|
static let title: LocalizedStringResource = "Discard Recording"
|
||
|
|
static let description = IntentDescription("Throws the paused recording away.")
|
||
|
|
static let openAppWhenRun = false
|
||
|
|
|
||
|
|
// 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()
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|