Files
KisaniCal/KisaniCalWidgets/StopCountdownIntent.swift

27 lines
969 B
Swift
Raw Normal View History

import AppIntents
import ActivityKit
/// Ends a running task Live Activity directly from its Lock Screen / Dynamic
/// Island card no need to open the app. Runs in the widget extension
/// process (that's how LiveActivityIntent works), so it talks to ActivityKit
/// directly rather than going through LiveActivityManager (app target only).
@available(iOS 17.0, *)
struct StopCountdownIntent: LiveActivityIntent {
static var title: LocalizedStringResource = "Stop Countdown"
static var description = IntentDescription("Ends this task's live countdown.")
@Parameter(title: "Task ID")
var taskID: String
init() {}
init(taskID: String) { self.taskID = taskID }
func perform() async throws -> some IntentResult {
for activity in Activity<TaskActivityAttributes>.activities
where activity.attributes.taskID == taskID {
await activity.end(dismissalPolicy: .immediate)
}
return .result()
}
}