From 16dcb5d20a82a0f8f28844b5f6171e04ea7873e2 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 2 Sep 2019 19:22:53 -0700 Subject: [PATCH] Tinkering around with the width. --- Clocker/Menu Bar/StatusContainerView.swift | 20 +++++++++++++------ Clocker/Overall App/DataStore.swift | 16 ++++++++++++--- .../Data Layer/TimezoneDataOperations.swift | 16 ++++++++++++--- .../Appearance/AppearanceViewController.swift | 3 ++- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Clocker/Menu Bar/StatusContainerView.swift b/Clocker/Menu Bar/StatusContainerView.swift index d3ca6b5..c0cfa2c 100644 --- a/Clocker/Menu Bar/StatusContainerView.swift +++ b/Clocker/Menu Bar/StatusContainerView.swift @@ -5,18 +5,22 @@ import Cocoa func bufferCalculatedWidth() -> Int { var totalWidth = 55 - if DataStore.shared().shouldShowDateInMenubar() { - totalWidth += 8 + if DataStore.shared().shouldShowDayInMenubar() { + totalWidth += 12 } if DataStore.shared().shouldDisplay(.twelveHour) { - totalWidth += 18 + totalWidth += 20 } if DataStore.shared().shouldDisplay(.seconds) { totalWidth += 15 } + if DataStore.shared().shouldShowDateInMenubar() { + totalWidth += 20 + } + return totalWidth } @@ -24,12 +28,12 @@ func compactWidth(for timezone: TimezoneData) -> Int { var totalWidth = 55 let timeFormat = timezone.timezoneFormat() - if DataStore.shared().shouldShowDateInMenubar() { - totalWidth += 8 + if DataStore.shared().shouldShowDayInMenubar() { + totalWidth += 12 } if timeFormat == DateFormat.twelveHour || timeFormat == DateFormat.twelveHourWithSeconds { - totalWidth += 18 + totalWidth += 20 } else if timeFormat == DateFormat.twentyFourHour || timeFormat == DateFormat.twentyFourHourWithSeconds { totalWidth += 0 } @@ -39,6 +43,10 @@ func compactWidth(for timezone: TimezoneData) -> Int { totalWidth += 15 } + if DataStore.shared().shouldShowDateInMenubar() { + totalWidth += 20 + } + return totalWidth } diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index 38c7f23..f2b1ee7 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/Clocker/Overall App/DataStore.swift @@ -21,7 +21,8 @@ class DataStore: NSObject { private static var sharedStore = DataStore(with: UserDefaults.standard) private var userDefaults: UserDefaults! - // Since this 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 shouldDisplayDateInMenubar: Bool = false class func shared() -> DataStore { @@ -31,7 +32,8 @@ class DataStore: NSObject { init(with defaults: UserDefaults) { super.init() userDefaults = defaults - shouldDisplayDateInMenubar = shouldDisplay(.dayInMenubar) + shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) + shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) } func timezones() -> [Data] { @@ -43,7 +45,15 @@ class DataStore: NSObject { } func updateDayPreference() { - shouldDisplayDateInMenubar = shouldDisplay(.dayInMenubar) + shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) + } + + func updateDateInPreference() { + shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) + } + + func shouldShowDayInMenubar() -> Bool { + return shouldDisplayDayInMenubar } func shouldShowDateInMenubar() -> Bool { diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 18a24ed..fed6044 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -35,13 +35,23 @@ extension TimezoneDataOperations { func compactMenuHeader() -> String { var subtitle = CLEmptyString - let shouldDayBeShown = DataStore.shared().shouldShowDateInMenubar() + let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar() if shouldDayBeShown { let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) subtitle.append(substring) } + let shouldDateBeShown = DataStore.shared().shouldShowDateInMenubar() + if shouldDateBeShown { + let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone()) + if subtitle.isEmpty == false { + subtitle.append(" \(date)") + } else { + subtitle.append("\(date)") + } + } + subtitle.isEmpty ? subtitle.append(time(with: 0)) : subtitle.append(" \(time(with: 0))") return subtitle @@ -53,8 +63,8 @@ extension TimezoneDataOperations { let dataStore = DataStore.shared() let shouldCityBeShown = dataStore.shouldDisplay(.placeInMenubar) - let shouldDayBeShown = dataStore.shouldShowDateInMenubar() - let shouldDateBeShown = dataStore.shouldDisplay(.dateInMenubar) + let shouldDayBeShown = dataStore.shouldShowDayInMenubar() + let shouldDateBeShown = dataStore.shouldShowDateInMenubar() if shouldCityBeShown { if let address = dataObject.formattedAddress, address.isEmpty == false { diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index f05bbda..a205f48 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/Clocker/Preferences/Appearance/AppearanceViewController.swift @@ -250,6 +250,7 @@ class AppearanceViewController: ParentViewController { } @IBAction func displayDateInMenubarAction(_: Any) { + DataStore.shared().updateDateInPreference() updateStatusItem() } @@ -288,6 +289,6 @@ class AppearanceViewController: ParentViewController { // We don't support showing day or date in the menubar for compact mode yet. // Disable those options to let the user know. private func updateMenubarControls(_ isEnabled: Bool) { - [includePlaceNameControl, includeDateInMenubarControl].forEach { $0?.isEnabled = isEnabled } + [includePlaceNameControl].forEach { $0?.isEnabled = isEnabled } } }