Skip to content

Commit

Permalink
Merge pull request #155 from wakatime/main
Browse files Browse the repository at this point in the history
Release v3.4.1
  • Loading branch information
alanhamlett authored Aug 11, 2023
2 parents fa756d9 + f58b1dc commit 555198d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
1 change: 0 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ opt_in_rules:
- closure_spacing
- contains_over_first_not_nil
- empty_count
- explicit_enum_raw_value
- explicit_init
- fatal_error_message
- first_where
Expand Down
40 changes: 39 additions & 1 deletion WakaTime/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
var statusBarA11yItem: NSMenuItem!
var statusBarA11ySeparator: NSMenuItem!
var statusBarA11yStatus: Bool = true
var notificationsEnabled: Bool = false
var settingsWindowController = SettingsWindowController()
var monitoredAppsWindowController = MonitoredAppsWindowController()
var wakaTime: WakaTime?
Expand Down Expand Up @@ -49,6 +50,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
statusBarItem.menu = menu

wakaTime = WakaTime(self)

// request notifications permission
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { granted, error in
guard granted else {
if let msg = error?.localizedDescription {
NSLog(msg)
print(msg)
}
return
}
self.notificationsEnabled = true
}
}

@objc func handleGetURL(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
Expand Down Expand Up @@ -78,7 +91,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
}

@objc func checkForUpdatesClicked(_ sender: AnyObject) {
updater.check().catch(policy: .allErrors) { error in
updater.check {
if self.notificationsEnabled {
self.sendNotification(title: "Updating to latest release")
}
}.catch(policy: .allErrors) { error in
if error.isCancelled {
let alert = NSAlert()
alert.messageText = "Up to date"
Expand Down Expand Up @@ -134,4 +151,25 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusBarDelegate {
NSApp.activate(ignoringOtherApps: true)
monitoredAppsWindowController.showWindow(self)
}

private func sendNotification(title: String, body: String = "") {
let content = UNMutableNotificationContent()
content.title = title

if !body.isEmpty {
content.body = body
}

let uuidString = UUID().uuidString
let request = UNNotificationRequest(
identifier: uuidString,
content: content, trigger: nil)

let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.requestAuthorization(options: [.alert, .sound]) { granted, _ in
guard granted else { return }

notificationCenter.add(request)
}
}
}
2 changes: 1 addition & 1 deletion WakaTime/Helpers/MonitoringManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MonitoringManager {
}

static func isAppElectron(for bundleId: String) -> Bool {
return electronAppIds.contains(bundleId)
electronAppIds.contains(bundleId)
}

static func isAppElectron(_ app: NSRunningApplication) -> Bool {
Expand Down
8 changes: 4 additions & 4 deletions WakaTime/WakaTime.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import AppKit
import Firebase
import Foundation

class WakaTime: HeartbeatEventHandler {
// MARK: Watcher
Expand Down Expand Up @@ -133,10 +133,10 @@ enum EntityType: String {
case app
}

protocol StatusBarDelegate {
func a11yStatusChanged(_ hasPermission: Bool) -> Void
protocol StatusBarDelegate: AnyObject {
func a11yStatusChanged(_ hasPermission: Bool)
}

protocol HeartbeatEventHandler {
func handleHeartbeatEvent(app: NSRunningApplication, entity: String, entityType: EntityType, isWrite: Bool, isBuilding: Bool) -> Void
func handleHeartbeatEvent(app: NSRunningApplication, entity: String, entityType: EntityType, isWrite: Bool, isBuilding: Bool)
}

0 comments on commit 555198d

Please sign in to comment.