From 64ba8117ea054b77aad00a030d4b97af1cfc6734 Mon Sep 17 00:00:00 2001 From: Johannes Buchner Date: Sat, 9 Dec 2023 11:04:16 +0100 Subject: [PATCH] implement tracking current window for Gnome+Wayland Based on information from: https://github.com/ActivityWatch/aw-watcher-window/pull/46 https://askubuntu.com/questions/1412130/dbus-calls-to-gnome-shell-dont-work-under-ubuntu-22-04 https://github.com/hseliger/window-calls-extended To avoid opening a security hole, it is wiser to install the "Window calls extended" extension by hseliger. Then we can regularly query the currently active window. Compared to the previous version, activity/passivity of the user is not detected anymore. --- track-gnome.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 track-gnome.sh diff --git a/track-gnome.sh b/track-gnome.sh new file mode 100644 index 0000000..16657e9 --- /dev/null +++ b/track-gnome.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Tracks what you are spending your time on +# +# +# Copyright (c) 2019 Johannes Buchner +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +DIR=$HOME/.local/share/activitytracker/ +mkdir -p $DIR + +if [ -e $DIR/pid ] +then + pid=$(cat $DIR/pid) + # check if still running + if kill -0 ${pid} 2>/dev/null + then + # check if related + if grep -q $0 /proc/${pid}/cmdline + then + echo "activity tracker already runnning as PID=$pid" + exit 0 + fi + fi +fi + +pid=$$ +echo $pid > $DIR/pid + +function window_call_info { + # call Gnome extension "Window Calls extended" + # https://extensions.gnome.org/extension/4974/window-calls-extended/ + # needs to be installed! + gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowsExt --method org.gnome.Shell.Extensions.WindowsExt.$1 | + sed -n "s/^('\(.*\)',)$/\1/g; s/['\"]//g; p" +} + +while true +do +echo '{"timestamp":'$(date +%s)',"windowname":"'$(window_call_info FocusTitle)'","exe":"'$(window_call_info FocusClass)'"}'; +sleep 10; +done >> $DIR/log