Skip to content

Commit

Permalink
Merge pull request #162 from wakatime/misc/debug
Browse files Browse the repository at this point in the history
Add debug helpers
  • Loading branch information
alanhamlett authored Aug 14, 2023
2 parents 9732e1f + c7f7f79 commit 14f1426
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
16 changes: 4 additions & 12 deletions WakaTime/Extensions/NSRunningApplicationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
11 changes: 11 additions & 0 deletions WakaTime/WakaTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
37 changes: 37 additions & 0 deletions WakaTime/Watcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14f1426

Please sign in to comment.