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)
setupSyncNotification()
}
func setupSyncNotification() {
func setupSyncNotification() {
if shouldDisplay(.sync) {
ubiquitousStore = NSUbiquitousKeyValueStore.default
NotificationCenter.default.addObserver(self,
@ -72,6 +72,8 @@ class DataStore: NSObject {
if cloudTimezones != currentTimezones {
Logger.info("Syncing local timezones with data from the ☁")
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))
}
}
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,
object: nil)
if DataStore.shared().shouldDisplay(.sync) {
NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: self,
queue: OperationQueue.main)
{ [weak self] _ in
if let sSelf = self {
sSelf.mainTableView.reloadData()
sSelf.setScrollViewConstraint()
}
NotificationCenter.default.addObserver(forName: DataStore.didSyncFromExternalSourceNotification,
object: self,
queue: OperationQueue.main)
{ [weak self] _ in
if let sSelf = self {
sSelf.mainTableView.reloadData()
sSelf.setScrollViewConstraint()
}
}

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

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

14
Clocker/Preferences/General/PreferencesViewController.swift

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

Loading…
Cancel
Save