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
import CoreModelKit
import CoreLoggerKit
import CoreModelKit
import Foundation
struct ConfigExport {

3
Clocker/Overall App/DataStore.swift

@ -112,11 +112,13 @@ class DataStore: NSObject {
}
// 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 shouldDisplay(.dayInMenubar)
}
@ -209,6 +211,7 @@ class DataStore: NSObject {
}
// 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

12
Clocker/Panel/ParentPanelController.swift

@ -587,8 +587,8 @@ class ParentPanelController: NSWindowController {
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),
NSAttributedString.Key.baselineOffset : 0.1]
private static let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: NSFont.monospacedDigitSystemFont(ofSize: 13.0, weight: NSFont.Weight.regular),
NSAttributedString.Key.baselineOffset: 0.1]
@objc func updateTime() {
let store = DataStore.shared()
@ -615,6 +615,7 @@ class ParentPanelController: NSWindowController {
}
}
let hoverRow = mainTableView.hoverRow
stride(from: 0, to: preferences.count, by: 1).forEach {
let current = preferences[$0]
@ -628,11 +629,16 @@ class ParentPanelController: NSWindowController {
if modernContainerView != nil, modernSlider.isHidden == false, modernContainerView.currentlyInFocus {
return
}
let dataOperation = TimezoneDataOperations(with: model, store: DataStore.shared())
cellView.time.stringValue = dataOperation.time(with: futureSliderValue)
cellView.sunriseSetTime.stringValue = dataOperation.formattedSunriseTime(with: futureSliderValue)
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.sunriseImage.image = model.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage()
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
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),
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?.image = nil
statusItem.button?.imagePosition = .imageLeft

Loading…
Cancel
Save