From e3b6dca80feddae1877bcd66a10a9eb11421231d Mon Sep 17 00:00:00 2001 From: Vincent Tourraine Date: Tue, 9 Jan 2024 09:52:57 +0100 Subject: [PATCH 1/2] Fix open URL on macOS with SwiftUI #114 --- CHANGELOG.md | 1 + Sources/AcknowList/AcknowListSwiftUI.swift | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae4b174..a83271e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add `GitHubAPI` to get licenses from GitHub API - Update `AcknowListViewController` 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 09675f0..7340038 100644 --- a/Sources/AcknowList/AcknowListSwiftUI.swift +++ b/Sources/AcknowList/AcknowListSwiftUI.swift @@ -126,7 +126,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 }) { From c24c4a76fd66b56016b094455831f5d32fca7ecc Mon Sep 17 00:00:00 2001 From: Vincent Tourraine Date: Tue, 16 Jan 2024 17:12:06 +0100 Subject: [PATCH 2/2] Add GitHub API version HTTP header --- Sources/AcknowList/GitHubAPI.swift | 4 +++- Tests/AcknowListTests/GitHubAPITests.swift | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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") } }