Files
taskview-community/web/ios/App/TaskViewWidget/OpenTaskIntent.swift
T
2026-07-11 10:49:38 +02:00

40 lines
902 B
Swift

import Foundation
import AppIntents
#if !WIDGET_EXTENSION
import UIKit
#endif
@available(iOS 18.0, *)
struct OpenTaskIntent: AppIntent {
static let title: LocalizedStringResource = "Open Task"
static let isDiscoverable = false
static let openAppWhenRun = true
@Parameter(title: "URL")
var urlString: String
init() {
urlString = "taskview://open"
}
init(urlString: String) {
self.urlString = urlString
}
private var resolvedURL: URL {
URL(string: urlString) ?? URL(string: "taskview://open")!
}
#if WIDGET_EXTENSION
func perform() async throws -> some IntentResult & OpensIntent {
.result(opensIntent: OpenURLIntent(resolvedURL))
}
#else
@MainActor
func perform() async throws -> some IntentResult {
await UIApplication.shared.open(resolvedURL)
return .result()
}
#endif
}