ActivityWatch / aw-watcher-window

Cross-platform window watcher (for use with ActivityWatch)
Mozilla Public License 2.0
88 stars 53 forks source link

Fixes "unknown" being returned when some apps open #64

Open michaeljelly opened 2 years ago

michaeljelly commented 2 years ago

I've been developing an electron application, and noticed that ActivityWatch regularly logged the window as unknown. From research, it seems that some applications aren't "scriptable" according to JXA/applescript, and so you can't get their attributes or properties, which was leading the original script to fail at executing both when setting mainWindow and later when setting title. This meant that everything for that window was recorded as unknown.

To fix this, I first try to get the window the old way, and if this fails then to get the name of the frontmost window as the title. This works very well, it seems to get appName and title accurately, and avoids failing to execute and getting Unknown app names.

Hope this helps!

michaeljelly commented 2 years ago

The code has become slightly uglier to account for Applications where there are no open windows. Let me know whether you prefer just one comment to explain the new try-catch, or a comment in each place.

krlmlr commented 2 years ago

This solves the issues I'm having with RStudio on macOS. What's the best way to move forward?

ErikBjare commented 2 years ago

This PR might not be needed if all goes well with the new default Swift-method #68, just released in v0.12.1

Thanks for your hard work on this @michaeljelly, but looks like there was different way that seems to work a lot better.