Browse Source

Backing store update.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
7e0cef7b4a
  1. 16
      Clocker/Overall App/DataStore.swift
  2. 49
      Clocker/Panel/ParentPanelController.swift

16
Clocker/Overall App/DataStore.swift

@ -40,12 +40,24 @@ class DataStore: NSObject {
} }
func timezones() -> [Data] { func timezones() -> [Data] {
if let cloudPreferences = NSUbiquitousKeyValueStore().object(forKey: CLDefaultPreferenceKey) as? [Data] {
Logger.info("Returning preferences from NSUbiquitousKeyValueStore")
return cloudPreferences
}
guard let preferences = userDefaults.object(forKey: CLDefaultPreferenceKey) as? [Data] else { guard let preferences = userDefaults.object(forKey: CLDefaultPreferenceKey) as? [Data] else {
return [] return []
} }
return preferences return preferences
} }
func setTimezones(_ timezones: [Data]?) {
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey)
// iCloud sync
NSUbiquitousKeyValueStore().set(timezones, forKey: CLDefaultPreferenceKey)
NSUbiquitousKeyValueStore().synchronize()
}
func menubarTimezones() -> [Data]? { func menubarTimezones() -> [Data]? {
return timezones().filter { return timezones().filter {
@ -70,10 +82,6 @@ class DataStore: NSObject {
return shouldDisplayDateInMenubar return shouldDisplayDateInMenubar
} }
func setTimezones(_ timezones: [Data]?) {
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey)
}
func retrieve(key: String) -> Any? { func retrieve(key: String) -> Any? {
return userDefaults.object(forKey: key) return userDefaults.object(forKey: key)
} }

49
Clocker/Panel/ParentPanelController.swift

@ -153,36 +153,53 @@ class ParentPanelController: NSWindowController {
override func awakeFromNib() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
// Setup table
mainTableView.backgroundColor = NSColor.clear mainTableView.backgroundColor = NSColor.clear
mainTableView.selectionHighlightStyle = .none mainTableView.selectionHighlightStyle = .none
mainTableView.enclosingScrollView?.hasVerticalScroller = false mainTableView.enclosingScrollView?.hasVerticalScroller = false
if #available(OSX 11.0, *) {
mainTableView.style = .fullWidth
}
// Setup images
let sharedThemer = Themer.shared() let sharedThemer = Themer.shared()
shutdownButton.image = sharedThemer.shutdownImage() shutdownButton.image = sharedThemer.shutdownImage()
preferencesButton.image = sharedThemer.preferenceImage() preferencesButton.image = sharedThemer.preferenceImage()
pinButton.image = sharedThemer.pinImage() pinButton.image = sharedThemer.pinImage()
sharingButton.image = sharedThemer.sharingImage() sharingButton.image = sharedThemer.sharingImage()
if let upcomingView = upcomingEventContainerView { // Setup KVO observers for user default changes
upcomingView.setAccessibility("UpcomingEventView")
}
setupObservers() setupObservers()
updateReviewViewFontColor() updateReviewViewFontColor()
// Setup layers
futureSliderView.wantsLayer = true futureSliderView.wantsLayer = true
reviewView.wantsLayer = true reviewView.wantsLayer = true
// Setup notifications
NotificationCenter.default.addObserver(self, NotificationCenter.default.addObserver(self,
selector: #selector(themeChanged), selector: #selector(themeChanged),
name: Notification.Name.themeDidChange, name: Notification.Name.themeDidChange,
object: nil) object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(systemTimezoneDidChange),
name: NSNotification.Name.NSSystemTimeZoneDidChange,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(ubiquitousStoreDidChange),
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: nil)
// Setup upcoming events view
upcomingEventContainerView.setAccessibility("UpcomingEventView")
determineUpcomingViewVisibility() determineUpcomingViewVisibility()
setupUpcomingEventViewCollectionViewIfNeccesary()
// Setup colors based on the curren theme
themeChanged() themeChanged()
// UI adjustments based on user preferences
if DataStore.shared().timezones().isEmpty || DataStore.shared().shouldDisplay(.futureSlider) == false { if DataStore.shared().timezones().isEmpty || DataStore.shared().shouldDisplay(.futureSlider) == false {
futureSliderView.isHidden = true futureSliderView.isHidden = true
if modernContainerView != nil { if modernContainerView != nil {
@ -203,22 +220,10 @@ class ParentPanelController: NSWindowController {
} }
} }
// More UI adjustments
sharingButton.sendAction(on: .leftMouseDown) sharingButton.sendAction(on: .leftMouseDown)
adjustFutureSliderBasedOnPreferences() adjustFutureSliderBasedOnPreferences()
NotificationCenter.default.addObserver(self,
selector: #selector(timezoneGonnaChange),
name: NSNotification.Name.NSSystemTimeZoneDidChange,
object: nil)
if #available(OSX 11.0, *) {
mainTableView.style = .fullWidth
}
setupModernSliderIfNeccessary() setupModernSliderIfNeccessary()
setupUpcomingEventViewCollectionViewIfNeccesary()
if roundedDateView != nil { if roundedDateView != nil {
setupRoundedDateView() setupRoundedDateView()
} }
@ -231,7 +236,7 @@ class ParentPanelController: NSWindowController {
roundedDateView.layer?.backgroundColor = Themer.shared().textBackgroundColor().cgColor roundedDateView.layer?.backgroundColor = Themer.shared().textBackgroundColor().cgColor
} }
@objc func timezoneGonnaChange() { @objc func systemTimezoneDidChange() {
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
/* /*
let locationController = LocationController.sharedController() let locationController = LocationController.sharedController()
@ -241,6 +246,14 @@ class ParentPanelController: NSWindowController {
coordinates: nil) coordinates: nil)
} }
} }
// Backing defaults changed
@objc func ubiquitousStoreDidChange() {
OperationQueue.main.addOperation {
self.mainTableView.reloadData()
self.setScrollViewConstraint()
}
}
private func updateHomeObject(with customLabel: String, coordinates: CLLocationCoordinate2D?) { private func updateHomeObject(with customLabel: String, coordinates: CLLocationCoordinate2D?) {
let timezones = DataStore.shared().timezones() let timezones = DataStore.shared().timezones()

Loading…
Cancel
Save