Skip to content

Commit 64ba811

Browse files
implement tracking current window for Gnome+Wayland
Based on information from: ActivityWatch/aw-watcher-window#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.
1 parent 0baa0de commit 64ba811

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

track-gnome.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
#
3+
# Tracks what you are spending your time on
4+
#
5+
#
6+
# Copyright (c) 2019 Johannes Buchner
7+
# All rights reserved.
8+
#
9+
# Redistribution and use in source and binary forms, with or without
10+
# modification, are permitted provided that the following conditions are met:
11+
#
12+
# 1. Redistributions of source code must retain the above copyright notice, this
13+
# list of conditions and the following disclaimer.
14+
#
15+
# 2. Redistributions in binary form must reproduce the above copyright notice,
16+
# this list of conditions and the following disclaimer in the documentation
17+
# and/or other materials provided with the distribution.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
#
30+
31+
DIR=$HOME/.local/share/activitytracker/
32+
mkdir -p $DIR
33+
34+
if [ -e $DIR/pid ]
35+
then
36+
pid=$(cat $DIR/pid)
37+
# check if still running
38+
if kill -0 ${pid} 2>/dev/null
39+
then
40+
# check if related
41+
if grep -q $0 /proc/${pid}/cmdline
42+
then
43+
echo "activity tracker already runnning as PID=$pid"
44+
exit 0
45+
fi
46+
fi
47+
fi
48+
49+
pid=$$
50+
echo $pid > $DIR/pid
51+
52+
function window_call_info {
53+
# call Gnome extension "Window Calls extended"
54+
# https://extensions.gnome.org/extension/4974/window-calls-extended/
55+
# needs to be installed!
56+
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowsExt --method org.gnome.Shell.Extensions.WindowsExt.$1 |
57+
sed -n "s/^('\(.*\)',)$/\1/g; s/['\"]//g; p"
58+
}
59+
60+
while true
61+
do
62+
echo '{"timestamp":'$(date +%s)',"windowname":"'$(window_call_info FocusTitle)'","exe":"'$(window_call_info FocusClass)'"}';
63+
sleep 10;
64+
done >> $DIR/log

0 commit comments

Comments
 (0)