2026-07-09 13:33:32 +03:00
|
|
|
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 {
|
2026-07-09 22:43:06 +03:00
|
|
|
await activity.end(nil, dismissalPolicy: .immediate)
|
2026-07-09 13:33:32 +03:00
|
|
|
}
|
|
|
|
|
return .result()
|
|
|
|
|
}
|
|
|
|
|
}
|