Compare commits

..

No commits in common. "63d7ad6356b894e95ff94a6f4b6390ba65baf271" and "ebe66d3161e6bbeb3fb9557fe02572b55b65f618" have entirely different histories.

2 changed files with 46 additions and 78 deletions

View file

@ -1,71 +0,0 @@
#!/usr/bin/env dash
WORK_TIME=1200
PAUSE_TIME=300
timer_state_pid=0
timer_state_state="inactive"
timer_state_time="00:00"
timer_state_progress=100
sub_timer_pid=0
start_timer() {
timer_type=$1
duration=0
timer_state_state="$timer_type" # Update done later
if [ "$timer_type" = "work" ]; then
duration=$WORK_TIME
timer_type="pause"
elif [ "$timer_type" = "pause" ]; then
duration=$PAUSE_TIME
timer_type="work"
else
echo "Invalid argument"
exit 1
fi
i=$duration
while [ "$i" -ge 0 ] ; do
timer_state_progress=$((i * 100 / duration))
timer_state_time="$(date -u -d @$i +'%M:%S')"
update_timer_state
sleep 1
i=$(( i - 1 ))
done
start_timer "$timer_type"
}
update_timer_state() {
echo "{\"pid\": $timer_state_pid, \"state\": \"$timer_state_state\", \"time\": \"$timer_state_time\", \"progress\": $timer_state_progress}"
}
handle_signal() {
# If a timer is running, kill it
if [ $sub_timer_pid -ne 0 ]; then
kill -9 $sub_timer_pid
sub_timer_pid=0
timer_state_state="inactive"
timer_state_progress=100
update_timer_state
else
start_timer "work" &
sub_timer_pid=$!
# Will wait forever
wait $sub_timer_pid
fi
}
# Set up the SIGUSR1 signal handler
trap handle_signal 10
timer_state_pid=$$; update_timer_state
while true; do
sleep infinity &
wait
done

View file

@ -1,18 +1,57 @@
(deflisten timer_state :initial '{"pid": 0, "state": "inactive", "time": "00:00", "progress": 100}' "~/.config/eww/scripts/timer")
(defvar WORK_TIME_SEC 1200)
(defvar PAUSE_TIME_SEC 300)
(defvar timer-state "inactive")
(defvar timer-start-time 0)
(defpoll timer-time
:interval "900ms"
:run-while {timer-state != "inactive"}
`date +%s`)
(defpoll timer-work-period
:interval "20m"
:initial "first"
:run-while {timer-state == "work"}
`if [ "$(eww get timer-work-period)" == "first" ]; then
eww update timer-start-time=$(date +%s)
echo next
else
notify-send -c grind-timer -i ~/Images/Icons/moai.jpg "Work period over" "You can take a little nap now."
eww update timer-state=pause timer-pause-period=first
echo final
fi`) ; TODO: Put in a separate script
(defpoll timer-pause-period
:interval "5m"
:initial "first"
:run-while {timer-state == "pause"}
`if [ "$(eww get timer-pause-period)" == "first" ]; then
eww update timer-start-time=$(date +%s)
echo next
else
notify-send -c grind-timer -i ~/Images/Icons/moai.jpg "Pause period over" "Back to grinding we go."
eww update timer-state=work timer-work-period=first
echo final
fi`) ; TODO: Put in a separate script
(defwidget start-button []
(button
:class "start-button"
:vexpand true
:onclick "kill -10 ${timer_state.pid}"
:onclick "eww update timer-state=${timer-state == "inactive" ? "work" : "inactive"} timer-work-period=first timer-pause-period=first"
(overlay
(circular-progress
:class "circle-progress"
:value "${timer_state.progress}"
:value "${
timer-state == "inactive" ? 100 :
100 * (timer-start-time + (timer-state == "work" ? WORK_TIME_SEC : PAUSE_TIME_SEC) - timer-time)
/ (timer-state == "work" ? WORK_TIME_SEC : PAUSE_TIME_SEC)
}"
:thickness 6
:start-at 75
:clockwise true)
(label :class "start-icon" :text "${timer_state.state == "inactive" ? 'Start' : (timer_state.state == "work" ? "Working" : "Pause")}")
(label :class "start-icon" :text "${timer-state == "inactive" ? 'Start' : (timer-state == "work" ? "Working" : "Pause")}")
)
)
)
@ -21,13 +60,13 @@
(box
:orientation "v"
:space-evenly false
:class "timer ${timer_state.state}"
:class "timer ${timer-state}"
(label :class "timer-title" :text "Grind timer")
(start-button :valign "center" :vexpand true)
(revealer
:transition "slideup"
:reveal {timer_state.state != "inactive"}
(label :class "timer-text" :text "${timer_state.time}")
:reveal {timer-state != "inactive"}
(label :class "timer-text" :text "${timer-state != "inactive" ? formattime(timer-start-time - (3600 - (timer-state == "work" ? WORK_TIME_SEC : PAUSE_TIME_SEC)) - timer-time, "%H:%M:%S") : "00:20:00"}")
)
)
)