Browse Source

Remove observer if sync is turned off.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
dc4456acfa
  1. 7
      Clocker/Overall App/DataStore.swift
  2. 4
      Clocker/Preferences/Appearance/AppearanceViewController.swift

7
Clocker/Overall App/DataStore.swift

@ -44,7 +44,10 @@ class DataStore: NSObject {
userDefaults = defaults userDefaults = defaults
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
setupSyncNotification()
}
func setupSyncNotification() {
if shouldDisplay(.sync) { if shouldDisplay(.sync) {
ubiquitousStore = NSUbiquitousKeyValueStore.default ubiquitousStore = NSUbiquitousKeyValueStore.default
NotificationCenter.default.addObserver(self, NotificationCenter.default.addObserver(self,
@ -52,6 +55,10 @@ class DataStore: NSObject {
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification, name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: NSUbiquitousKeyValueStore.default) object: NSUbiquitousKeyValueStore.default)
ubiquitousStore?.synchronize() ubiquitousStore?.synchronize()
} else {
NotificationCenter.default.removeObserver(self,
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: nil)
} }
} }

4
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -359,8 +359,8 @@ class AppearanceViewController: ParentViewController {
previewPanelTableView.reloadData() previewPanelTableView.reloadData()
} }
@IBAction func toggleSync(_: Any) { @IBAction func toggleSync(_ sender: NSSegmentedControl) {
print("Toggle Sync") DataStore.shared().setupSyncNotification()
} }
} }

Loading…
Cancel
Save