2e3s / awatcher

Activity and idle watchers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to properly autostart awatcher on GNOME Wayland?

ArcticDev78 opened this issue · comments

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 &
  1. ~/.local/opt/activitywatch/kill.sh
#!/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
  1. ~/.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

commented

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.

commented

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

@2e3s thanks 👍

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 �[32mINFO�[0m awatcher] Sending to server localhost:5600
[2024-01-26 07:25:39.991048 �[32mINFO�[0m awatcher] Idle timeout: 180 seconds
[2024-01-26 07:25:39.991063 �[32mINFO�[0m awatcher] Idle polling period: 5 seconds
[2024-01-26 07:25:39.991070 �[32mINFO�[0m awatcher] Window polling period: 1 seconds
[2024-01-26 07:25:40.016767 �[34mDEBUG�[0m awatcher::bundle::modules] Processing bundle config at /home/[NAME_REMOVED]/.config/awatcher/bundle-config.toml
[2024-01-26 07:25:40.040898 �[33mWARN�[0m rocket::launch] 🚀 �[1;49;39mRocket has launched from�[0m �[1;4;49;39mhttp://127.0.0.1:5600�[0m
[2024-01-26 07:25:40.144694 �[34mDEBUG�[0m watchers::watchers] wl_kwin_idle::IdleWatcher cannot run: the requested global was not found in the registry
[2024-01-26 07:25:40.145475 �[34mDEBUG�[0m watchers::watchers] x11_screensaver_idle::IdleWatcher cannot run: Unsupported extension
[2024-01-26 07:25:40.145800 �[34mDEBUG�[0m watchers::watchers] wl_foreign_toplevel::WindowWatcher cannot run: the requested global was not found in the registry
[2024-01-26 07:25:40.147313 �[34mDEBUG�[0m watchers::watchers] kwin_window::WindowWatcher cannot run: org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable
[2024-01-26 07:25:40.148155 �[34mDEBUG�[0m watchers::watchers] x11_window::WindowWatcher cannot run: GetPropertyReply[_NET_WM_NAME] failed
[2024-01-26 07:25:40.148279 �[32mINFO�[0m watchers::watchers] Selected gnome_idle::IdleWatcher as idle watcher
[2024-01-26 07:25:40.148293 �[32mINFO�[0m watchers::watchers] Starting idle watcher
[2024-01-26 07:25:40.148756 �[32mINFO�[0m watchers::watchers] Selected gnome_window::WindowWatcher as active window watcher
[2024-01-26 07:25:40.148788 �[32mINFO�[0m watchers::watchers] Starting active window watcher
[2024-01-26 07:25:40.171941 �[34mDEBUG�[0m watchers::watchers::gnome_window] Changed window app_id="com.raggesilver.BlackBox", title="blackbox-terminal"
[2024-01-26 07:25:52.584111 �[34mDEBUG�[0m 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 �[34mDEBUG�[0m watchers::watchers::gnome_window] Changed window app_id="com.raggesilver.BlackBox", title="blackbox-terminal"
[2024-01-26 07:26:00.052256 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[33mWARN�[0m 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 �[34mDEBUG�[0m watchers::watchers::gnome_window] Changed window app_id="firefox", title="ActivityWatch — Mozilla Firefox"
[2024-01-26 07:26:04.816015 �[34mDEBUG�[0m watchers::watchers::gnome_window] Changed window app_id="com.raggesilver.BlackBox", title="blackbox-terminal"
[2024-01-26 07:26:07.430040 �[33mWARN�[0m awatcher] Caught SIGINT, shutting down...
[2024-01-26 07:26:07.430306 �[31mERROR�[0m 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.

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! 🎉
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
commented

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.

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).