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.44k stars 521 forks source link

aw-watcher-windows & aw-watcher-afk not working when launched outside of console on AwesomeWM #924

Closed bricebasty closed 11 months ago

bricebasty commented 12 months ago

Describe the bug

When launching the executable outside of the console, aw-watcher-windows and aw-watcher-afk don't work. Same for launching from the recommended start.sh here

2023-07-29 10:49:19 [INFO ]: window-watcher stopped because parent process died  (aw_watcher_window.main:101)
2023-07-29 10:49:19 [INFO ]: afkwatcher stopped because parent process died  (aw_watcher_afk.afk:80)
2023-07-29 10:49:19 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:436)
2023-07-29 10:49:19 [INFO ]: Connection to aw-server established by aw-watcher-afk  (aw_client.client:436)

When launching both of them separately from the console, then it works (but is very annoying to do).

In red launched from console directly/In green launched from script or from executables: 2023-07-29-103700_2560x1440_scrot

Steps to reproduce

Just use the start.sh recommended.

Expected behavior

AW logging the time from launching with the executables.

github-actions[bot] commented 12 months ago

Hi there! As you're new to this repo, please make sure you've used an appropriate issue template and searched for duplicates (it helps us focus on actual development!). We'd also like to suggest that you read our contribution guidelines and our code of conduct. Thanks a bunch for opening your first issue! 🙏

bricebasty commented 11 months ago

Hey there!

So, I've been tinkering a bit and finally found the solution! It was not a bug, but a misunderstanding of how X sessions work.

I used systemd to create a daemon in the user's session.

Back to the solution

How to make ActivityWatch run automatically on AwesomeWM

1. Create these 3 files in your preferred text editor at /home/YOURNAME/.config/systemd/user (create folder if non-existent)

MODIFY THE PATHS IN ALL CAPS IN ExecStart TO BE IN ACCORDANCE WITH YOUR ACTIVITYWATCH FOLDER

aw-server.service

[Unit]
Description=ActivityWatch Server
After=network.target

[Service]
ExecStart=/PATH/TO/activitywatch/aw-server/aw-server
Restart=always

[Install]
WantedBy=default.target

aw-watcher-window.service

[Unit]
Description=ActivityWatch Window Watcher
After=network.target

[Service]
ExecStart=/PATH/TO/activitywatch/aw-watcher-window/aw-watcher-window
Restart=always

[Install]
WantedBy=default.target

aw-watcher-afk.service

[Unit]
Description=ActivityWatch AFK Watcher
After=network.target

[Service]
ExecStart=/PATH/TO/activitywatch/aw-watcher-afk/aw-watcher-afk
Restart=always

[Install]
WantedBy=default.target

2. Run these commands

$ systemctl --user daemon-reload
$ systemctl --user start aw-watcher-afk
$ systemctl --user start aw-watcher-window
$ systemctl --user start aw-server
$ systemctl --user enable aw-watcher-afk
$ systemctl --user enable aw-watcher-window
$ systemctl --user enable aw-server

3. Enjoy!