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,6 +40,11 @@ class DataStore: NSObject {
}
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 {
return []
}
@ -47,6 +52,13 @@ class DataStore: NSObject {
return preferences
}
func setTimezones(_ timezones: [Data]?) {
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey)
// iCloud sync
NSUbiquitousKeyValueStore().set(timezones, forKey: CLDefaultPreferenceKey)
NSUbiquitousKeyValueStore().synchronize()
}
func menubarTimezones() -> [Data]? {
return timezones().filter {
let customTimezone = TimezoneData.customObject(from: $0)
@ -70,10 +82,6 @@ class DataStore: NSObject {
return shouldDisplayDateInMenubar
}
func setTimezones(_ timezones: [Data]?) {
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey)
}
func retrieve(key: String) -> Any? {
return userDefaults.object(forKey: key)
}

49
Clocker/Panel/ParentPanelController.swift

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

Loading…
Cancel
Save