Skip to content

Commit

Permalink
Merge pull request #294 from wakatime/main
Browse files Browse the repository at this point in the history
Release v5.20.0
  • Loading branch information
alanhamlett authored Aug 18, 2024
2 parents 5ec9a50 + 963bc91 commit 5e17145
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions WakaTime/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UserNotifications
class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
var window: NSWindow!
var statusBarItem: NSStatusItem!
let menu = NSMenu()
var statusBarA11yItem: NSMenuItem!
var statusBarA11ySeparator: NSMenuItem!
var statusBarA11yStatus: Bool = true
Expand Down Expand Up @@ -37,7 +38,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.variableLength)
statusBarItem.button?.image = NSImage(named: NSImage.Name("WakaTime"))

let menu = NSMenu()
// refresh code time text when status bar icon clicked
statusBarItem.button?.target = self
statusBarItem.button?.action = #selector(AppDelegate.onClick(_:))
statusBarItem.button?.sendAction(on: [.leftMouseUp, .rightMouseUp])

statusBarA11yItem = NSMenuItem(
title: "* A11y permission needed *",
Expand All @@ -50,18 +54,26 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
statusBarA11ySeparator.isHidden = true
menu.addItem(withTitle: "Dashboard", action: #selector(AppDelegate.dashboardClicked(_:)), keyEquivalent: "")
menu.addItem(withTitle: "Settings", action: #selector(AppDelegate.settingsClicked(_:)), keyEquivalent: "")
menu.addItem(withTitle: "Monitored Apps", action: #selector(AppDelegate.monitoredAppsClicked(_:)), keyEquivalent: "")
menu.addItem(
withTitle: "Monitored Apps",
action: #selector(AppDelegate.monitoredAppsClicked(_:)),
keyEquivalent: "")
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "Check for Updates", action: #selector(AppDelegate.checkForUpdatesClicked(_:)), keyEquivalent: "")
menu.addItem(
withTitle: "Check for Updates",
action: #selector(AppDelegate.checkForUpdatesClicked(_:)),
keyEquivalent: "")
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "Quit", action: #selector(AppDelegate.quitClicked(_:)), keyEquivalent: "")

statusBarItem.menu = menu

wakaTime = WakaTime(self)

settingsWindowController.settingsView.delegate = self

Task.detached(priority: .background) {
self.fetchToday()
}

// request notifications permission
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { granted, error in
guard granted else {
Expand Down Expand Up @@ -143,6 +155,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
NSApplication.shared.terminate(self)
}

@objc func onClick(_ sender: NSStatusItem) {
Task.detached(priority: .background) {
self.fetchToday()
}
statusBarItem.popUpMenu(menu)
}

func a11yStatusChanged(_ hasPermission: Bool) {
guard statusBarA11yStatus != hasPermission else { return }

Expand Down

0 comments on commit 5e17145

Please sign in to comment.