Browse Source

Sync setup..

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
75bcb10d9a
  1. 10
      Clocker/Overall App/DataStore.swift
  2. 16
      Clocker/Panel/ParentPanelController.swift
  3. 2
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  4. 14
      Clocker/Preferences/General/PreferencesViewController.swift

10
Clocker/Overall App/DataStore.swift

@ -46,8 +46,8 @@ class DataStore: NSObject {
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
setupSyncNotification() setupSyncNotification()
} }
func setupSyncNotification() { func setupSyncNotification() {
if shouldDisplay(.sync) { if shouldDisplay(.sync) {
ubiquitousStore = NSUbiquitousKeyValueStore.default ubiquitousStore = NSUbiquitousKeyValueStore.default
NotificationCenter.default.addObserver(self, NotificationCenter.default.addObserver(self,
@ -72,6 +72,8 @@ class DataStore: NSObject {
if cloudTimezones != currentTimezones { if cloudTimezones != currentTimezones {
Logger.info("Syncing local timezones with data from the ☁") Logger.info("Syncing local timezones with data from the ☁")
userDefaults.set(cloudTimezones, forKey: CLDefaultPreferenceKey) userDefaults.set(cloudTimezones, forKey: CLDefaultPreferenceKey)
NotificationCenter.default.post(name: DataStore.didSyncFromExternalSourceNotification,
object: self)
} }
} }
@ -201,3 +203,7 @@ class DataStore: NSObject {
return value.isEqual(to: NSNumber(value: 0)) return value.isEqual(to: NSNumber(value: 0))
} }
} }
extension DataStore {
public static let didSyncFromExternalSourceNotification: NSNotification.Name = .init("didSyncFromExternalSourceNotification")
}

16
Clocker/Panel/ParentPanelController.swift

@ -196,15 +196,13 @@ class ParentPanelController: NSWindowController {
name: NSNotification.Name.NSSystemTimeZoneDidChange, name: NSNotification.Name.NSSystemTimeZoneDidChange,
object: nil) object: nil)
if DataStore.shared().shouldDisplay(.sync) { NotificationCenter.default.addObserver(forName: DataStore.didSyncFromExternalSourceNotification,
NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification, object: self,
object: self, queue: OperationQueue.main)
queue: OperationQueue.main) { [weak self] _ in
{ [weak self] _ in if let sSelf = self {
if let sSelf = self { sSelf.mainTableView.reloadData()
sSelf.mainTableView.reloadData() sSelf.setScrollViewConstraint()
sSelf.setScrollViewConstraint()
}
} }
} }

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -359,7 +359,7 @@ class AppearanceViewController: ParentViewController {
previewPanelTableView.reloadData() previewPanelTableView.reloadData()
} }
@IBAction func toggleSync(_ sender: NSSegmentedControl) { @IBAction func toggleSync(_: NSSegmentedControl) {
DataStore.shared().setupSyncNotification() DataStore.shared().setupSyncNotification()
} }
} }

14
Clocker/Preferences/General/PreferencesViewController.swift

@ -93,14 +93,12 @@ class PreferencesViewController: ParentViewController {
name: NSNotification.Name.customLabelChanged, name: NSNotification.Name.customLabelChanged,
object: nil) object: nil)
if DataStore.shared().shouldDisplay(.sync) { NotificationCenter.default.addObserver(forName: DataStore.didSyncFromExternalSourceNotification,
NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification, object: self,
object: self, queue: OperationQueue.main)
queue: OperationQueue.main) { [weak self] _ in
{ [weak self] _ in if let sSelf = self {
if let sSelf = self { sSelf.refreshTimezoneTableView()
sSelf.refreshTimezoneTableView()
}
} }
} }

Loading…
Cancel
Save