Browse Source

Merge branch 'master' of https://github.com/n0shake/Clocker

pull/113/head
Abhishek Banthia 2 years ago
parent
commit
11638856d9
  1. 2
      Clocker/Clocker/ja.lproj/Localizable.strings
  2. 2
      Clocker/Clocker/pt-BR.lproj/Localizable.strings
  3. 14
      Clocker/ClockerUnitTests/ReviewControllerTests.swift
  4. 8
      Clocker/Events and Reminders/CalendarHandler.swift
  5. 2
      Clocker/Overall App/ConfigExport.swift
  6. 7
      Clocker/Overall App/DataStore.swift
  7. 21
      Clocker/Panel/ParentPanelController.swift
  8. 19
      Clocker/Panel/UI/TimezoneDataSource.swift
  9. 4
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift
  10. 2
      Readme.md

2
Clocker/Clocker/ja.lproj/Localizable.strings

@ -294,7 +294,7 @@
"This can be configured later in Clocker Preferences." = "This can be configured later in Clocker Preferences."; "This can be configured later in Clocker Preferences." = "This can be configured later in Clocker Preferences.";
"Time Format" = "Time Format"; "Time Format" = "表示フォーマット";
"Truncate menubar text longer than" = "Truncate menubar text longer than"; "Truncate menubar text longer than" = "Truncate menubar text longer than";

2
Clocker/Clocker/pt-BR.lproj/Localizable.strings

@ -102,7 +102,7 @@
"Favourite a timezone to enable menubar display options." = "Favorite um fuso horário para habilitar opções de exibição na barra de menus."; "Favourite a timezone to enable menubar display options." = "Favorite um fuso horário para habilitar opções de exibição na barra de menus.";
"Main Panel Options" = "Opções do painel principal"; "Main Panel Options" = "Opções do painel principal";
"Time Format" = "Formato da hora"; "Time Format" = "Formato da hora";
"Day Display Options" = "Day Display Options"; "Day Display Options" = "Opções de Exibição do Dia";
"Show Future Slider" = "Show Future Slider"; "Show Future Slider" = "Show Future Slider";
"Show Sunrise/Sunset" = "Mostrar Nascer do Sol / Pôr do Sol"; "Show Sunrise/Sunset" = "Mostrar Nascer do Sol / Pôr do Sol";
"Display the time in seconds" = "Exibir o tempo em segundos"; "Display the time in seconds" = "Exibir o tempo em segundos";

14
Clocker/ClockerUnitTests/ReviewControllerTests.swift

@ -19,20 +19,6 @@ class ReviewControllerTests: XCTestCase {
mockDefaults.removeSuite(named: mockSuite) mockDefaults.removeSuite(named: mockSuite)
} }
func testPromptNotDisplayedInFirstWeekSinceInstall() {
let mockSuite = "com.test.Clocker1.\(randomLetter())"
guard let mockDefaults = UserDefaults(suiteName: mockSuite) else {
return
}
// Set key install time
ReviewController.applicationDidLaunch(mockDefaults)
// Explicitly set preview mode to false
ReviewController.setPreviewMode(false)
XCTAssertFalse(ReviewController.canPrompt())
mockDefaults.removeSuite(named: mockSuite)
}
func testPrompDisplayedAfterFirstWeekOfInstall() { func testPrompDisplayedAfterFirstWeekOfInstall() {
let dateChunk = TimeChunk(seconds: 0, let dateChunk = TimeChunk(seconds: 0,
minutes: 0, minutes: 0,

8
Clocker/Events and Reminders/CalendarHandler.swift

@ -124,7 +124,7 @@ extension EventCenter {
let relevantEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date())] ?? [] let relevantEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date())] ?? []
let filteredEvents = relevantEvents.filter { let filteredEvents = relevantEvents.filter {
$0.event.isAllDay == false && $0.event.endDate.timeIntervalSinceNow > 0 $0.event.isAllDay == false && $0.event.endDate.timeIntervalSinceNow > 0 && $0.event.startDate.timeIntervalSinceNow > -300
} }
if filteredEvents.count == 1 { return filteredEvents.first } if filteredEvents.count == 1 { return filteredEvents.first }
@ -458,16 +458,16 @@ struct EventInfo {
var withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) var withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString)
// If the user has not turned on seconds granularity for one of the timezones, // If the user has not turned on seconds granularity for one of the timezones,
// we return "in 12 seconds" which looks weird. // we return "in 12 seconds" which looks weird.
let upToHours: Set<Calendar.Component> = [.second, .minute, .hour] let upToHours: Set<Calendar.Component> = [.second, .minute, .hour]
let difference = nsCalendar.dateComponents(upToHours, from: Date(), to: event.startDate as Date) let difference = nsCalendar.dateComponents(upToHours, from: Date(), to: event.startDate as Date)
let minuteDifference = difference.minute ?? 0 let minuteDifference = difference.minute ?? 0
let hourDifference = difference.hour ?? 0 let hourDifference = difference.hour ?? 0
if hourDifference > 0, minuteDifference > 0 { if hourDifference > 0, minuteDifference > 0 {
withoutAgo.append(contentsOf: "\(minuteDifference)m") withoutAgo.append(contentsOf: "\(minuteDifference)m")
} }
return withoutAgo.contains("seconds") ? "in <1m" : "in \(withoutAgo.lowercased())".trimmingCharacters(in: .whitespaces) return withoutAgo.contains("seconds") ? "in <1m" : "in \(withoutAgo.lowercased())".trimmingCharacters(in: .whitespaces)
} else if event.startDate.isTomorrow { } else if event.startDate.isTomorrow {
let hoursUntil = event.startDate.hoursUntil let hoursUntil = event.startDate.hoursUntil

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 {

7
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)
} }
@ -207,8 +209,9 @@ class DataStore: NSObject {
} }
return value.isEqual(to: NSNumber(value: 0)) return value.isEqual(to: NSNumber(value: 0))
} }
// 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

21
Clocker/Panel/ParentPanelController.swift

@ -586,9 +586,9 @@ 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, *) {
@ -1130,7 +1136,8 @@ extension ParentPanelController: NSSharingServicePickerDelegate {
} }
let timezoneOperations = TimezoneDataOperations(with: earliestTimezone, store: DataStore.shared()) let timezoneOperations = TimezoneDataOperations(with: earliestTimezone, store: DataStore.shared())
var sectionTitle = timezoneOperations.todaysDate(with: 0) // TODO: Take slider value into consideration let futureSliderValue = datasource?.sliderValue ?? 0
var sectionTitle = timezoneOperations.todaysDate(with: futureSliderValue)
clipboardCopy.append("\(sectionTitle)\n") clipboardCopy.append("\(sectionTitle)\n")
stride(from: 0, to: sortedByTime.count, by: 1).forEach { stride(from: 0, to: sortedByTime.count, by: 1).forEach {
@ -1138,8 +1145,8 @@ extension ParentPanelController: NSSharingServicePickerDelegate {
let dataModel = TimezoneData.customObject(from: sortedByTime[$0]) let dataModel = TimezoneData.customObject(from: sortedByTime[$0])
{ {
let dataOperations = TimezoneDataOperations(with: dataModel, store: DataStore.shared()) let dataOperations = TimezoneDataOperations(with: dataModel, store: DataStore.shared())
let date = dataOperations.todaysDate(with: 0) let date = dataOperations.todaysDate(with: futureSliderValue)
let time = dataOperations.time(with: 0) let time = dataOperations.time(with: futureSliderValue)
if date != sectionTitle { if date != sectionTitle {
sectionTitle = date sectionTitle = date
clipboardCopy.append("\n\(sectionTitle)\n") clipboardCopy.append("\n\(sectionTitle)\n")

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
} }
} }

4
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -365,9 +365,9 @@ class StatusItemHandler: NSObject {
setClockerIcon() setClockerIcon()
return return
} }
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

2
Readme.md

@ -1,5 +1,3 @@
# Clocker
<p align="center"> <p align="center">
<a href="https://github.com/n0shake/Clocker/releases/latest"> <a href="https://github.com/n0shake/Clocker/releases/latest">
<img src="https://img.shields.io/badge/download-latest-brightgreen.svg" alt="download"> <img src="https://img.shields.io/badge/download-latest-brightgreen.svg" alt="download">

Loading…
Cancel
Save