Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions WakaTime/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
}
}

private func formatTimeText(_ text: String) -> String {
if !PropertiesManager.shouldDisplayTodayMinutesInStatusBar {
let parts = text.components(separatedBy: " ")
return parts[0] + " " + parts[1]
} else {
return text
}
}

internal func fetchToday() {
guard PropertiesManager.shouldDisplayTodayInStatusBar else {
setText("")
Expand All @@ -218,7 +227,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {

let time = Int(NSDate().timeIntervalSince1970)
guard lastTodayTime + 120 < time else {
setText(lastTodayText)
setText(formatTimeText(lastTodayText))
return
}

Expand Down Expand Up @@ -254,6 +263,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
let data = handle.readDataToEndOfFile()
let text = (String(data: data, encoding: String.Encoding.utf8) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
lastTodayText = text
setText(text)
setText(formatTimeText(text))
}
}
16 changes: 16 additions & 0 deletions WakaTime/Helpers/PropertiesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PropertiesManager {
case shouldAutomaticallyDownloadUpdates = "should_automatically_download_updates"
case hasLaunchedBefore = "has_launched_before"
case shouldDisplayTodayInStatusBar = "status_bar_text"
case shouldDisplayTodayMinutesInStatusBar = "status_bar_minutes"
case domainPreference = "domain_preference"
case filterType = "filter_type"
case denylist = "denylist"
Expand Down Expand Up @@ -104,6 +105,21 @@ class PropertiesManager {
}
}

static var shouldDisplayTodayMinutesInStatusBar: Bool {
get {
guard UserDefaults.standard.string(forKey: Keys.shouldDisplayTodayMinutesInStatusBar.rawValue) != nil else {
UserDefaults.standard.set(true, forKey: Keys.shouldDisplayTodayMinutesInStatusBar.rawValue)
return true
}

return UserDefaults.standard.bool(forKey: Keys.shouldDisplayTodayMinutesInStatusBar.rawValue)
}
set {
UserDefaults.standard.set(newValue, forKey: Keys.shouldDisplayTodayMinutesInStatusBar.rawValue)
UserDefaults.standard.synchronize()
}
}

static var hasLaunchedBefore: Bool {
get {
guard UserDefaults.standard.string(forKey: Keys.hasLaunchedBefore.rawValue) != nil else {
Expand Down
28 changes: 27 additions & 1 deletion WakaTime/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class SettingsView: NSView, NSTextFieldDelegate, NSTextViewDelegate {
return checkbox
}()

lazy var statusBarMinutesCheckbox: NSButton = {
let checkbox = NSButton(
checkboxWithTitle: "Show minutes in status bar",
target: self,
action: #selector(enableStatusBarMinutesCheckboxClicked)
)
checkbox.state = PropertiesManager.shouldDisplayTodayMinutesInStatusBar ? .on : .off
return checkbox
}()

lazy var requestA11yCheckbox: NSButton = {
let checkbox = NSButton(
checkboxWithTitle: "Enable stats from Xcode by requesting accessibility permission",
Expand All @@ -67,7 +77,13 @@ class SettingsView: NSView, NSTextFieldDelegate, NSTextViewDelegate {
}()

lazy var checkboxesStackView: NSStackView = {
let stack = NSStackView(views: [launchAtLoginCheckbox, statusBarTextCheckbox, requestA11yCheckbox, enableLoggingCheckbox])
let stack = NSStackView(views: [
launchAtLoginCheckbox,
statusBarTextCheckbox,
statusBarMinutesCheckbox,
requestA11yCheckbox,
enableLoggingCheckbox
])
stack.alignment = .leading
stack.orientation = .vertical
stack.spacing = 10
Expand Down Expand Up @@ -265,6 +281,16 @@ class SettingsView: NSView, NSTextFieldDelegate, NSTextViewDelegate {
delegate?.fetchToday()
}

@objc func enableStatusBarMinutesCheckboxClicked() {
PropertiesManager.shouldDisplayTodayMinutesInStatusBar = statusBarMinutesCheckbox.state == .on
if statusBarMinutesCheckbox.state == .on {
PropertiesManager.shouldDisplayTodayMinutesInStatusBar = true
} else {
PropertiesManager.shouldDisplayTodayMinutesInStatusBar = false
}
delegate?.fetchToday()
}

@objc func enableA11yCheckboxClicked() {
PropertiesManager.shouldRequestA11yPermission = requestA11yCheckbox.state == .on
if requestA11yCheckbox.state == .on {
Expand Down