From 326bb6b289c52d4717c74d971cf5bc796b6147b3 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sun, 8 May 2022 14:49:26 +0530 Subject: [PATCH] Revert back to non-cached reading of menubar display options. --- Clocker/Overall App/DataStore.swift | 30 +++++++++---------- .../Appearance/AppearanceViewController.swift | 2 -- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index 5668610..8ed0f6a 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/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 { diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 695175f..002c6be 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/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() }