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) {
super.init()
userDefaults = defaults
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
setupSyncNotification()
}
@ -113,20 +111,14 @@ class DataStore: NSObject {
}
}
func updateDayPreference() {
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
}
func updateDateInPreference() {
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
// MARK: Date (May 8th) in Compact Menubar
func shouldShowDateInMenubar() -> Bool {
return shouldDisplay(.dateInMenubar)
}
// MARK: Day (Sun, Mon etc.) in Compact Menubar
func shouldShowDayInMenubar() -> Bool {
return shouldDisplayDayInMenubar
}
func shouldShowDateInMenubar() -> Bool {
return shouldDisplayDateInMenubar
return shouldDisplay(.dayInMenubar)
}
func retrieve(key: String) -> Any? {
@ -189,11 +181,11 @@ class DataStore: NSObject {
}
return value.isEqual(to: NSNumber(value: 1))
case .dateInMenubar:
return shouldDisplayHelper(CLShowDateInMenu)
return shouldDisplayNonObjectHelper(CLShowDateInMenu)
case .placeInMenubar:
return shouldDisplayHelper(CLShowPlaceInMenu)
case .dayInMenubar:
return shouldDisplayHelper(CLShowDayInMenu)
return shouldDisplayNonObjectHelper(CLShowDayInMenu)
case .appDisplayOptions:
return shouldDisplayHelper(CLAppDisplayOptions)
case .menubarCompactMode:
@ -215,6 +207,12 @@ class DataStore: NSObject {
}
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 {

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

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

Loading…
Cancel
Save