2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
6 # * left click seconds to reset main timer
7 # * right click seconds to disable minutes & half hours of main timer
8 # * left click minutes to reset 2nd timer.
9 # * right click minutes to disable 2nd timer
11 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
13 source /a
/bin
/errhandle
/err
27 if [[ /b
/data
/daystart
-ot /b
/data
/daystart-generated
&& $day_tmp ]]; then
30 day_tmp
=$
(cat /b
/data
/daystart
)
31 day_start_hour
=${day_tmp%??}
32 day_start_min
=${day_tmp: -2}
33 echo $day_start_hour > /b
/data
/daystart-generated
34 echo $day_start_min >> /b
/data
/daystart-generated
35 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
36 # for after midnight but before the day start.
37 if (( day_start
> EPOCHSECONDS
)); then
38 day_start
=$
(date -d "$day_start_hour:$day_start_min yesterday" +%s
)
47 # if [[ $line ]]; then
48 # echo "line=$line" >>/tmp/t
54 case $
(echo "$json" | jq
-r .name
) in
56 case $
(echo "$json" | jq
-r .button
) in
69 case $
(echo "$json" | jq
-r .button
) in
82 time=$
((EPOCHSECONDS
- start
))
83 total_mins
=$
(( time / 60 ))
84 mins
=$
(( total_mins
% 30 ))
85 half_hours
=$
(( total_mins
/ 30 ))
92 if [[ $start2 ]]; then
93 time2
=$
((EPOCHSECONDS
- start2
))
94 total_mins2
=$
(( time2
/ 60 ))
95 mins2
=$
(( total_mins2
% 30 ))
96 half_hours2
=$
(( total_mins2
/ 30 ))
97 # this is duplicate of mins and half hours except for different
98 # colors and looking at vars above.
101 printf '{ "color": "#EFC93E", "full_text": "'
102 for ((i
=half_hours2-1
; i
>= 0 ; i--
)); do
104 if (( i
> 0 && i
% 2 == 0 )); then
112 printf '{ "name":"mins2", "color":"#ED297D", "full_text": "'
113 for ((i
=29; i
>= 0 ; i--
)); do
114 if (( i
< mins2
)); then
119 if (( i
> 0 && i
% 5 == 0 )); then
129 printf '{ "color": "#FFB542", "full_text": "'
130 for ((i
=half_hours-1
; i
>= 0 ; i--
)); do
132 if (( i
> 0 && i
% 2 == 0 )); then
140 printf '{ "name":"mins", "color":"#0D6BDD", "full_text": "'
141 for ((i
=29; i
>= 0 ; i--
)); do
142 if (( i
< mins
)); then
147 if (( i
> 0 && i
% 5 == 0 )); then
155 printf '{ "name": "seconds", "full_text": "'
157 for ((i
=0; i
< 20; i
++)); do
158 # This first condition is to make the transition from full to empty
159 # be less jarring. We are filling a bucket of space with ticks of
160 # time, we would have to choose to show full or empty, but never
161 # both. Or we could have a half/tick to show full then empty real
162 # quick. I decided to try having it work like a snake, empty out the
163 # 1st quarter as we fill up the last quarter.
165 if (( i
> 0 && i
% 5 == 0 )); then
168 i_end
=$
(( time % 60 / 3 + 1 ))
169 if (( i_end
- i
> 15 )); then
171 elif (( i
< i_end
)); then
179 ## begin day percent, in thousandths, plus a spark block for ten_thousandth.
180 printf '{ "name": "day_percent", "full_text": "'
183 # after 24 hours, reset the day start
184 if (( day_start
+ 24 * 60 * 60 < EPOCHSECONDS
)); then
185 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
188 spark_index
="$(( (100000 -($EPOCHSECONDS - $day_start)*100000 / (16*60*60) ) % 100 / 11 ))"
190 # note: 960 minutes, so 10 minutes is about 1%
191 day_thousandth
=$
(( 1000 - (EPOCHSECONDS
- day_start
)*1000 / (16*60*60) ))
192 printf %s
"$day_thousandth${spark:spark_index:1} $(date "+%l
:%M
")"
194 # .1% of a waking year is ~5.75 hours, or 365 thousandths of a day.
195 # 1% of a waking year is 3.7 days
196 # A spark line of a thousandth of a waking year is 39 minutes.
197 year_start
=$
(date +%s
-d 'january 1 6am')
198 year_days
=$
(( (EPOCHSECONDS
- year_start
) / (24*60*60) ))
199 year_start
=$
(( year_start
+ year_days
* 8*60*60 ))
200 year_spark_index
=$
(( ( 100000 - (EPOCHSECONDS
- year_start
)*100000 / (365*16*60*60) ) % 100 / 11 ))
201 year_tenthousandth
=$
(( 10000 - (EPOCHSECONDS
- year_start
)*10000 / (365*16*60*60) ))
202 printf %s
" $year_tenthousandth${spark:year_spark_index:1}"
211 # pass any arg and we just run once. mainly for debugging
216 #echo date -d $day_start_hour:$day_start_min +%s
217 #echo day_start=$day_start now=$EPOCHSECONDS
220 printf '{ "version": 1, "click_events": true }\n['
224 read -r -t 3 line ||
: