Browse Source

Revert back to non-cached reading of menubar display options.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
326bb6b289
  1. 30
      Clocker/Overall App/DataStore.swift
  2. 2
      Clocker/Preferences/Appearance/AppearanceViewController.swift

30
Clocker/Overall App/DataStore.swift

@ -41,8 +41,6 @@ class DataStore: NSObject {
init(with defaults: UserDefaults) { init(with defaults: UserDefaults) {
super.init() super.init()
userDefaults = defaults userDefaults = defaults
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
setupSyncNotification() setupSyncNotification()
} }
@ -113,20 +111,14 @@ class DataStore: NSObject {
} }
} }
func updateDayPreference() { // MARK: Date (May 8th) in Compact Menubar
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) func shouldShowDateInMenubar() -> Bool {
} return shouldDisplay(.dateInMenubar)
func updateDateInPreference() {
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
} }
// MARK: Day (Sun, Mon etc.) in Compact Menubar
func shouldShowDayInMenubar() -> Bool { func shouldShowDayInMenubar() -> Bool {
return shouldDisplayDayInMenubar return shouldDisplay(.dayInMenubar)
}
func shouldShowDateInMenubar() -> Bool {
return shouldDisplayDateInMenubar
} }
func retrieve(key: String) -> Any? { func retrieve(key: String) -> Any? {
@ -189,11 +181,11 @@ class DataStore: NSObject {
} }
return value.isEqual(to: NSNumber(value: 1)) return value.isEqual(to: NSNumber(value: 1))
case .dateInMenubar: case .dateInMenubar:
return shouldDisplayHelper(CLShowDateInMenu) return shouldDisplayNonObjectHelper(CLShowDateInMenu)
case .placeInMenubar: case .placeInMenubar:
return shouldDisplayHelper(CLShowPlaceInMenu) return shouldDisplayHelper(CLShowPlaceInMenu)
case .dayInMenubar: case .dayInMenubar:
return shouldDisplayHelper(CLShowDayInMenu) return shouldDisplayNonObjectHelper(CLShowDayInMenu)
case .appDisplayOptions: case .appDisplayOptions:
return shouldDisplayHelper(CLAppDisplayOptions) return shouldDisplayHelper(CLAppDisplayOptions)
case .menubarCompactMode: case .menubarCompactMode:
@ -215,6 +207,12 @@ class DataStore: NSObject {
} }
return value.isEqual(to: NSNumber(value: 0)) return value.isEqual(to: NSNumber(value: 0))
} }
// MARK: Some values are stored as plain integers; objectForKey: will return nil, so using integerForKey:
private func shouldDisplayNonObjectHelper(_ key: String) -> Bool {
let value = userDefaults.integer(forKey: key)
return value == 0
}
} }
extension DataStore { extension DataStore {

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -316,12 +316,10 @@ class AppearanceViewController: ParentViewController {
} }
@IBAction func displayDayInMenubarAction(_: Any) { @IBAction func displayDayInMenubarAction(_: Any) {
DataStore.shared().updateDayPreference()
updateStatusItem() updateStatusItem()
} }
@IBAction func displayDateInMenubarAction(_: Any) { @IBAction func displayDateInMenubarAction(_: Any) {
DataStore.shared().updateDateInPreference()
updateStatusItem() updateStatusItem()
} }

Loading…
Cancel
Save