2e3s / awatcher

Activity and idle watchers
Mozilla Public License 2.0
126 stars 4 forks source link

How to properly autostart awatcher on GNOME Wayland? #8

Closed ArcticDev78 closed 7 months ago

ArcticDev78 commented 8 months ago

Hi! Firstly, I'd like to say thank you for making ActivityWatch work on GNOME (Wayland) with this project. But there is one issue which I'm facing — the inability to autostart awatcher when I login to my GNOME (Wayland) session. The solution I tried is to use autostart scripts and .desktop files to autostart it using the “Startup Applications” in GNOME Tweaks app. (My query is regarding the startup files only, but the other files are provided below as well.)

Below are my modified versions of the scripts and .desktop files:

Scripts:

(Yes, I have run chmod +x on both these scripts)

  1. ~/.local/opt/activitywatch/start.sh
    
    #!/bin/bash

sleep 5s

cd ~/.local/opt/activitywatch # Put your ActivityWatch install folder here

./aw-watcher-afk/aw-watcher-afk &

./aw-watcher-window/aw-watcher-window & # you can add --exclude-title here to exclude window title tracking for this session only

notify-send "ActivityWatch started" # Optional, sends a notification when ActivityWatch is started

./aw-server/aw-server;

cd cd ~/.local/opt/awatcher-bundle

./awatcher &

2. `~/.local/opt/activitywatch/kill.sh`
```shell
#!/bin/bash
pkill awatcher
notify-send "ActivityWatch killed"    # Optional, sends a notification when ActivityWatch

.desktop files:

  1. ~/.local/share/applications/aw-start.desktop
    [Desktop Entry]
    Name=Start ActivityWatch
    Comment=Start AW
    Exec="/home/NAME_REDACTED/.local/opt/activitywatch/start.sh"
    # Exec="/home/NAME_REDACTED/.local/opt/awatcher-bundle/awatcher"
    Hidden=false
    Terminal=false
    Type=Application
    Version=1.0
    Categories=Utility;
    X-GNOME-Autostart-enabled=true
  2. ~/.local/share/applications/aw-kill.sh
    Name=Kill ActivityWatch
    Comment=Kill AW
    Exec="/home/NAME_REDACTED/.local/opt/activitywatch/kill.sh"
    Hidden=false
    Terminal=false
    Type=Application
    Version=1.0
    Icon=activitywatch
    Categories=Utility;
    X-GNOME-Autostart-enabled=true

The issue is that when I login to my GNOME (Wayland) session I get the notification from notify-send saying “ActivityWatch started” but awatcher itself does not start up as expected. PS: I am using the latest bundled version of awatcher

2e3s commented 8 months ago

Hello! Some lines are commented and I'm confused, do you run aw-server as well? It's incompatible with the bundled version which carries the server. Also, I guess the sleep is necessary because I suspect that Gnome extensions may run later than the autostart. To diagnose, please add -vvv to the command and save output, something like ./awatcher -vvv > ~/awatcher.log. If the logging works, it would likely tell what's the problem.

2e3s commented 7 months ago

Hello, I've improved autostarting in https://github.com/2e3s/awatcher/releases/tag/v0.2.4-alpha2 I've added a description to autostart https://github.com/2e3s/awatcher/commit/16ec9f64d7c33e1a91eeb78fa835746f31c5bc86

stephane-klein commented 7 months ago

@2e3s thanks :+1:

ArcticDev78 commented 7 months ago

Hello! Some lines are commented and I'm confused, do you run aw-server as well? It's incompatible with the bundled version which carries the server. Also, I guess the sleep is necessary because I suspect that Gnome extensions may run later than the autostart. To diagnose, please add -vvv to the command and save output, something like ./awatcher -vvv > ~/awatcher.log. If the logging works, it would likely tell what's the problem.

Hello, I apologize for my delayed response.

  1. The code for the start.sh and kill.sh are taken from this ActivityWatch documentation page. I have commented those lines which I believe to be not required for awatcher.
  2. I just added the sleep command in the start.sh scripts while trying to solve this issue, so they may not be required.
  3. Output of running ./awatcher -vvv > ~/awatcher.log in the terminal (and stopping it using Ctrl-C):
    [2024-01-26 07:25:39.990973 INFO awatcher] Sending to server localhost:5600
    [2024-01-26 07:25:39.991048 INFO awatcher] Idle timeout: 180 seconds
    [2024-01-26 07:25:39.991063 INFO awatcher] Idle polling period: 5 seconds
    [2024-01-26 07:25:39.991070 INFO awatcher] Window polling period: 1 seconds
    [2024-01-26 07:25:40.016767 DEBUG awatcher::bundle::modules] Processing bundle config at /home/[NAME_REMOVED]/.config/awatcher/bundle-config.toml
    [2024-01-26 07:25:40.040898 WARN rocket::launch] 🚀 Rocket has launched from http://127.0.0.1:5600
    [2024-01-26 07:25:40.144694 DEBUG watchers::watchers] wl_kwin_idle::IdleWatcher cannot run: the requested global was not found in the registry
    [2024-01-26 07:25:40.145475 DEBUG watchers::watchers] x11_screensaver_idle::IdleWatcher cannot run: Unsupported extension
    [2024-01-26 07:25:40.145800 DEBUG watchers::watchers] wl_foreign_toplevel::WindowWatcher cannot run: the requested global was not found in the registry
    [2024-01-26 07:25:40.147313 DEBUG watchers::watchers] kwin_window::WindowWatcher cannot run: org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable
    [2024-01-26 07:25:40.148155 DEBUG watchers::watchers] x11_window::WindowWatcher cannot run: GetPropertyReply[_NET_WM_NAME] failed
    [2024-01-26 07:25:40.148279 INFO watchers::watchers] Selected gnome_idle::IdleWatcher as idle watcher
    [2024-01-26 07:25:40.148293 INFO watchers::watchers] Starting idle watcher
    [2024-01-26 07:25:40.148756 INFO watchers::watchers] Selected gnome_window::WindowWatcher as active window watcher
    [2024-01-26 07:25:40.148788 INFO watchers::watchers] Starting active window watcher
    [2024-01-26 07:25:40.171941 DEBUG watchers::watchers::gnome_window] Changed window app_id="com.raggesilver.BlackBox", title="blackbox-terminal"
    [2024-01-26 07:25:52.584111 DEBUG watchers::watchers::gnome_window] Changed window app_id="firefox", title="How to properly autostart awatcher on GNOME Wayland? · Issue #8 · 2e3s/awatcher — Mozilla Firefox"
    [2024-01-26 07:25:55.627799 DEBUG watchers::watchers::gnome_window] Changed window app_id="com.raggesilver.BlackBox", title="blackbox-terminal"
    [2024-01-26 07:26:00.052256 WARN aw_transform::flood] Gap was of negative duration (-PT172.793528999Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.052479 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT183.731719832Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.067640 WARN aw_transform::flood] Gap was of negative duration (-PT4060.425517667Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.067720 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT181.668879172Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.085198 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT180.941991154Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.085311 WARN aw_transform::flood] Gap was of negative duration (-PT2313.219172789Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.100047 WARN aw_transform::flood] Gap was of negative duration (-PT318.439568539Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.100117 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT183.204972174Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.112416 WARN aw_transform::flood] Gap was of negative duration (-PT1405.222063635Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.112470 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT181.044335669Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.129177 WARN aw_transform::flood] Gap was of negative duration (-PT2927.064985229Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.129350 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT184.865953892Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.143163 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT181.959452745Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.143230 WARN aw_transform::flood] Gap was of negative duration (-PT358.374444543Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.165342 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT182.958920014Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.165397 WARN aw_transform::flood] Gap was of negative duration (-PT4081.145427009Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.178587 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT183.958447514Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.178670 WARN aw_transform::flood] Gap was of negative duration (-PT525.695419987Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.188625 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT182.788072630Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.188671 WARN aw_transform::flood] Gap was of negative duration (-PT554.323495687Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.196832 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT180.731125172Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.196872 WARN aw_transform::flood] Gap was of negative duration (-PT354.816934458Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.206594 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT183.886855632Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.206667 WARN aw_transform::flood] Gap was of negative duration (-PT475.265597582Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.213728 WARN aw_transform::flood] Gap was of negative duration and could NOT be safely merged (-PT183.967235952Ss). This warning will only show once per batch.
    [2024-01-26 07:26:00.213770 WARN aw_transform::flood] Gap was of negative duration (-PT183.893747684Ss), but could be safely merged. This error will only show once per batch.
    [2024-01-26 07:26:00.740191 DEBUG watchers::watchers::gnome_window] Changed window app_id="firefox", title="ActivityWatch — Mozilla Firefox"
    [2024-01-26 07:26:04.816015 DEBUG watchers::watchers::gnome_window] Changed window app_id="com.raggesilver.BlackBox", title="blackbox-terminal"
    [2024-01-26 07:26:07.430040 WARN awatcher] Caught SIGINT, shutting down...
    [2024-01-26 07:26:07.430306 ERROR aw_datastore::worker] DB worker quitting, error: RecvError

    The above testing was done on awatcher version 0.12.1 (which was in the bundle zip uploaded to the Releases page on 27th Nov 2023). I will post a reply using the latest (alpha) version of awatcher to see if it works properly. Thank you.

ArcticDev78 commented 7 months ago

Hello, I'm replying to let you know that I got the autostart to work by changing a few things in my start.sh script! :tada: Here is the current working version of the start.sh script:

#!/bin/bash

sleep 5s

~/.local/opt/awatcher-bundle/awatcher &

notify-send "ActivityWatch started" # Optional, sends a notification when ActivityWatch is started
2e3s commented 7 months ago

By the way, you don't need to make it as complex as activitywatch docs suggest. I just select awatcher from the list given by KDE settings or Gnome Tweaks (installed by .deb though). Go with the easiest way to add to autostart IMO, there is no Qt dependency after all.

ArcticDev78 commented 7 months ago

By the way, you don't need to make it as complex as activitywatch docs suggest. I just select awatcher from the list given by KDE settings or Gnome Tweaks (installed by .deb though). Go with the easiest way to add to autostart IMO.

I'm sorry, I forgot to mention why I'm not using the .deb package to install it, and instead using it through the binary in the bundle zip. I use Fedora Linux, and .deb packages are not natively compatible (unless I use alien or some other similar tool to convert .deb files to .rpm files). This is why I instead use the method mentioned in the ActivityWatch documentation (https://docs.activitywatch.net/en/latest/running-on-gnome.html?highlight=gnome) to autostart it. By the way, in the Gnome Tweaks application, I have selected the "Start ActivityWatch" option (which is from the aw-start.desktop file I created in reference with the docs).