Browse Source

Sync setup..

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

6
Clocker/Overall App/DataStore.swift

@ -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")
}

4
Clocker/Panel/ParentPanelController.swift

@ -196,8 +196,7 @@ 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
@ -206,7 +205,6 @@ class ParentPanelController: NSWindowController {
sSelf.setScrollViewConstraint() sSelf.setScrollViewConstraint()
} }
} }
}
// Setup upcoming events view // Setup upcoming events view
upcomingEventContainerView.setAccessibility("UpcomingEventView") upcomingEventContainerView.setAccessibility("UpcomingEventView")

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()
} }
} }

4
Clocker/Preferences/General/PreferencesViewController.swift

@ -93,8 +93,7 @@ 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
@ -102,7 +101,6 @@ class PreferencesViewController: ParentViewController {
sSelf.refreshTimezoneTableView() sSelf.refreshTimezoneTableView()
} }
} }
}
refreshTimezoneTableView() refreshTimezoneTableView()

Loading…
Cancel
Save