Browse Source

Show timezone offset from hover!

pull/113/head
Abhishek 2 years ago
parent
commit
c5534caaea
  1. 2
      Clocker/Overall App/ConfigExport.swift
  2. 3
      Clocker/Overall App/DataStore.swift
  3. 12
      Clocker/Panel/ParentPanelController.swift
  4. 19
      Clocker/Panel/UI/TimezoneDataSource.swift
  5. 2
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

2
Clocker/Overall App/ConfigExport.swift

@ -1,7 +1,7 @@
// Copyright © 2015 Abhishek Banthia // Copyright © 2015 Abhishek Banthia
import CoreModelKit
import CoreLoggerKit import CoreLoggerKit
import CoreModelKit
import Foundation import Foundation
struct ConfigExport { struct ConfigExport {

3
Clocker/Overall App/DataStore.swift

@ -112,11 +112,13 @@ class DataStore: NSObject {
} }
// MARK: Date (May 8th) in Compact Menubar // MARK: Date (May 8th) in Compact Menubar
func shouldShowDateInMenubar() -> Bool { func shouldShowDateInMenubar() -> Bool {
return shouldDisplay(.dateInMenubar) return shouldDisplay(.dateInMenubar)
} }
// MARK: Day (Sun, Mon etc.) in Compact Menubar // MARK: Day (Sun, Mon etc.) in Compact Menubar
func shouldShowDayInMenubar() -> Bool { func shouldShowDayInMenubar() -> Bool {
return shouldDisplay(.dayInMenubar) return shouldDisplay(.dayInMenubar)
} }
@ -209,6 +211,7 @@ class DataStore: NSObject {
} }
// MARK: Some values are stored as plain integers; objectForKey: will return nil, so using integerForKey: // MARK: Some values are stored as plain integers; objectForKey: will return nil, so using integerForKey:
private func shouldDisplayNonObjectHelper(_ key: String) -> Bool { private func shouldDisplayNonObjectHelper(_ key: String) -> Bool {
let value = userDefaults.integer(forKey: key) let value = userDefaults.integer(forKey: key)
return value == 0 return value == 0

12
Clocker/Panel/ParentPanelController.swift

@ -587,8 +587,8 @@ class ParentPanelController: NSWindowController {
private lazy var menubarTitleHandler = MenubarTitleProvider(with: DataStore.shared(), eventStore: EventCenter.sharedCenter()) private lazy var menubarTitleHandler = MenubarTitleProvider(with: DataStore.shared(), eventStore: EventCenter.sharedCenter())
static private let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: NSFont.monospacedDigitSystemFont(ofSize: 13.0, weight: NSFont.Weight.regular), private static let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: NSFont.monospacedDigitSystemFont(ofSize: 13.0, weight: NSFont.Weight.regular),
NSAttributedString.Key.baselineOffset : 0.1] NSAttributedString.Key.baselineOffset: 0.1]
@objc func updateTime() { @objc func updateTime() {
let store = DataStore.shared() let store = DataStore.shared()
@ -615,6 +615,7 @@ class ParentPanelController: NSWindowController {
} }
} }
let hoverRow = mainTableView.hoverRow
stride(from: 0, to: preferences.count, by: 1).forEach { stride(from: 0, to: preferences.count, by: 1).forEach {
let current = preferences[$0] let current = preferences[$0]
@ -628,11 +629,16 @@ class ParentPanelController: NSWindowController {
if modernContainerView != nil, modernSlider.isHidden == false, modernContainerView.currentlyInFocus { if modernContainerView != nil, modernSlider.isHidden == false, modernContainerView.currentlyInFocus {
return return
} }
let dataOperation = TimezoneDataOperations(with: model, store: DataStore.shared()) let dataOperation = TimezoneDataOperations(with: model, store: DataStore.shared())
cellView.time.stringValue = dataOperation.time(with: futureSliderValue) cellView.time.stringValue = dataOperation.time(with: futureSliderValue)
cellView.sunriseSetTime.stringValue = dataOperation.formattedSunriseTime(with: futureSliderValue) cellView.sunriseSetTime.stringValue = dataOperation.formattedSunriseTime(with: futureSliderValue)
cellView.sunriseSetTime.lineBreakMode = .byClipping cellView.sunriseSetTime.lineBreakMode = .byClipping
cellView.relativeDate.stringValue = dataOperation.date(with: futureSliderValue, displayType: .panel)
if $0 != hoverRow {
cellView.relativeDate.stringValue = dataOperation.date(with: futureSliderValue, displayType: .panel)
}
cellView.currentLocationIndicator.isHidden = !model.isSystemTimezone cellView.currentLocationIndicator.isHidden = !model.isSystemTimezone
cellView.sunriseImage.image = model.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() cellView.sunriseImage.image = model.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage()
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {

19
Clocker/Panel/UI/TimezoneDataSource.swift

@ -205,8 +205,27 @@ extension TimezoneDataSource: PanelTableViewDelegate {
} }
rowCellView.extraOptions.alphaValue = (rowIndex == row) ? 1 : 0.5 rowCellView.extraOptions.alphaValue = (rowIndex == row) ? 1 : 0.5
if rowIndex == row, let hoverString = hoverStringForSelectedRow(row: row) {
rowCellView.relativeDate.stringValue = hoverString
}
}
}
}
private func hoverStringForSelectedRow(row: Int) -> String? {
let currentModel = timezones[row]
if let timezone = TimeZone(identifier: currentModel.timezone()) {
let offSet = Double(timezone.secondsFromGMT()) / 3600
let localizedName = timezone.localizedName(for: .shortDaylightSaving, locale: Locale.autoupdatingCurrent) ?? "Error"
if offSet == 0.0 {
return "\(localizedName)"
} else {
let offSetSign = offSet > 0 ? "+" : CLEmptyString
let offsetString = "UTC\(offSetSign)\(offSet)"
return "\(localizedName) (\(offsetString))"
} }
} }
return nil
} }
} }

2
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -367,7 +367,7 @@ class StatusItemHandler: NSObject {
} }
let attributes = [NSAttributedString.Key.font: NSFont.monospacedDigitSystemFont(ofSize: 13.0, weight: NSFont.Weight.regular), let attributes = [NSAttributedString.Key.font: NSFont.monospacedDigitSystemFont(ofSize: 13.0, weight: NSFont.Weight.regular),
NSAttributedString.Key.baselineOffset : 0.1] as [NSAttributedString.Key : Any] NSAttributedString.Key.baselineOffset: 0.1] as [NSAttributedString.Key: Any]
statusItem.button?.attributedTitle = NSAttributedString(string: menubarText, attributes: attributes) statusItem.button?.attributedTitle = NSAttributedString(string: menubarText, attributes: attributes)
statusItem.button?.image = nil statusItem.button?.image = nil
statusItem.button?.imagePosition = .imageLeft statusItem.button?.imagePosition = .imageLeft

Loading…
Cancel
Save