testsAndMisc/linux_configuration/scripts/periodic_background/i3-configuration/i3blocks/activitywatch_status.sh
Krzysztof kuhy Rudnicki db6276b3ff refactor(linux_configuration): move remaining dirs + scripts/ to meta/
- Move fresh-install/ → scripts/single_use/fresh-install/
- Move hosts/ → scripts/periodic_background/hosts/
- Move i3-configuration/ → scripts/periodic_background/i3-configuration/
- Delete linux_configuration/LaTeX/, nix-poc/, report/ (dead dirs)
- Move repo-root scripts/ → meta/scripts/
- Update root .pre-commit-config.yaml: scripts/ → meta/scripts/ (9 entries)
- Update run.sh ARTIFACT_INIT_SCRIPT to meta/scripts/
- Update fresh-install/main.sh: hosts/install.sh + i3-configuration/install.sh paths
- Update check_python_location.sh: add meta/scripts/ to exception list
- Fix midnight flakiness in test_recent_workout_returns_true: use timezone-aware
  local noon instead of now-1h to avoid SQL date() boundary issues
2026-05-15 00:53:01 +02:00

74 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# ActivityWatch status script for i3blocks.
set -euo pipefail
SCRIPT_DIR=${BASH_SOURCE[0]%/*}
[[ $SCRIPT_DIR == "${BASH_SOURCE[0]}" ]] && SCRIPT_DIR='.'
# shellcheck source=linux_configuration/i3-configuration/i3blocks/persist_common.sh
source "$SCRIPT_DIR/persist_common.sh"
check_installed() {
command -v aw-qt > /dev/null 2>&1 || command -v aw-server > /dev/null 2>&1
}
check_running() {
local proc_file proc_name
for proc_file in /proc/[0-9]*/comm; do
[[ -r $proc_file ]] || continue
read -r proc_name < "$proc_file" || continue
case $proc_name in
aw-qt | aw-server)
return 0
;;
esac
done
return 1
}
emit() {
local state
if ! check_installed; then
state='uninstalled'
elif check_running; then
state='on'
else
state='off'
fi
if ! i3blocks_update_if_changed_key "activitywatch_state" "$state"; then
return 0
fi
if [[ $state == 'uninstalled' ]]; then
echo "AW uninstalled"
echo
echo "#FF0000"
elif [[ $state == 'on' ]]; then
echo "AW on"
echo
echo "#00FF00"
else
echo "AW off"
echo
echo "#FF0000"
fi
}
is_persist_mode() {
[[ ${BLOCK_INTERVAL:-} == "persist" ]]
}
HEARTBEAT_INTERVAL_S=60
emit
if is_persist_mode; then
# Intentionally calm heartbeat in persist mode: process-table event streams can
# be extremely noisy and cause unnecessary churn.
while true; do
i3blocks_wait_seconds "$HEARTBEAT_INTERVAL_S"
emit
done
fi