|
1 | 1 | import XCTestDynamicOverlay
|
2 |
| - |
3 |
| -#if canImport(AppKit) |
4 |
| - import AppKit |
5 |
| -#endif |
6 |
| -#if canImport(UIKit) |
7 |
| - import UIKit |
8 |
| -#endif |
9 | 2 | #if canImport(SwiftUI)
|
10 | 3 | import SwiftUI
|
11 |
| -#endif |
12 | 4 |
|
13 |
| -#if canImport(AppKit) || canImport(UIKit) || canImport(SwiftUI) |
14 | 5 | extension DependencyValues {
|
15 | 6 | /// 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, *) |
17 | 8 | public var openURL: OpenURLEffect {
|
18 | 9 | get { self[OpenURLKey.self] }
|
19 | 10 | set { self[OpenURLKey.self] = newValue }
|
20 | 11 | }
|
21 | 12 | }
|
22 | 13 |
|
| 14 | + @available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) |
23 | 15 | private enum OpenURLKey: DependencyKey {
|
24 | 16 | static let liveValue = OpenURLEffect { url in
|
25 | 17 | let stream = AsyncStream<Bool> { continuation in
|
26 | 18 | 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 |
34 | 25 | continuation.yield(canOpen)
|
35 | 26 | continuation.finish()
|
36 | 27 | }
|
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() |
49 | 28 | #endif
|
50 | 29 | }
|
51 | 30 | continuation.onTermination = { @Sendable _ in
|
|
0 commit comments