|
1 | 1 | import Foundation
|
2 | 2 | import XCTestDynamicOverlay
|
3 |
| - |
4 |
| -#if canImport(AppKit) |
5 |
| - import AppKit |
6 |
| -#endif |
7 |
| -#if canImport(UIKit) |
8 |
| - import UIKit |
9 |
| -#endif |
10 | 3 | #if canImport(SwiftUI)
|
11 | 4 | import SwiftUI
|
12 |
| -#endif |
13 | 5 |
|
14 |
| -#if canImport(AppKit) || canImport(UIKit) || canImport(SwiftUI) |
15 | 6 | extension DependencyValues {
|
16 | 7 | /// A dependency that opens a URL.
|
17 |
| - @available(iOS 13, macOS 10.15, tvOS 13, watchOS 7, *) |
| 8 | + @available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) |
18 | 9 | public var openURL: OpenURLEffect {
|
19 | 10 | get { self[OpenURLKey.self] }
|
20 | 11 | set { self[OpenURLKey.self] = newValue }
|
21 | 12 | }
|
22 | 13 | }
|
23 | 14 |
|
| 15 | + @available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) |
24 | 16 | private enum OpenURLKey: DependencyKey {
|
25 | 17 | static let liveValue = OpenURLEffect { url in
|
26 | 18 | let stream = AsyncStream<Bool> { continuation in
|
27 | 19 | let task = Task { @MainActor in
|
28 |
| - #if canImport(AppKit) && !targetEnvironment(macCatalyst) |
29 |
| - NSWorkspace.shared.open(url, configuration: .init()) { app, error in |
30 |
| - continuation.yield(app != nil && error == nil) |
31 |
| - continuation.finish() |
32 |
| - } |
33 |
| - #elseif canImport(UIKit) && !os(watchOS) |
34 |
| - UIApplication.shared.open(url) { canOpen in |
| 20 | + #if os(watchOS) |
| 21 | + EnvironmentValues().openURL(url) |
| 22 | + continuation.yield(true) |
| 23 | + continuation.finish() |
| 24 | + #else |
| 25 | + EnvironmentValues().openURL(url) { canOpen in |
35 | 26 | continuation.yield(canOpen)
|
36 | 27 | continuation.finish()
|
37 | 28 | }
|
38 |
| - #elseif canImport(SwiftUI) |
39 |
| - if #available(watchOS 7, *) { |
40 |
| - EnvironmentValues().openURL(url) |
41 |
| - continuation.yield(true) |
42 |
| - continuation.finish() |
43 |
| - } else { |
44 |
| - continuation.yield(false) |
45 |
| - continuation.finish() |
46 |
| - } |
47 |
| - #else |
48 |
| - continuation.yield(false) |
49 |
| - continuation.finish() |
50 | 29 | #endif
|
51 | 30 | }
|
52 | 31 | continuation.onTermination = { @Sendable _ in
|
|
0 commit comments