From c56be112c3af41f3b945de8c4070611acdb76329 Mon Sep 17 00:00:00 2001 From: Gigi <42325924+g-cqd@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:48:18 +0100 Subject: [PATCH] Fixed permissions (finally) --- Cami.xcodeproj/project.pbxproj | 18 +++----- Cami/Extensions/Notifications.swift | 4 +- Cami/Model/PermissionModel.swift | 40 ++++++++-------- Cami/View/EditEventViewController.swift | 2 +- Cami/View/Settings/PermissionsView.swift | 2 +- Multiplatform/Custom Types/Day.swift | 10 ++-- Multiplatform/Extensions/Calendars.swift | 2 +- Multiplatform/Helper/CamiHelper.swift | 12 ++--- ...CalendarHelper.swift => EventHelper.swift} | 46 +++++++++++++++++-- Multiplatform/Helper/ReminderHelper.swift | 42 ----------------- 10 files changed, 83 insertions(+), 95 deletions(-) rename Multiplatform/Helper/{CalendarHelper.swift => EventHelper.swift} (76%) delete mode 100644 Multiplatform/Helper/ReminderHelper.swift diff --git a/Cami.xcodeproj/project.pbxproj b/Cami.xcodeproj/project.pbxproj index e0a3f21..00abdcf 100644 --- a/Cami.xcodeproj/project.pbxproj +++ b/Cami.xcodeproj/project.pbxproj @@ -50,7 +50,6 @@ 467F3DCB2B04C49200F10899 /* PermissionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 467F3DCA2B04C49200F10899 /* PermissionsView.swift */; }; 467F3DCD2B04C50B00F10899 /* CalendarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 467F3DCC2B04C50B00F10899 /* CalendarView.swift */; }; 467F3DCF2B04C76400F10899 /* ContactHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 467F3DCE2B04C76400F10899 /* ContactHelper.swift */; }; - 46968DB52B05188A00EA1C8D /* ReminderHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46968DB42B05188A00EA1C8D /* ReminderHelper.swift */; }; 46968DB82B0518AB00EA1C8D /* CamiHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46968DB72B0518AB00EA1C8D /* CamiHelper.swift */; }; 46968DC42B06148500EA1C8D /* Calendars.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46968DC32B06148500EA1C8D /* Calendars.swift */; }; 469853122B0C19AF00A1F35B /* DayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 469853112B0C19AF00A1F35B /* DayView.swift */; }; @@ -85,10 +84,9 @@ 46B1608C2B07D90A00A44FBF /* EdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 460CAB202B0669900059B2F7 /* EdgeInsets.swift */; }; 46B1608D2B07D90A00A44FBF /* EKEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CC7E132AF7944800607AAF /* EKEvent.swift */; }; 46B1608F2B07D90A00A44FBF /* Calendars.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46968DC32B06148500EA1C8D /* Calendars.swift */; }; - 46B160912B07D90D00A44FBF /* CalendarHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CC7E1D2AF795EF00607AAF /* CalendarHelper.swift */; }; + 46B160912B07D90D00A44FBF /* EventHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CC7E1D2AF795EF00607AAF /* EventHelper.swift */; }; 46B160922B07D90D00A44FBF /* ContactHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 467F3DCE2B04C76400F10899 /* ContactHelper.swift */; }; 46B160932B07D90D00A44FBF /* CamiHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46968DB72B0518AB00EA1C8D /* CamiHelper.swift */; }; - 46B160942B07D90D00A44FBF /* ReminderHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46968DB42B05188A00EA1C8D /* ReminderHelper.swift */; }; 46B160952B07D91000A44FBF /* TypeAliases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46BDFBFA2AFA8AED00B4C7CB /* TypeAliases.swift */; }; 46B160962B07D91000A44FBF /* PermissionSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461CF49F2B035F15003D9293 /* PermissionSet.swift */; }; 46B160972B07D91000A44FBF /* WidgetFamilySet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 460CAB142B0652470059B2F7 /* WidgetFamilySet.swift */; }; @@ -108,7 +106,7 @@ 46BDFBFB2AFA8AED00B4C7CB /* TypeAliases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46BDFBFA2AFA8AED00B4C7CB /* TypeAliases.swift */; }; 46CC7E142AF7944800607AAF /* EKEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CC7E132AF7944800607AAF /* EKEvent.swift */; }; 46CC7E172AF7946700607AAF /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CC7E162AF7946700607AAF /* Date.swift */; }; - 46CC7E1E2AF795EF00607AAF /* CalendarHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CC7E1D2AF795EF00607AAF /* CalendarHelper.swift */; }; + 46CC7E1E2AF795EF00607AAF /* EventHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CC7E1D2AF795EF00607AAF /* EventHelper.swift */; }; 46E0222F2B7A72B7005725B0 /* Collections in Frameworks */ = {isa = PBXBuildFile; productRef = 46E0222E2B7A72B7005725B0 /* Collections */; }; 46E022312B7A72B7005725B0 /* DequeModule in Frameworks */ = {isa = PBXBuildFile; productRef = 46E022302B7A72B7005725B0 /* DequeModule */; }; 46E022332B7A72B7005725B0 /* OrderedCollections in Frameworks */ = {isa = PBXBuildFile; productRef = 46E022322B7A72B7005725B0 /* OrderedCollections */; }; @@ -200,7 +198,6 @@ 467F3DCC2B04C50B00F10899 /* CalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarView.swift; sourceTree = ""; }; 467F3DCE2B04C76400F10899 /* ContactHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactHelper.swift; sourceTree = ""; }; 46934D912B78F5130025ADF2 /* sonar-project.properties */ = {isa = PBXFileReference; lastKnownFileType = text; path = "sonar-project.properties"; sourceTree = ""; }; - 46968DB42B05188A00EA1C8D /* ReminderHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReminderHelper.swift; sourceTree = ""; }; 46968DB72B0518AB00EA1C8D /* CamiHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CamiHelper.swift; sourceTree = ""; }; 46968DC32B06148500EA1C8D /* Calendars.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Calendars.swift; sourceTree = ""; }; 469853112B0C19AF00A1F35B /* DayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayView.swift; sourceTree = ""; }; @@ -226,7 +223,7 @@ 46CC7E102AF78DC700607AAF /* CamiWidgetEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CamiWidgetEntry.swift; sourceTree = ""; }; 46CC7E132AF7944800607AAF /* EKEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EKEvent.swift; sourceTree = ""; }; 46CC7E162AF7946700607AAF /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; - 46CC7E1D2AF795EF00607AAF /* CalendarHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarHelper.swift; sourceTree = ""; }; + 46CC7E1D2AF795EF00607AAF /* EventHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventHelper.swift; sourceTree = ""; }; 46E0221A2B7A6B57005725B0 /* CamiWidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CamiWidgetExtension.entitlements; sourceTree = ""; }; 46E58C702B75A468003B48A0 /* InformationModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InformationModalView.swift; sourceTree = ""; }; 46E58C722B75A4A1003B48A0 /* FAQInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FAQInformation.swift; sourceTree = ""; }; @@ -484,9 +481,8 @@ isa = PBXGroup; children = ( 46968DB72B0518AB00EA1C8D /* CamiHelper.swift */, - 46CC7E1D2AF795EF00607AAF /* CalendarHelper.swift */, + 46CC7E1D2AF795EF00607AAF /* EventHelper.swift */, 467F3DCE2B04C76400F10899 /* ContactHelper.swift */, - 46968DB42B05188A00EA1C8D /* ReminderHelper.swift */, ); path = Helper; sourceTree = ""; @@ -691,7 +687,6 @@ 4616493A2B09B57500F7E7E1 /* MonthWeekRow.swift in Sources */, 46F331422B7812D70060FA8B /* Notifications.swift in Sources */, 460CAB122B0650370059B2F7 /* Rounded.swift in Sources */, - 46968DB52B05188A00EA1C8D /* ReminderHelper.swift in Sources */, 460CAB1E2B06602E0059B2F7 /* Pad.swift in Sources */, 469E05992B0922B600F3263D /* CamiWidgetConfiguration.swift in Sources */, 4611A4BE2B7A5287007D85ED /* OSLog.swift in Sources */, @@ -708,7 +703,7 @@ 460CAB2A2B06C5410059B2F7 /* HiddenIf.swift in Sources */, 4655330F2AF4EA69000B537B /* ContentView.swift in Sources */, 461D69112B0DF2B000A600D7 /* EventView.swift in Sources */, - 46CC7E1E2AF795EF00607AAF /* CalendarHelper.swift in Sources */, + 46CC7E1E2AF795EF00607AAF /* EventHelper.swift in Sources */, 46225B012B58970900765185 /* EditEventViewController.swift in Sources */, 46E58C752B75A4E7003B48A0 /* FAQInformationModel.swift in Sources */, 469E058A2B086C3100F3263D /* WidgetCalendarEntity.swift in Sources */, @@ -777,14 +772,13 @@ 46B160832B07D90500A44FBF /* Pad.swift in Sources */, 469E059D2B0956B500F3263D /* EventDict.swift in Sources */, 4673449F2B7907FE00470979 /* PermissionStatus.swift in Sources */, - 46B160942B07D90D00A44FBF /* ReminderHelper.swift in Sources */, 46B160842B07D90500A44FBF /* MiniBadge.swift in Sources */, 46B1608B2B07D90A00A44FBF /* Bool.swift in Sources */, 46B160872B07D90A00A44FBF /* RectangleCornerRadii.swift in Sources */, 469E05812B08172700F3263D /* AllDayStyleEnum.swift in Sources */, 46B1609F2B07D9A100A44FBF /* CamiWidgetProvider.swift in Sources */, 46F331432B781AFA0060FA8B /* Notifications.swift in Sources */, - 46B160912B07D90D00A44FBF /* CalendarHelper.swift in Sources */, + 46B160912B07D90D00A44FBF /* EventHelper.swift in Sources */, 46B160A42B07D9A100A44FBF /* RemainingTimeComponent.swift in Sources */, 46B160862B07D90A00A44FBF /* Date.swift in Sources */, 46B160922B07D90D00A44FBF /* ContactHelper.swift in Sources */, diff --git a/Cami/Extensions/Notifications.swift b/Cami/Extensions/Notifications.swift index 9114c4c..576a091 100644 --- a/Cami/Extensions/Notifications.swift +++ b/Cami/Extensions/Notifications.swift @@ -8,11 +8,11 @@ import Foundation extension Notification.Name { - static let requestEventsAccess = Notification.Name("requestEventsAccess") + static let requestCalendarsAccess = Notification.Name("requestCalendarsAccess") static let requestContactsAccess = Notification.Name("requestContactsAccess") static let requestRemindersAccess = Notification.Name("requestRemindersAccess") static let requestAccess = Notification.Name("requestAccess") - static let eventsAccessUpdated = Notification.Name("eventsAccessUpdated") + static let calendarsAccessUpdated = Notification.Name("calendarsAccessUpdated") static let contactsAccessUpdated = Notification.Name("contactsAccessUpdated") static let remindersAccessUpdated = Notification.Name("remindersAccessUpdated") static let accessUpdated = Notification.Name("accessUpdated") diff --git a/Cami/Model/PermissionModel.swift b/Cami/Model/PermissionModel.swift index fd2a550..cb96c3e 100644 --- a/Cami/Model/PermissionModel.swift +++ b/Cami/Model/PermissionModel.swift @@ -28,29 +28,29 @@ final class PermissionModel: ObservableObject { self.events = switch EKEventStore.authorizationStatus(for: .event) { case .fullAccess: - AuthSet.calendars + PermissionSet.calendars case .notDetermined: - AuthSet.none + PermissionSet.none default: - AuthSet.restrictedCalendars + PermissionSet.restrictedCalendars } self.contacts = switch CNContactStore.authorizationStatus(for: .contacts) { case .authorized: - AuthSet.contacts + PermissionSet.contacts case .notDetermined: - AuthSet.none + PermissionSet.none default: - AuthSet.restrictedContacts + PermissionSet.restrictedContacts } self.reminders = switch EKEventStore.authorizationStatus(for: .reminder) { case .fullAccess: - AuthSet.reminders + PermissionSet.reminders case .notDetermined: - AuthSet.none + PermissionSet.none default: - AuthSet.restrictedReminders + PermissionSet.restrictedReminders } self.global = PermissionSet([ @@ -73,16 +73,16 @@ extension PermissionModel { @objc func requestAccess() async { Logger.perms.debug("Requesting Full Access") - self.requestEventsAccess() + self.requestCalendarsAccess() self.requestContactsAccess() self.requestRemindersAccess() } - @objc func requestEventsAccess() { + @objc func requestCalendarsAccess() { Logger.perms.debug("Requesting Calendars Access") - CalendarHelper.requestAccess { result in + EventHelper.requestCalendarsAccess { result in Logger.perms.debug("\(String(describing: result))") - Self.center.post(name: .eventsAccessUpdated, object: nil) + Self.center.post(name: .calendarsAccessUpdated, object: nil) } } @@ -96,7 +96,7 @@ extension PermissionModel { @objc func requestRemindersAccess() { Logger.perms.debug("Requesting Reminders Access") - ReminderHelper.requestAccess { result in + EventHelper.requestRemindersAccess { result in Logger.perms.debug("\(String(describing: result))") Self.center.post(name: .remindersAccessUpdated, object: nil) } @@ -142,13 +142,13 @@ extension PermissionModel { private func addObservers() { Self.center.addObserver( self, - selector: #selector(requestAccess), + selector: #selector(requestCalendarsAccess), name: .requestAccess, object: nil ) Self.center.addObserver( self, - selector: #selector(requestEventsAccess), - name: .requestEventsAccess, object: nil + selector: #selector(requestCalendarsAccess), + name: .requestCalendarsAccess, object: nil ) Self.center.addObserver( self, @@ -164,7 +164,7 @@ extension PermissionModel { Self.center.addObserver( self, selector: #selector(updateAccess), - name: .eventsAccessUpdated, object: nil + name: .calendarsAccessUpdated, object: nil ) Self.center.addObserver( self, @@ -180,10 +180,10 @@ extension PermissionModel { private func removeObservers() { Self.center.removeObserver(self, name: .requestAccess, object: nil) - Self.center.removeObserver(self, name: .requestEventsAccess, object: nil) + Self.center.removeObserver(self, name: .requestCalendarsAccess, object: nil) Self.center.removeObserver(self, name: .requestContactsAccess, object: nil) Self.center.removeObserver(self, name: .requestRemindersAccess, object: nil) - Self.center.removeObserver(self, name: .eventsAccessUpdated, object: nil) + Self.center.removeObserver(self, name: .calendarsAccessUpdated, object: nil) Self.center.removeObserver(self, name: .contactsAccessUpdated, object: nil) Self.center.removeObserver(self, name: .remindersAccessUpdated, object: nil) } diff --git a/Cami/View/EditEventViewController.swift b/Cami/View/EditEventViewController.swift index a837e72..a30e6eb 100644 --- a/Cami/View/EditEventViewController.swift +++ b/Cami/View/EditEventViewController.swift @@ -38,7 +38,7 @@ struct EditEventViewController: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> EKEventEditViewController { let eventEditViewController = EKEventEditViewController() eventEditViewController.event = event - eventEditViewController.eventStore = CalendarHelper.store + eventEditViewController.eventStore = EventHelper.store eventEditViewController.editViewDelegate = context.coordinator return eventEditViewController } diff --git a/Cami/View/Settings/PermissionsView.swift b/Cami/View/Settings/PermissionsView.swift index c0c9705..f32ab6c 100644 --- a/Cami/View/Settings/PermissionsView.swift +++ b/Cami/View/Settings/PermissionsView.swift @@ -36,7 +36,7 @@ struct PermissionsView: View { status: perms.global.calendars, title: "Calendars", label: "Access to calendars authorized", - notificationName: .requestEventsAccess, + notificationName: .requestCalendarsAccess, description: "Cami ONLY uses your calendars informations to display events in widgets.", restrictedDescription: "Review Cami access to your calendars." ) diff --git a/Multiplatform/Custom Types/Day.swift b/Multiplatform/Custom Types/Day.swift index cf44009..a65ba2c 100644 --- a/Multiplatform/Custom Types/Day.swift +++ b/Multiplatform/Custom Types/Day.swift @@ -68,7 +68,7 @@ import EventKit let calendars = self.sourceCalendars?.ekCalendars ?? self.sourceCalendars?.identifiers?.asEKCalendars() ?? CamiHelper.allCalendars - self.events = CalendarHelper.events(from: calendars, during: 1, relativeTo: date ) + self.events = EventHelper.events(from: calendars, during: 1, relativeTo: date ) } return self.events! } @@ -76,7 +76,7 @@ import EventKit @discardableResult func lazyInitEvents(from calendars: [String]) async -> Events { if self.events == nil { - self.events = CalendarHelper.events(from: calendars.asEKCalendars(), during: 1, relativeTo: date ) + self.events = EventHelper.events(from: calendars.asEKCalendars(), during: 1, relativeTo: date ) } return self.events! } @@ -84,7 +84,7 @@ import EventKit @discardableResult func lazyInitEvents(from calendars: Calendars) async -> Events { if self.events == nil { - self.events = CalendarHelper.events(from: calendars, during: 1, relativeTo: date ) + self.events = EventHelper.events(from: calendars, during: 1, relativeTo: date ) } return self.events! } @@ -94,7 +94,7 @@ import EventKit if events == nil && self.calendars == nil { let unwrappedEvents: Events = events ?? self.events - ?? CalendarHelper.events( + ?? EventHelper.events( from: CamiHelper.allCalendars, during: 1, relativeTo: self.date @@ -110,7 +110,7 @@ import EventKit @discardableResult func lazyBirthdays() async -> Events { if self.birthdays == nil { - self.birthdays = CalendarHelper.birthdays(from: self.date, during: 1) + self.birthdays = EventHelper.birthdays(from: self.date, during: 1) } return self.birthdays! } diff --git a/Multiplatform/Extensions/Calendars.swift b/Multiplatform/Extensions/Calendars.swift index 7267872..7ccfb80 100644 --- a/Multiplatform/Extensions/Calendars.swift +++ b/Multiplatform/Extensions/Calendars.swift @@ -19,7 +19,7 @@ extension Calendars: Observable { extension Array { func asEKCalendars() -> Calendars { let optionalCalendarList = self.map { calendar in - CalendarHelper.store.calendar(withIdentifier: calendar) + EventHelper.store.calendar(withIdentifier: calendar) } return optionalCalendarList.filter { calendar in calendar != nil diff --git a/Multiplatform/Helper/CamiHelper.swift b/Multiplatform/Helper/CamiHelper.swift index 942f99b..bd3aa0b 100644 --- a/Multiplatform/Helper/CamiHelper.swift +++ b/Multiplatform/Helper/CamiHelper.swift @@ -12,7 +12,7 @@ import Contacts struct CamiHelper { public static var allCalendars: Calendars { - CalendarHelper.store.calendars(for: .event).filter { calendar in + EventHelper.store.calendars(for: .event).filter { calendar in calendar.type != .birthday } } @@ -26,13 +26,13 @@ struct CamiHelper { } public static var birthdayCalendar: EKCalendar? { - CalendarHelper.store.calendars(for: .event).first { calendar in + EventHelper.store.calendars(for: .event).first { calendar in calendar.type == .birthday } } public static func requestEventAccess() { - PermissionModel.center.post(name: .requestEventsAccess, object: nil) + PermissionModel.center.post(name: .requestCalendarsAccess, object: nil) } public static func requestReminderAccess() { @@ -53,7 +53,7 @@ struct CamiHelper { where filter: ((EKEvent) -> Bool)? = nil, relativeTo date: Date ) -> EventDict { - return CalendarHelper.events( + return EventHelper.events( from: calendars, during: days, where: filter, @@ -69,7 +69,7 @@ struct CamiHelper { where filter: ((EKEvent) -> Bool)? = nil, relativeTo date: Date ) -> EventDict { - return CalendarHelper.events( + return EventHelper.events( from: calendars, during: days, where: filter, @@ -97,7 +97,7 @@ struct CamiHelper { from date: Date, during days: Int = 365 ) -> Events { - return CalendarHelper.birthdays( + return EventHelper.birthdays( from: date, during: days ) diff --git a/Multiplatform/Helper/CalendarHelper.swift b/Multiplatform/Helper/EventHelper.swift similarity index 76% rename from Multiplatform/Helper/CalendarHelper.swift rename to Multiplatform/Helper/EventHelper.swift index cff1eaf..484f4ff 100644 --- a/Multiplatform/Helper/CalendarHelper.swift +++ b/Multiplatform/Helper/EventHelper.swift @@ -9,11 +9,11 @@ import Foundation import EventKit import OSLog -struct CalendarHelper { +struct EventHelper { static let store: EKEventStore = .init() - public static var authorizationStatus: Bool { + public static var calendarsAccess: Bool { let authorizationStatus: EKAuthorizationStatus = EKEventStore.authorizationStatus(for: .event) return switch authorizationStatus { case .fullAccess: @@ -23,7 +23,17 @@ struct CalendarHelper { } } - public static func requestAccess() async -> AuthSet { + public static var remindersAccess: Bool { + let authorizationStatus: EKAuthorizationStatus = EKEventStore.authorizationStatus(for: .reminder) + return switch authorizationStatus { + case .fullAccess: + true + default: + false + } + } + + public static func requestCalendarsAccess() async -> PermissionSet { do { let result = try await Self.store.requestFullAccessToEvents() Logger.perms.info("CalendarHelper -> \(String(describing: result))") @@ -34,7 +44,7 @@ struct CalendarHelper { return .none } - public static func requestAccess( + public static func requestCalendarsAccess( _ callback: @escaping (PermissionSet) -> Void ) { Self.store.requestFullAccessToEvents { result, error in @@ -49,13 +59,39 @@ struct CalendarHelper { Self.store.refreshSourcesIfNecessary() } + public static func requestRemindersAccess() async -> PermissionSet { + do { + return try await Self.store.requestFullAccessToReminders() + ? .reminders + : .restrictedReminders + } catch { + Logger.perms.error("\(String(describing: error))") + } + Logger.perms.error("ReminderHelper() -> .none") + return .none + } + + public static func requestRemindersAccess( + callback: @escaping (PermissionSet) -> Void + ) { + Self.store.requestFullAccessToReminders { result, error in + if error != nil { + Logger.perms.error("\(String(describing: error))") + callback(.none) + } else { + Logger.perms.error("ReminderHelper() -> \(result.description)") + callback(result ? .reminders : .none) + } + } + } + public static func events( from calendars: [String] = CamiHelper.allCalendars.asIdentifiers, during days: Int = 30, where filter: ((EKEvent) -> Bool)? = nil, relativeTo date: Date ) -> Events { - CalendarHelper.events( + EventHelper.events( from: calendars.asEKCalendars(), during: days, where: filter, diff --git a/Multiplatform/Helper/ReminderHelper.swift b/Multiplatform/Helper/ReminderHelper.swift deleted file mode 100644 index 4aeb579..0000000 --- a/Multiplatform/Helper/ReminderHelper.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// ReminderHelper.swift -// Cami -// -// Created by Guillaume Coquard on 15/11/23. -// - -import Foundation -import EventKit -import OSLog - -struct ReminderHelper { - - static let store: EKEventStore = .init() - - public static func requestAccess() async -> PermissionSet { - do { - return try await Self.store.requestFullAccessToReminders() - ? .reminders - : .restrictedReminders - } catch { - Logger.perms.error("\(String(describing: error))") - } - Logger.perms.error("ReminderHelper() -> .none") - return .none - } - - public static func requestAccess( - callback: @escaping (PermissionSet) -> Void - ) { - Self.store.requestFullAccessToReminders { result, error in - if error != nil { - Logger.perms.error("\(String(describing: error))") - callback(.none) - } else { - Logger.perms.error("ReminderHelper() -> \(result.description)") - callback(result ? .reminders : .none) - } - } - } - -}