From c7f7f791fa354bb762d0a0193cc747800941b1b5 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Mon, 14 Aug 2023 19:28:17 +0200 Subject: [PATCH] Add debug helpers --- .../NSRunningApplicationExtension.swift | 16 ++------ WakaTime/WakaTime.swift | 11 ++++++ WakaTime/Watcher.swift | 37 +++++++++++++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/WakaTime/Extensions/NSRunningApplicationExtension.swift b/WakaTime/Extensions/NSRunningApplicationExtension.swift index 7bfc829..44476b7 100644 --- a/WakaTime/Extensions/NSRunningApplicationExtension.swift +++ b/WakaTime/Extensions/NSRunningApplicationExtension.swift @@ -3,22 +3,14 @@ import Cocoa enum MonitoredApp: String, CaseIterable { case xcode = "com.apple.dt.Xcode" case figma = "com.figma.Desktop" - case postman = "com.postmanlabs.mac" case canva = "com.canva.CanvaDesktop" + case postman = "com.postmanlabs.mac" init?(from bundleId: String) { - switch bundleId { - case MonitoredApp.xcode.rawValue: - self = .xcode - case MonitoredApp.figma.rawValue: - self = .figma - case MonitoredApp.canva.rawValue: - self = .canva - case MonitoredApp.postman.rawValue: - self = .postman - default: - return nil + if let app = MonitoredApp(rawValue: bundleId) { + self = app } + return nil } static var allBundleIds: [String] { diff --git a/WakaTime/WakaTime.swift b/WakaTime/WakaTime.swift index 633e275..62effc4 100644 --- a/WakaTime/WakaTime.swift +++ b/WakaTime/WakaTime.swift @@ -38,6 +38,17 @@ class WakaTime: HeartbeatEventHandler { checkForApiKey() watcher.heartbeatEventHandler = self watcher.statusBarDelegate = delegate + + // In local dev builds, print bundle-ids of all running apps to Xcode console + if Bundle.main.version == "local-build" { + print("********* Start Running Applications *********") + for runningApp in NSWorkspace.shared.runningApplications where runningApp.activationPolicy == .regular { + if let name = runningApp.localizedName, let id = runningApp.bundleIdentifier { + print("\(name): \(id)") + } + } + print("********* End Running Applications *********") + } } private func configureFirebase() { diff --git a/WakaTime/Watcher.swift b/WakaTime/Watcher.swift index 08656d7..807fcd6 100644 --- a/WakaTime/Watcher.swift +++ b/WakaTime/Watcher.swift @@ -124,6 +124,43 @@ class Watcher: NSObject { try observer.add(notification: kAXValueChangedNotification, element: axApp, refcon: this) } + /* + if app.monitoredApp == .iterm2 { + try observer.add(notification: kAXValueChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXMainWindowChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXApplicationActivatedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXApplicationDeactivatedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXApplicationHiddenNotification, element: axApp, refcon: this) + try observer.add(notification: kAXApplicationShownNotification, element: axApp, refcon: this) + try observer.add(notification: kAXWindowCreatedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXWindowMovedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXWindowResizedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXWindowMiniaturizedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXWindowDeminiaturizedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXDrawerCreatedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXSheetCreatedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXHelpTagCreatedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXElementBusyChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXMenuOpenedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXMenuClosedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXMenuItemSelectedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXRowCountChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXRowExpandedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXRowCollapsedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXSelectedCellsChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXUnitsChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXSelectedChildrenMovedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXSelectedChildrenChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXResizedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXMovedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXCreatedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXSelectedRowsChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXSelectedColumnsChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXTitleChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXLayoutChangedNotification, element: axApp, refcon: this) + try observer.add(notification: kAXAnnouncementRequestedNotification, element: axApp, refcon: this) + }*/ + observer.addToRunLoop() self.observer = observer self.observingElement = axApp