mirror of
https://github.com/Gimanh/taskview-community.git
synced 2026-09-12 05:49:01 +00:00
40 lines
902 B
Swift
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
|
|
}
|