Skip to content

Commit

Permalink
Fixed permissions (finally)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-cqd committed Feb 12, 2024
1 parent ec3360a commit c56be11
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 95 deletions.
18 changes: 6 additions & 12 deletions Cami.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 */; };
Expand All @@ -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 */; };
Expand Down Expand Up @@ -200,7 +198,6 @@
467F3DCC2B04C50B00F10899 /* CalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarView.swift; sourceTree = "<group>"; };
467F3DCE2B04C76400F10899 /* ContactHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactHelper.swift; sourceTree = "<group>"; };
46934D912B78F5130025ADF2 /* sonar-project.properties */ = {isa = PBXFileReference; lastKnownFileType = text; path = "sonar-project.properties"; sourceTree = "<group>"; };
46968DB42B05188A00EA1C8D /* ReminderHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReminderHelper.swift; sourceTree = "<group>"; };
46968DB72B0518AB00EA1C8D /* CamiHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CamiHelper.swift; sourceTree = "<group>"; };
46968DC32B06148500EA1C8D /* Calendars.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Calendars.swift; sourceTree = "<group>"; };
469853112B0C19AF00A1F35B /* DayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayView.swift; sourceTree = "<group>"; };
Expand All @@ -226,7 +223,7 @@
46CC7E102AF78DC700607AAF /* CamiWidgetEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CamiWidgetEntry.swift; sourceTree = "<group>"; };
46CC7E132AF7944800607AAF /* EKEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EKEvent.swift; sourceTree = "<group>"; };
46CC7E162AF7946700607AAF /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
46CC7E1D2AF795EF00607AAF /* CalendarHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarHelper.swift; sourceTree = "<group>"; };
46CC7E1D2AF795EF00607AAF /* EventHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventHelper.swift; sourceTree = "<group>"; };
46E0221A2B7A6B57005725B0 /* CamiWidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CamiWidgetExtension.entitlements; sourceTree = "<group>"; };
46E58C702B75A468003B48A0 /* InformationModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InformationModalView.swift; sourceTree = "<group>"; };
46E58C722B75A4A1003B48A0 /* FAQInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FAQInformation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 2 additions & 2 deletions Cami/Extensions/Notifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
40 changes: 20 additions & 20 deletions Cami/Model/PermissionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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)
}
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Cami/View/EditEventViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Cami/View/Settings/PermissionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
10 changes: 5 additions & 5 deletions Multiplatform/Custom Types/Day.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ 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!
}

@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!
}

@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!
}
Expand All @@ -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
Expand All @@ -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!
}
Expand Down
2 changes: 1 addition & 1 deletion Multiplatform/Extensions/Calendars.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension Calendars: Observable {
extension Array<String> {
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
Expand Down
12 changes: 6 additions & 6 deletions Multiplatform/Helper/CamiHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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() {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -97,7 +97,7 @@ struct CamiHelper {
from date: Date,
during days: Int = 365
) -> Events {
return CalendarHelper.birthdays(
return EventHelper.birthdays(
from: date,
during: days
)
Expand Down
Loading

0 comments on commit c56be11

Please sign in to comment.