diff --git a/CHANGELOG.md b/CHANGELOG.md index 0137c34..97b23de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add `GitHubAPI` to get licenses from GitHub API - Update `AcknowListViewController` and `AcknowListSwiftUIView` to get missing licenses from GitHub API, with new `canFetchLicenseFromGitHub` property to disable this behavior +- Fix open URL on macOS with SwiftUI ## 3.0.1 (24 November 2022) diff --git a/Sources/AcknowList/AcknowListSwiftUI.swift b/Sources/AcknowList/AcknowListSwiftUI.swift index d056ee2..15d4992 100644 --- a/Sources/AcknowList/AcknowListSwiftUI.swift +++ b/Sources/AcknowList/AcknowListSwiftUI.swift @@ -129,7 +129,9 @@ public struct AcknowListRowSwiftUIView: View { else if let repository = acknowledgement.repository, canOpenRepository(for: repository) { Button(action: { -#if os(iOS) +#if os(macOS) + NSWorkspace.shared.open(repository) +#elseif os(iOS) UIApplication.shared.open(repository) #endif }) { diff --git a/Sources/AcknowList/GitHubAPI.swift b/Sources/AcknowList/GitHubAPI.swift index feea5a2..4157a81 100644 --- a/Sources/AcknowList/GitHubAPI.swift +++ b/Sources/AcknowList/GitHubAPI.swift @@ -66,7 +66,9 @@ open class GitHubAPI { let path = pathWithoutExtension(for: repository) let url = "https://api.github.com/repos\(path)/license" var request = URLRequest(url: URL(string: url)!) - request.allHTTPHeaderFields = ["Accept": "application/vnd.github.raw"] + request.allHTTPHeaderFields = [ + "Accept": "application/vnd.github.raw", + "X-GitHub-Api-Version": "2022-11-28"] return request } diff --git a/Tests/AcknowListTests/GitHubAPITests.swift b/Tests/AcknowListTests/GitHubAPITests.swift index 3822013..ec94078 100644 --- a/Tests/AcknowListTests/GitHubAPITests.swift +++ b/Tests/AcknowListTests/GitHubAPITests.swift @@ -25,7 +25,7 @@ class GitHubAPITests: XCTestCase { let request = GitHubAPI.getLicenseRequest(for: repoURL) XCTAssertEqual(request.url?.absoluteString, "https://api.github.com/repos/vtourraine/AcknowList/license") - XCTAssertEqual(request.allHTTPHeaderFields, ["Accept": "application/vnd.github.raw"]) + XCTAssertEqual(request.allHTTPHeaderFields, ["Accept": "application/vnd.github.raw", "X-GitHub-Api-Version": "2022-11-28"]) XCTAssertEqual(request.httpMethod, "GET") } }