Skip to content

Commit

Permalink
MacOS Ventura support
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Aug 8, 2022
1 parent f1bd540 commit 9c2be52
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nicklockwood/[email protected]
realm/[email protected]
ChargePoint/[email protected]
tuist/[email protected]
18 changes: 16 additions & 2 deletions Work Hours/ReportsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 })
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion Work Hours/WorkHours.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 9c2be52

Please sign in to comment.