Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
n0shake committed Jul 24, 2022
2 parents db53221 + d077b97 commit 1163885
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Clocker/Clocker/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"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";
Expand Down
2 changes: 1 addition & 1 deletion Clocker/Clocker/pt-BR.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
"Main Panel Options" = "Opções do painel principal";
"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 Sunrise/Sunset" = "Mostrar Nascer do Sol / Pôr do Sol";
"Display the time in seconds" = "Exibir o tempo em segundos";
Expand Down
14 changes: 0 additions & 14 deletions Clocker/ClockerUnitTests/ReviewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ class ReviewControllerTests: XCTestCase {
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() {
let dateChunk = TimeChunk(seconds: 0,
minutes: 0,
Expand Down
8 changes: 4 additions & 4 deletions Clocker/Events and Reminders/CalendarHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extension EventCenter {
let relevantEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date())] ?? []

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 }
Expand Down Expand Up @@ -458,16 +458,16 @@ struct EventInfo {
var withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString)
// If the user has not turned on seconds granularity for one of the timezones,
// we return "in 12 seconds" which looks weird.

let upToHours: Set<Calendar.Component> = [.second, .minute, .hour]
let difference = nsCalendar.dateComponents(upToHours, from: Date(), to: event.startDate as Date)
let minuteDifference = difference.minute ?? 0
let hourDifference = difference.hour ?? 0

if hourDifference > 0, minuteDifference > 0 {
withoutAgo.append(contentsOf: "\(minuteDifference)m")
}

return withoutAgo.contains("seconds") ? "in <1m" : "in \(withoutAgo.lowercased())".trimmingCharacters(in: .whitespaces)
} else if event.startDate.isTomorrow {
let hoursUntil = event.startDate.hoursUntil
Expand Down
2 changes: 1 addition & 1 deletion Clocker/Overall App/ConfigExport.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2015 Abhishek Banthia

import CoreModelKit
import CoreLoggerKit
import CoreModelKit
import Foundation

struct ConfigExport {
Expand Down
7 changes: 5 additions & 2 deletions Clocker/Overall App/DataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -207,8 +209,9 @@ class DataStore: NSObject {
}
return value.isEqual(to: NSNumber(value: 0))
}

// 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
Expand Down
21 changes: 14 additions & 7 deletions Clocker/Panel/ParentPanelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ 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()
Expand All @@ -615,6 +615,7 @@ class ParentPanelController: NSWindowController {
}
}

let hoverRow = mainTableView.hoverRow
stride(from: 0, to: preferences.count, by: 1).forEach {
let current = preferences[$0]

Expand All @@ -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, *) {
Expand Down Expand Up @@ -1130,16 +1136,17 @@ extension ParentPanelController: NSSharingServicePickerDelegate {
}

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")

stride(from: 0, to: sortedByTime.count, by: 1).forEach {
if $0 < sortedByTime.count,
let dataModel = TimezoneData.customObject(from: sortedByTime[$0])
{
let dataOperations = TimezoneDataOperations(with: dataModel, store: DataStore.shared())
let date = dataOperations.todaysDate(with: 0)
let time = dataOperations.time(with: 0)
let date = dataOperations.todaysDate(with: futureSliderValue)
let time = dataOperations.time(with: futureSliderValue)
if date != sectionTitle {
sectionTitle = date
clipboardCopy.append("\n\(sectionTitle)\n")
Expand Down
19 changes: 19 additions & 0 deletions Clocker/Panel/UI/TimezoneDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions Clocker/Preferences/Menu Bar/StatusItemHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ class StatusItemHandler: NSObject {
setClockerIcon()
return
}

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
Expand Down
2 changes: 0 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Clocker

<p align="center">
<a href="https://github.com/n0shake/Clocker/releases/latest">
<img src="https://img.shields.io/badge/download-latest-brightgreen.svg" alt="download">
Expand Down

0 comments on commit 1163885

Please sign in to comment.