#!/bin/bash # # waybar-breaktimer.sh - modulo custom Waybar per breaktimer # Legge il tempo rimanente gia' congelato dal daemon (no calcolo next-now). # # Copyright (C) 2026 Danilo M. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, see . 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