ActivityWatch / activitywatch

The best free and open-source automated time tracker. Cross-platform, extensible, privacy-focused.
https://activitywatch.net/
Mozilla Public License 2.0
11.8k stars 536 forks source link

Window tracking not working after upgrade to v0.12.0 #787

Open rtpHarry opened 2 years ago

rtpHarry commented 2 years ago

Describe the bug

Since upgrading my aw-watcher-window bucket is empty.

I'm trying to refresh my memory from a year ago. I remember the titles use to go blank after an update, but this time its just totally empty.

The AFK tracker is populating ok.

I've gone into system preferences > security and permissions > accessibility and added in the AW executable in the Applications folder. (Is there any other category it wants to have?)

I've closed the app, and confirmed that the localhost server is no longer there, so I don't think its still running in the background. After reopening it, still no improvement.

There are some links to various issues but they don't seem to cover this.

To Reproduce

Expected behavior

Documentation

Additional context

rtpHarry commented 2 years ago

Just to be clear, as per this doc:

https://docs.activitywatch.net/en/latest/updating.html#macos

It wasn't in the accessibility list any more, so i didn't just tick it, I added it in, and then restarted AW but still not populating the window bucket.

ErikBjare commented 2 years ago

There are some links to various issues but they don't seem to cover this.

What makes you think this isn't fixed by the workarounds in https://github.com/ActivityWatch/activitywatch/issues/334? Looks like a similar issue to me.

One of these days I'm buying a Macbook to get rid of these macOS issues once and for all.

rtpHarry commented 2 years ago

Thanks for your reply. A lot of the early issues in #334 was actually me having problems with it before.

But that was before you started bundling it as a .dwg and whatnot.

There is a post reply where I got it working by giving it the permissions - https://github.com/ActivityWatch/activitywatch/issues/334#issuecomment-593137561

That hasn't worked this time.

I have just re-read #334 and tried giving it "full file system" (with a close, restart and test) and then "developer tools" permissions but it hasn't done anything to fix the window bucket being empty.

Strangely that does seem to have just changed what it sees my computer as. Before it was .local and now its .net:

image

The afk .net version is now collecting data, and the window .net bucket has not collected anything.

I also tried removing and readding the accessibility now that it has these two other extra permissions, but no improvement.

ErikBjare commented 2 years ago

Wow, that's pretty bad. The hostname change is probably not related though, more likely to be your computer taking a transient hostname from a router or something (it's pretty annoying).

I saw that you were early in that other issue, Have you tried configuring aw-watcher-window to use the old applescript method instead of jxa? (edit the aw-watcher-window.toml in the config dir).

What do the logs say?

BelKed commented 2 years ago

I had the same issue, but launching ActivityWatch using Terminal helped: https://github.com/ActivityWatch/activitywatch/issues/334#issuecomment-1052392579

Gleek commented 2 years ago

I seem to have the same problem. Windows watcher stopped working correctly after the v0.12.0 upgrade

The https://github.com/ActivityWatch/activitywatch/issues/334#issuecomment-1052392579 method worked partially. As in, few windows started to report the title and name, but the rest did not.

The apps inside the Automation section in privacy seem to be related but I've no idea on how I could add more apps manually to the list.

image

Opening some apps would give me a popup asking permission for Terminal to control the app, which seem to add it the list but I don't get that for every other app (Emacs for example)

https://github.com/ActivityWatch/activitywatch/issues/785 might be related here

Checking the logs it seems there are some permission error

Exception: jxa error: Error: Error: ActivityWatch is not allowed assistive access.
2022-09-10 15:47:19 [ERROR]: Exception thrown while trying to get active window  (aw_watcher_window.main:77)
Traceback (most recent call last):
  File "aw_watcher_window/main.py", line 74, in heartbeat_loop
  File "aw_watcher_window/lib.py", line 55, in get_current_window
  File "aw_watcher_window/lib.py", line 27, in get_current_window_macos
  File "aw_watcher_window/macos_jxa.py", line 64, in getInfo

But I already have ActivityWatch and aw-qt from the bundle in the accessibility list as mentioned in the #334 comment

image

use the old applescript method instead of jxa

This seems to work without error, but then the window titles are not reported unfortunately (which is a deal breaker for me)

Edit: Also, this is a regression from v0.11.0 for me. As none of the steps in the #334 were required to run it and things would run normally. Only issues earlier was that it refused to launch normally and I had to do a open -a /Applications/ActivityWatch.app to run it and it had a low res icon. Everything else ran smoothly.

kortschak commented 2 years ago

I'm seeing the same behaviour after upgrade to v0.12.0. AFK watcher is working fine, window watcher has empty buckets. The comment linked at #334 above does not appear to be the issue in my instance.

I see similar errors in the window watcher log.

Reversion to v0.11.0 has not fixed things. There is now no dashboard content is served, but screen is blank. Clearing the browser cache fixes this.

ErikBjare commented 1 year ago

This will be fixed soon, see: https://github.com/ActivityWatch/activitywatch/issues/334#issuecomment-1258166391

ErikBjare commented 1 year ago

All issues mentioned here should have been fixed in the just released v0.12.1.

Please let me know if I can close this issue.

ErikBjare commented 1 year ago

From all I've heard from users, this issue has been resolved in v0.12.1.

Thanks for reporting!

Gleek commented 1 year ago

Unfortunately, v0.12.1 didn't work for me. There are no errors in the logs now:

➜  ~ cat ~/Library/Logs/activitywatch/aw-watcher-window/aw-watcher-window_2022-09-28T16-39-12.log 
2022-09-28 16:39:12 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
2022-09-28 16:39:13 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
2022-09-28 16:39:13 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:429)

But it seems that the afk-watcher-window is not running as seen from the ps output

➜  ~ ps aux|grep ActivityWatch|grep -v grep
umar              1424   0.4  0.5  5205432  81832   ??  S     4:38PM   0:04.11 /Applications/ActivityWatch.app/Contents/MacOS/aw-qt
umar              1436   0.3  0.3  4492020  47588   ??  S     4:38PM   0:01.61 /Applications/ActivityWatch.app/Contents/MacOS/aw-watcher-afk
umar              1434   0.0  0.3  4376404  43864   ??  S     4:38PM   0:01.29 /Applications/ActivityWatch.app/Contents/MacOS/aw-server

Running it manually would give the following error:

➜  ~ /Applications/ActivityWatch.app/Contents/MacOS/aw-watcher-window
 2022-09-28 16:44:17 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
usage: A cross platform window watcher for Activitywatch.
Supported on: Linux (X11), macOS and Windows.
       [-h] [--host HOST] [--port PORT] [--testing] [--exclude-title] [--verbose]
       [--poll-time POLL_TIME] [--strategy {jxa,applescript,swift}]
usage: A cross platform window watcher for Activitywatch.
Supported on: Linux (X11), macOS and Windows.
       [-h] [--host HOST] [--port PORT] [--testing] [--exclude-title] [--verbose]
       [--poll-time POLL_TIME] [--strategy {jxa,applescript,swift}]
A cross platform window watcher for Activitywatch.
Supported on: Linux (X11), macOS and Windows.: error: unrecognized arguments: -B -S -E -s -c from multiprocessing.resource_tracker import main;main(5)
A cross platform window watcher for Activitywatch.
Supported on: Linux (X11), macOS and Windows.: error: unrecognized arguments: --multiprocessing-fork tracker_fd=6 pipe_handle=8
2022-09-28 16:44:18 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib
  Referenced from: /Applications/ActivityWatch.app/Contents/MacOS/aw_watcher_window/aw-watcher-window-macos
  Reason: image not found
2022-09-28 16:44:19 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:429)

Changing the method to jxa also doesn't work with the following logs

Exception: jxa error: Error: Error: An error occurred.
2022-09-28 16:49:36 [ERROR]: Exception thrown while trying to get active window  (aw_watcher_window.main:110)
Traceback (most recent call last):
  File "aw_watcher_window/main.py", line 107, in heartbeat_loop
  File "aw_watcher_window/lib.py", line 55, in get_current_window
  File "aw_watcher_window/lib.py", line 27, in get_current_window_macos
  File "aw_watcher_window/macos_jxa.py", line 64, in getInfo

I'm on macOS Big Sur (v11.6.1)

Any help is appreciated! Thanks :)

Edit: I also get an error pop-up, that I hadn't noticed before, everytime activitywatch opens up. There's no error in the details. But it's consistently crashing

image
ErikBjare commented 1 year ago

Seems to be a case of https://stackoverflow.com/questions/68353353/crash-on-dyld-library-not-loaded-usr-lib-swift-libswift-concurrency-dylib-run

I'll look into it, and I opened #801 to track the issue.

Thanks for reporting!

rtpHarry commented 1 year ago

Ok I just tried upgrading again, to v0.12.1.

The window tracker is working, but the window titles are not populating.

I've tried:

  1. unticking and ticking the accessibility
  2. removing and adding the accessibility
  3. closing aw, removing and reading the accessibility

Nothing has kickstarted it being able to see the window titles.

I'm not using any commandline to run it, i just open the app. (So far I've not had to resort to this in previous versions either).

Any ideas?

(Thanks so much for going above and beyond with buying an entire macbook just to solve these issues)

stgarf-sx commented 1 year ago

I had the same problem as @rtpHarry but in my case I didn't particularly care about my historical data (I only use AW to get myself a nice pretty activty and timeline image (btw would be nice to have export features for those so i can stop screenshotting them instead!) so I deleted all the databases in the data folder and restarted AW. After that I had window titles working again.

I can understand if you want to avoid removing your historical data, however, and so instead you might temporarily rename the folder and relaunch AW to see if that sovles your problem. If it does it's possibly the DB is corrupt in some way and maybe you can hold onto your old db in hopes that a hotfix is pushed that repairs the database? Not sure tho, mostly speculating based on my experience with the same issue.

rtpHarry commented 1 year ago

I've deleted the db and restarted.

A couple of window titles are being populated but not most of them:

image

Also tried closing down aw, removing from accessibility, adding, reloading aw, and no improvement:

image

Not seeing anything to note in the watcher-window log:

2022-10-10 13:15:40 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
2022-10-10 13:15:41 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
2022-10-10 13:15:41 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:429)

or the server log:

2022-10-10 13:15:40 [INFO ]: Using storage method: peewee  (aw_server.main:33)
2022-10-10 13:15:40 [INFO ]: Starting up...  (aw_server.main:41)
2022-10-10 13:15:40 [INFO ]: Using database file: /Users/matthewharris/Library/Application Support/activitywatch/aw-server/peewee-sqlite.v2.db  (aw_datastore.storages.peewee:126)
2022-10-10 13:15:40 [INFO ]:  * Running on http://localhost:5600 (Press CTRL+C to quit)  (werkzeug:224)
2022-10-10 13:15:41 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_Matthews-MBP.local)  (aw_server.api:279)
rtpHarry commented 1 year ago

actually i misspoke there, from further testing it is getting the window titles except for Google Chrome.

I've tried closing and reopening that but that hasn't made any difference. Is there some other step for browser tab support?

BelKed commented 1 year ago

Maybe enabling Google Chrome under Automation settings in System Preferences would help?

Screenshot 2022-10-10 at 14 27 10
rtpHarry commented 1 year ago

I've just tried installing the Chrome browser extension. There is a bucket now for web-chrome which is populating the tab information, but from reading the docs it seems that just the raw url should work without this, and at the moment the main window watcher bucket is not populating anything in the title still.

@BelKed thanks for the tip, I've just tried that tab but don't have any options for editing it? I tried unlocking the padlock, and dragging AW onto the window, but it didn't do anything, and there is no + - buttons in this section of the panel.

rtpHarry commented 1 year ago

This still isn't working for me, and despite being the ticket creator, I don't have a way to reopen it. @ErikBjare should I start a new ticket?

ErikBjare commented 1 year ago

@rtpHarry From some clues in your comments it seems like you might have changed the aw-watcher-window config while trying to fix this pre-v0.12.0 (the empty url field for chrome indicates the jxa-method is in use).

If so, you should delete or edit the config so it uses the new default "swift" strategy for fetching window titles.

rtpHarry commented 1 year ago

I tried the following and it hasn't fixed the issue:

Checking the latest modified log in the aw-watcher-window dir it says:

2022-10-25 23:29:24 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
2022-10-25 23:29:25 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
2022-10-25 23:29:25 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:429)
ErikBjare commented 1 year ago

Alright, just downloaded Chrome and reproduced. Should have just done so sooner, sorry!

Might be fixed by https://github.com/ActivityWatch/aw-watcher-window/pull/69

theofal commented 1 year ago

Hi, Not sure if that's related:

Installing the current project: aw-watcher-window (0.2.0)
# if macOS, build swift
if [ "Darwin" = "Darwin" ]; then \
        make build-swift; \
    fi
swiftc aw_watcher_window/macos.swift -o aw_watcher_window/aw-watcher-window-macos
aw_watcher_window/macos.swift:192:53: error: 'upload(for:from:delegate:)' is only available in macOS 12.0 or newer
    let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                    ^
aw_watcher_window/macos.swift:192:53: note: add 'if #available' version check
    let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                    ^
aw_watcher_window/macos.swift:183:6: note: add @available attribute to enclosing global function
func createBucket() {
     ^
aw_watcher_window/macos.swift:258:51: error: 'upload(for:from:delegate:)' is only available in macOS 12.0 or newer
  let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                  ^
aw_watcher_window/macos.swift:258:51: note: add 'if #available' version check
  let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                  ^
aw_watcher_window/macos.swift:250:6: note: add @available attribute to enclosing global function
func sendHeartbeatSingle(_ heartbeat: Heartbeat, pulsetime: Double) async throws {
     ^
aw_watcher_window/macos.swift:295:24: error: 'now' is only available in macOS 12 or newer
    let nowTime = Date.now
                       ^
aw_watcher_window/macos.swift:295:24: note: add 'if #available' version check
    let nowTime = Date.now
                       ^
aw_watcher_window/macos.swift:279:8: note: add @available attribute to enclosing instance method
  func windowTitleChanged(
       ^
aw_watcher_window/macos.swift:267:7: note: add @available attribute to enclosing class
class MainThing {
      ^
aw_watcher_window/macos.swift:321:76: warning: left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used
            error("tab title diff: \(tabTitle), window title: \(data.title ?? "")")
                                                                ~~~~~~~~~~ ^~~~~

aw_watcher_window/macos.swift:340:74: warning: left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used
          error("tab title diff: \(tabTitle), window title: \(data.title ?? "")")
                                                              ~~~~~~~~~~ ^~~~~

make[2]: *** [aw_watcher_window/aw-watcher-window-macos] Error 1
make[1]: *** [build] Error 2
make: *** [build] Error 2

macos BigSur version 11.7.6

BelKed commented 1 year ago

From the errors I can see that we are using functions in the code that are supporting macOS 12 and higher.


By the way, why are you building ActivityWatch from source? The pre-built binaries doesn't work?

theofal commented 1 year ago

Window tracking is not working on my mac from binaries, I was building it in an effort to troubleshoot hence the error logs sharing

BelKed commented 1 year ago

Would you mind installing the latest version of ActivityWatch v0.12.3b1 and running it?

If you run it, the aw-watcher-window should "quit unexpectedly".

Then, you could run the following command in Terminal to start aw-watcher-window (in verbose mode), which should give us more info about what is going on, and why it's crashing:

/Applications/ActivityWatch.app/Contents/MacOS/aw-watcher-window --verbose
theofal commented 1 year ago
2023-04-20 19:58:11 [DEBUG]: SingleInstance lockfile: /Users/xxx/Library/Caches/activitywatch/client_locks/aw-watcher-window-at-127.0.0.1-on-5600  (aw_client.singleinstance:22)
2023-04-20 19:58:11 [DEBUG]: queue path '/Users/xxx/Library/Application Support/activitywatch/aw-client/queued/aw-watcher-window.v1.persistqueue'  (aw_client.client:407)
2023-04-20 19:58:11 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing] [--exclude-title] [--verbose] [--poll-time POLL_TIME] [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: --multiprocessing-fork tracker_fd=7 pipe_handle=9
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing] [--exclude-title] [--verbose] [--poll-time POLL_TIME] [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: -B -S -E -s -c from multiprocessing.resource_tracker import main;main(6)
2023-04-20 19:58:12 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib
  Referenced from: /Applications/ActivityWatch.app/Contents/MacOS/aw_watcher_window/aw-watcher-window-macos
  Reason: image not found
2023-04-20 19:58:12 [DEBUG]: Starting new HTTP connection (1): 127.0.0.1:5600  (urllib3.connectionpool:228)
2023-04-20 19:58:12 [DEBUG]: http://127.0.0.1:5600 "POST /api/0/buckets/aw-watcher-xxx.local HTTP/1.1" 304 0  (urllib3.connectionpool:456)
2023-04-20 19:58:12 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:436)
2023-04-20 19:58:12 [DEBUG]: queue path '/Users/xxx/Library/Application Support/activitywatch/aw-client/queued/aw-watcher-window.v1.persistqueue'  (aw_client.client:407)

Note that I only have the CommandLineTools installed (version: 13.2.0.0.1.1638488800) without Xcode.

BelKed commented 1 year ago

Thanks! There's already an open issue for this problem: