mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 09:28:38 +00:00
Added handling of unauthorised access to calendar
This commit is contained in:
parent
de555a1265
commit
7d3a34053a
@ -145,7 +145,7 @@ class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
|||||||
|
|
||||||
|
|
||||||
func getBackgroundColor(startDate: Date) -> NSColor {
|
func getBackgroundColor(startDate: Date) -> NSColor {
|
||||||
let distance = Date().timeIntervalSinceReferenceDate/60 - startDate.timeIntervalSinceReferenceDate/60 // Get time difference in minutes
|
let distance = startDate.timeIntervalSinceReferenceDate/60 - Date().timeIntervalSinceReferenceDate/60 // Get time difference in minutes
|
||||||
if (distance < 0 as TimeInterval) { // If it's in the past, draw as blue
|
if (distance < 0 as TimeInterval) { // If it's in the past, draw as blue
|
||||||
return NSColor.systemBlue
|
return NSColor.systemBlue
|
||||||
} else if (distance < 30 as TimeInterval) { // Less than 30 minutes, backround is red
|
} else if (distance < 30 as TimeInterval) { // Less than 30 minutes, backround is red
|
||||||
@ -214,23 +214,31 @@ class UpNextCalenderSource : IUpNextSource {
|
|||||||
static public let bundleIdentifier: String = "com.apple.iCal"
|
static public let bundleIdentifier: String = "com.apple.iCal"
|
||||||
|
|
||||||
public var hasPermission: Bool = false
|
public var hasPermission: Bool = false
|
||||||
private var eventStore = EKEventStore()
|
private var eventStore : EKEventStore
|
||||||
internal var updateCallback: () -> Void
|
internal var updateCallback: () -> Void
|
||||||
|
|
||||||
required init(updateCallback: @escaping () -> Void = {}) {
|
required init(updateCallback: @escaping () -> Void = {}) {
|
||||||
self.updateCallback = updateCallback
|
self.updateCallback = updateCallback
|
||||||
|
eventStore = EKEventStore()
|
||||||
NotificationCenter.default.addObserver(forName: .EKEventStoreChanged, object: eventStore, queue: nil, using: handleUpdate)
|
NotificationCenter.default.addObserver(forName: .EKEventStoreChanged, object: eventStore, queue: nil, using: handleUpdate)
|
||||||
|
let authStatus = EKEventStore.authorizationStatus(for: .event)
|
||||||
eventStore.requestAccess(to: .event){ granted, error in
|
if (authStatus != .authorized) {
|
||||||
self.hasPermission = granted;
|
eventStore.requestAccess(to: .event){ granted, error in
|
||||||
self.handleUpdate(note: Notification(name: Notification.Name("refresh view")))
|
self.hasPermission = granted;
|
||||||
if(!granted) {
|
self.handleUpdate()
|
||||||
NSLog("Error: MTMR UpNextBarWidget not given calendar access.")
|
if(!granted) {
|
||||||
return
|
NSLog("Error: MTMR UpNextBarWidget not given calendar access.")
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.handleUpdate()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public func handleUpdate() {
|
||||||
|
self.handleUpdate(note: Notification(name: Notification.Name("refresh view")))
|
||||||
|
}
|
||||||
public func handleUpdate(note: Notification) {
|
public func handleUpdate(note: Notification) {
|
||||||
self.updateCallback()
|
self.updateCallback()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user