|
|
@ -23,6 +23,7 @@ enum ViewType { |
|
|
|
class DataStore: NSObject { |
|
|
|
class DataStore: NSObject { |
|
|
|
private static var sharedStore = DataStore(with: UserDefaults.standard) |
|
|
|
private static var sharedStore = DataStore(with: UserDefaults.standard) |
|
|
|
private var userDefaults: UserDefaults! |
|
|
|
private var userDefaults: UserDefaults! |
|
|
|
|
|
|
|
private var defaultUbiquotousKeyValueStore: NSUbiquitousKeyValueStore! |
|
|
|
|
|
|
|
|
|
|
|
// Since these pref can accessed every second, let's cache this |
|
|
|
// Since these pref can accessed every second, let's cache this |
|
|
|
private var shouldDisplayDayInMenubar: Bool = false |
|
|
|
private var shouldDisplayDayInMenubar: Bool = false |
|
|
@ -35,12 +36,13 @@ class DataStore: NSObject { |
|
|
|
init(with defaults: UserDefaults) { |
|
|
|
init(with defaults: UserDefaults) { |
|
|
|
super.init() |
|
|
|
super.init() |
|
|
|
userDefaults = defaults |
|
|
|
userDefaults = defaults |
|
|
|
|
|
|
|
defaultUbiquotousKeyValueStore = NSUbiquitousKeyValueStore.default |
|
|
|
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) |
|
|
|
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) |
|
|
|
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) |
|
|
|
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func timezones() -> [Data] { |
|
|
|
func timezones() -> [Data] { |
|
|
|
if let cloudPreferences = NSUbiquitousKeyValueStore().object(forKey: CLDefaultPreferenceKey) as? [Data] { |
|
|
|
if let cloudPreferences = defaultUbiquotousKeyValueStore.object(forKey: CLDefaultPreferenceKey) as? [Data] { |
|
|
|
Logger.info("Returning preferences from NSUbiquitousKeyValueStore") |
|
|
|
Logger.info("Returning preferences from NSUbiquitousKeyValueStore") |
|
|
|
return cloudPreferences |
|
|
|
return cloudPreferences |
|
|
|
} |
|
|
|
} |
|
|
@ -55,8 +57,7 @@ class DataStore: NSObject { |
|
|
|
func setTimezones(_ timezones: [Data]?) { |
|
|
|
func setTimezones(_ timezones: [Data]?) { |
|
|
|
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey) |
|
|
|
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey) |
|
|
|
// iCloud sync |
|
|
|
// iCloud sync |
|
|
|
NSUbiquitousKeyValueStore().set(timezones, forKey: CLDefaultPreferenceKey) |
|
|
|
defaultUbiquotousKeyValueStore.set(timezones, forKey: CLDefaultPreferenceKey) |
|
|
|
NSUbiquitousKeyValueStore().synchronize() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func menubarTimezones() -> [Data]? { |
|
|
|
func menubarTimezones() -> [Data]? { |
|
|
|