Skip to content

Commit

Permalink
Fix permissions on macOS Sonoma (#70)
Browse files Browse the repository at this point in the history
The old API now fails 100% of the time and you have to use the new API.
This also starts printing the returned error in this case for the
future.
  • Loading branch information
keith authored Nov 9, 2023
1 parent a7a062f commit 886a6a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ name: Swift

jobs:
build:
runs-on: macos-latest
runs-on: macos-13
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: xcode-select
run: sudo xcode-select -s /Applications/Xcode_15.0.app
- name: Build
run: swift build -Xswiftc -warnings-as-errors
- name: Test
Expand Down
20 changes: 15 additions & 5 deletions Sources/RemindersLibrary/Reminders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,26 @@ public enum Priority: String, ExpressibleByArgument {
}

public final class Reminders {
public static func requestAccess() -> Bool {
public static func requestAccess() -> (Bool, Error?) {
let semaphore = DispatchSemaphore(value: 0)
var grantedAccess = false
Store.requestAccess(to: .reminder) { granted, _ in
grantedAccess = granted
semaphore.signal()
var returnError: Error? = nil
if #available(macOS 14.0, *) {
Store.requestFullAccessToReminders { granted, error in
grantedAccess = granted
returnError = error
semaphore.signal()
}
} else {
Store.requestAccess(to: .reminder) { granted, error in
grantedAccess = granted
returnError = error
semaphore.signal()
}
}

semaphore.wait()
return grantedAccess
return (grantedAccess, returnError)
}

func getListNames() -> [String] {
Expand Down
10 changes: 7 additions & 3 deletions Sources/reminders/main.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Darwin
import RemindersLibrary

if Reminders.requestAccess() {
switch Reminders.requestAccess() {
case (true, _):
CLI.main()
} else {
print("You need to grant reminders access")
case (false, let error):
print("error: you need to grant reminders access")
if let error {
print("error: \(error.localizedDescription)")
}
exit(1)
}

0 comments on commit 886a6a3

Please sign in to comment.