You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

// Copyright © 2015 Abhishek Banthia
import Cocoa
import CoreLoggerKit
import EventKit
class EventCenter: NSObject {
private static var shared = EventCenter()
var eventStore: EKEventStore!
var calendar: EKCalendar?
var autoupdatingCalendar = NSCalendar.autoupdatingCurrent
var eventsForDate: [Date: [EventInfo]] = [:]
var filteredEvents: [Date: [EventInfo]] = [:]
@discardableResult class func sharedCenter() -> EventCenter {
return shared
}
override init() {
super.init()
refetchAll()
NotificationCenter.default.addObserver(self,
selector: #selector(EventCenter.eventStoreDidChange(_:)),
name: .EKEventStoreChanged,
object: nil)
}
6 years ago
@objc func eventStoreDidChange(_: Any) {
refetchAll()
}
4 years ago
deinit {
// Just to be super safe
NotificationCenter.default.removeObserver(self)
}
private func refetchAll() {
Logger.info("\nRefetching events from the store")
eventsForDate = [:]
filteredEvents = [:]
// We get events for a 120 day period.
// If the user uses a calendar often, this will be called frequently
fetchEvents(-40, 80)
}
}