Skip to content

Commit fbd70bf

Browse files
authored
Base OpenURL dependency on SwiftUI (#1714)
* Base `OpenURL` dependency on SwiftUI * indent
1 parent 1c50ffc commit fbd70bf

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

Sources/Dependencies/Dependencies/OpenURL.swift

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
11
import XCTestDynamicOverlay
2-
3-
#if canImport(AppKit)
4-
import AppKit
5-
#endif
6-
#if canImport(UIKit)
7-
import UIKit
8-
#endif
92
#if canImport(SwiftUI)
103
import SwiftUI
11-
#endif
124

13-
#if canImport(AppKit) || canImport(UIKit) || canImport(SwiftUI)
145
extension DependencyValues {
156
/// A dependency that opens a URL.
16-
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 7, *)
7+
@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
178
public var openURL: OpenURLEffect {
189
get { self[OpenURLKey.self] }
1910
set { self[OpenURLKey.self] = newValue }
2011
}
2112
}
2213

14+
@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
2315
private enum OpenURLKey: DependencyKey {
2416
static let liveValue = OpenURLEffect { url in
2517
let stream = AsyncStream<Bool> { continuation in
2618
let task = Task { @MainActor in
27-
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
28-
NSWorkspace.shared.open(url, configuration: .init()) { app, error in
29-
continuation.yield(app != nil && error == nil)
30-
continuation.finish()
31-
}
32-
#elseif canImport(UIKit) && !os(watchOS)
33-
UIApplication.shared.open(url) { canOpen in
19+
#if os(watchOS)
20+
EnvironmentValues().openURL(url)
21+
continuation.yield(true)
22+
continuation.finish()
23+
#else
24+
EnvironmentValues().openURL(url) { canOpen in
3425
continuation.yield(canOpen)
3526
continuation.finish()
3627
}
37-
#elseif canImport(SwiftUI)
38-
if #available(watchOS 7, *) {
39-
EnvironmentValues().openURL(url)
40-
continuation.yield(true)
41-
continuation.finish()
42-
} else {
43-
continuation.yield(false)
44-
continuation.finish()
45-
}
46-
#else
47-
continuation.yield(false)
48-
continuation.finish()
4928
#endif
5029
}
5130
continuation.onTermination = { @Sendable _ in

0 commit comments

Comments
 (0)