From d15531a76f87e29e32c18ba64445003cafe1734a Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 23 Jun 2026 12:12:29 +0200 Subject: Initial commit: breaktimer break-reminder daemon with Waybar module Co-Authored-By: Claude Opus 4.8 --- waybar-breaktimer.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 waybar-breaktimer.sh (limited to 'waybar-breaktimer.sh') diff --git a/waybar-breaktimer.sh b/waybar-breaktimer.sh new file mode 100755 index 0000000..b445893 --- /dev/null +++ b/waybar-breaktimer.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# waybar-breaktimer.sh - modulo custom Waybar per breaktimer +# Legge il tempo rimanente gia' congelato dal daemon (no calcolo next-now). + +RUNTIME="${XDG_RUNTIME_DIR:-/tmp}" +PID_FILE="$RUNTIME/breaktimer.pid" +STATE_FILE="$RUNTIME/breaktimer.state" +PHASE_FILE="$RUNTIME/breaktimer.phase" +REMAIN_FILE="$RUNTIME/breaktimer.remain" + +is_running() { + [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE" 2>/dev/null)" 2>/dev/null +} + +if ! is_running; then + printf '{"text":"󰒲","tooltip":"breaktimer: fermo (click dx per avviare)","class":"stopped"}\n' + exit 0 +fi + +state="$(cat "$STATE_FILE" 2>/dev/null)" +phase="$(cat "$PHASE_FILE" 2>/dev/null)" + +rem="$(cat "$REMAIN_FILE" 2>/dev/null)" +[ -z "$rem" ] && rem=0 +[ "$rem" -lt 0 ] && rem=0 +countdown=$(printf '%d:%02d' $(( rem / 60 )) $(( rem % 60 ))) + +if [ "$state" = "paused" ]; then + printf '{"text":"󰏤 %s","tooltip":"breaktimer in pausa (click sx per riprendere)","class":"paused"}\n' "$countdown" + exit 0 +fi + +case "$phase" in + working) + printf '{"text":"󰐊 %s","tooltip":"lavoro: pausa tra %s (sx: pausa, dx: stop/restart)","class":"working"}\n' "$countdown" "$countdown" + ;; + breaking) + printf '{"text":"󰗽 %s","tooltip":"micro-pausa: muoviti! ripresa tra %s","class":"breaking"}\n' "$countdown" "$countdown" + ;; + longbreak) + printf '{"text":"󰒲 %s","tooltip":"pausa lunga: stacca! ripresa tra %s","class":"longbreak"}\n' "$countdown" "$countdown" + ;; + *) + printf '{"text":"󰐊 %s","tooltip":"breaktimer attivo","class":"working"}\n' "$countdown" + ;; +esac -- cgit v1.2.3