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
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
setupSyncNotification()
}
func setupSyncNotification() {
if shouldDisplay(.sync) {
ubiquitousStore = NSUbiquitousKeyValueStore.default
NotificationCenter.default.addObserver(self,
@ -52,6 +55,10 @@ class DataStore: NSObject {
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: NSUbiquitousKeyValueStore.default)
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()
}
@IBAction func toggleSync(_: Any) {
print("Toggle Sync")
@IBAction func toggleSync(_ sender: NSSegmentedControl) {
DataStore.shared().setupSyncNotification()
}
}

Loading…
Cancel
Save