Skip to content

Commit

Permalink
Add macOS openURL implementation and fix test crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Nov 28, 2023
1 parent dd516ee commit e52c1ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import UIKit
private import UIKitCore
private import CoreServices
#endif
#elseif os(macOS)
import AppKit
#endif
#endif

Expand Down Expand Up @@ -97,10 +99,12 @@ extension EnvironmentValues {
struct OpenURLActionKey: EnvironmentKey {
static let defaultValue = OpenURLAction(
handler: .system { url, completion in
#if os(iOS) || os(tvOS) || os(visionOS)
#if os(iOS) || os(tvOS)
UIApplication.shared.open(url, options: [:], completionHandler: completion)
#elseif os(macOS)
fatalError("Unimplemented")
NSWorkspace.shared.open(url, configuration: .init()) { application, error in
completion(error != nil)
}
#else
fatalError("Unimplemented")
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import XCTest
@testable import OpenSwiftUI

final class EnvironmentValuesOpenURLTests: XCTestCase {
#if DEBUG
func testOpenSensitiveURLActionKey() throws {
let value = OpenSensitiveURLActionKey.defaultValue
#if os(iOS) || os(macOS) || os(tvOS)
func testOpenURLActionKey() {
let value = OpenURLActionKey.defaultValue
value.callAsFunction(URL(string: "https://example.com")!)
}
#endif
Expand Down

0 comments on commit e52c1ca

Please sign in to comment.