Browse Source

Tinkering around with the width.

pull/92/head
Abhishek 5 years ago
parent
commit
16dcb5d20a
  1. 20
      Clocker/Menu Bar/StatusContainerView.swift
  2. 16
      Clocker/Overall App/DataStore.swift
  3. 16
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  4. 3
      Clocker/Preferences/Appearance/AppearanceViewController.swift

20
Clocker/Menu Bar/StatusContainerView.swift

@ -5,18 +5,22 @@ import Cocoa
func bufferCalculatedWidth() -> Int { func bufferCalculatedWidth() -> Int {
var totalWidth = 55 var totalWidth = 55
if DataStore.shared().shouldShowDateInMenubar() { if DataStore.shared().shouldShowDayInMenubar() {
totalWidth += 8 totalWidth += 12
} }
if DataStore.shared().shouldDisplay(.twelveHour) { if DataStore.shared().shouldDisplay(.twelveHour) {
totalWidth += 18 totalWidth += 20
} }
if DataStore.shared().shouldDisplay(.seconds) { if DataStore.shared().shouldDisplay(.seconds) {
totalWidth += 15 totalWidth += 15
} }
if DataStore.shared().shouldShowDateInMenubar() {
totalWidth += 20
}
return totalWidth return totalWidth
} }
@ -24,12 +28,12 @@ func compactWidth(for timezone: TimezoneData) -> Int {
var totalWidth = 55 var totalWidth = 55
let timeFormat = timezone.timezoneFormat() let timeFormat = timezone.timezoneFormat()
if DataStore.shared().shouldShowDateInMenubar() { if DataStore.shared().shouldShowDayInMenubar() {
totalWidth += 8 totalWidth += 12
} }
if timeFormat == DateFormat.twelveHour || timeFormat == DateFormat.twelveHourWithSeconds { if timeFormat == DateFormat.twelveHour || timeFormat == DateFormat.twelveHourWithSeconds {
totalWidth += 18 totalWidth += 20
} else if timeFormat == DateFormat.twentyFourHour || timeFormat == DateFormat.twentyFourHourWithSeconds { } else if timeFormat == DateFormat.twentyFourHour || timeFormat == DateFormat.twentyFourHourWithSeconds {
totalWidth += 0 totalWidth += 0
} }
@ -39,6 +43,10 @@ func compactWidth(for timezone: TimezoneData) -> Int {
totalWidth += 15 totalWidth += 15
} }
if DataStore.shared().shouldShowDateInMenubar() {
totalWidth += 20
}
return totalWidth return totalWidth
} }

16
Clocker/Overall App/DataStore.swift

@ -21,7 +21,8 @@ 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!
// 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 private var shouldDisplayDateInMenubar: Bool = false
class func shared() -> DataStore { class func shared() -> DataStore {
@ -31,7 +32,8 @@ class DataStore: NSObject {
init(with defaults: UserDefaults) { init(with defaults: UserDefaults) {
super.init() super.init()
userDefaults = defaults userDefaults = defaults
shouldDisplayDateInMenubar = shouldDisplay(.dayInMenubar) shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
} }
func timezones() -> [Data] { func timezones() -> [Data] {
@ -43,7 +45,15 @@ class DataStore: NSObject {
} }
func updateDayPreference() { func updateDayPreference() {
shouldDisplayDateInMenubar = shouldDisplay(.dayInMenubar) shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
}
func updateDateInPreference() {
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
}
func shouldShowDayInMenubar() -> Bool {
return shouldDisplayDayInMenubar
} }
func shouldShowDateInMenubar() -> Bool { func shouldShowDateInMenubar() -> Bool {

16
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -35,13 +35,23 @@ extension TimezoneDataOperations {
func compactMenuHeader() -> String { func compactMenuHeader() -> String {
var subtitle = CLEmptyString var subtitle = CLEmptyString
let shouldDayBeShown = DataStore.shared().shouldShowDateInMenubar() let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar()
if shouldDayBeShown { if shouldDayBeShown {
let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay)
subtitle.append(substring) 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))") subtitle.isEmpty ? subtitle.append(time(with: 0)) : subtitle.append(" \(time(with: 0))")
return subtitle return subtitle
@ -53,8 +63,8 @@ extension TimezoneDataOperations {
let dataStore = DataStore.shared() let dataStore = DataStore.shared()
let shouldCityBeShown = dataStore.shouldDisplay(.placeInMenubar) let shouldCityBeShown = dataStore.shouldDisplay(.placeInMenubar)
let shouldDayBeShown = dataStore.shouldShowDateInMenubar() let shouldDayBeShown = dataStore.shouldShowDayInMenubar()
let shouldDateBeShown = dataStore.shouldDisplay(.dateInMenubar) let shouldDateBeShown = dataStore.shouldShowDateInMenubar()
if shouldCityBeShown { if shouldCityBeShown {
if let address = dataObject.formattedAddress, address.isEmpty == false { if let address = dataObject.formattedAddress, address.isEmpty == false {

3
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -250,6 +250,7 @@ class AppearanceViewController: ParentViewController {
} }
@IBAction func displayDateInMenubarAction(_: Any) { @IBAction func displayDateInMenubarAction(_: Any) {
DataStore.shared().updateDateInPreference()
updateStatusItem() updateStatusItem()
} }
@ -288,6 +289,6 @@ class AppearanceViewController: ParentViewController {
// We don't support showing day or date in the menubar for compact mode yet. // We don't support showing day or date in the menubar for compact mode yet.
// Disable those options to let the user know. // Disable those options to let the user know.
private func updateMenubarControls(_ isEnabled: Bool) { private func updateMenubarControls(_ isEnabled: Bool) {
[includePlaceNameControl, includeDateInMenubarControl].forEach { $0?.isEnabled = isEnabled } [includePlaceNameControl].forEach { $0?.isEnabled = isEnabled }
} }
} }

Loading…
Cancel
Save