From 9c2be52d5487b68294d88730ad7a21122f6bb322 Mon Sep 17 00:00:00 2001 From: Janez Troha Date: Mon, 8 Aug 2022 11:34:13 +0200 Subject: [PATCH] MacOS Ventura support --- Makefile | 8 ++++---- Mintfile | 4 ++++ Work Hours/ReportsGenerator.swift | 18 ++++++++++++++++-- Work Hours/WorkHours.swift | 6 +++++- 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 Mintfile diff --git a/Makefile b/Makefile index 50c7b65..19382d6 100644 --- a/Makefile +++ b/Makefile @@ -44,14 +44,14 @@ dmg: create-dmg --overwrite Export/Work\ Hours.app Export && mv Export/*.dmg WorkHours.dmg lint: - swiftlint . + mint run swiftlint . fmt: - swiftformat --swiftversion 5 . - swiftlint . --fix + mint run swiftformat --swiftversion 5 . + mint run swiftlint . --fix notarize: - xcrun notarytool submit WorkHours.dmg --team-id PM784W7B8X --progress --wait + xcrun notarytool submit WorkHours.dmg --team-id PM784W7B8X --progress --wait ${APPLE_AUTH_TOKEN} clean: rm -rf SourcePackages diff --git a/Mintfile b/Mintfile new file mode 100644 index 0000000..a2ded20 --- /dev/null +++ b/Mintfile @@ -0,0 +1,4 @@ +nicklockwood/SwiftFormat@0.49.13 +realm/SwiftLint@0.47.1 +ChargePoint/xcparse@2.2.1 +tuist/xcbeautify@0.13.0 diff --git a/Work Hours/ReportsGenerator.swift b/Work Hours/ReportsGenerator.swift index f599b42..bec5321 100644 --- a/Work Hours/ReportsGenerator.swift +++ b/Work Hours/ReportsGenerator.swift @@ -10,6 +10,19 @@ import Foundation import os.log import SwiftCSV +extension Date { + func convertToLocalTime(fromTimeZone timeZoneAbbreviation: String) -> Date? { + if let timeZone = TimeZone(abbreviation: timeZoneAbbreviation) { + let targetOffset = TimeInterval(timeZone.secondsFromGMT(for: self)) + let localOffset = TimeInterval(TimeZone.autoupdatingCurrent.secondsFromGMT(for: self)) + + return addingTimeInterval(targetOffset + localOffset) + } + + return nil + } +} + enum Action: String { case start = "START" case stop = "END" @@ -26,6 +39,7 @@ struct Report { if duration < 60 { continue } + reports.append(Report(timestamp: timestamp, amount: TimeInterval.hoursAndMinutes(duration))) } return reports.sorted(by: { $0.timestamp < $1.timestamp }) @@ -148,9 +162,9 @@ enum Events { switch line[0] { case Action.start.rawValue: - startTimestamp = Date(dateString: line[1]) + startTimestamp = Date(dateString: line[1]).convertToLocalTime(fromTimeZone: "UTC") case Action.stop.rawValue: - endTimestamp = Date(dateString: line[1]) + endTimestamp = Date(dateString: line[1]).convertToLocalTime(fromTimeZone: "UTC") default: os_log("Unknown line %s", line) return nil diff --git a/Work Hours/WorkHours.swift b/Work Hours/WorkHours.swift index 121a448..0841c2d 100644 --- a/Work Hours/WorkHours.swift +++ b/Work Hours/WorkHours.swift @@ -71,7 +71,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { func processAction(_: URL) {} @objc func showPrefs() { - NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil) + if #available(macOS 13.0, *) { + NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil) + } else { + NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil) + } NSApp.activate(ignoringOtherApps: true) }