diff options
| author | appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> | 2026-06-30 03:52:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-29 23:52:33 -0400 |
| commit | 0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66 (patch) | |
| tree | 4ab852fa1a3d8e0c79e85e345b88ed6333a5c155 /.local/bin/statusbar/sb-price | |
| parent | f82018293b3619485787075023ab4e9af2fd0f58 (diff) | |
| download | eibhear-0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66.tar.gz eibhear-0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66.tar.zst eibhear-0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66.zip | |
Make dwmblocks modules async (#1296)
* Make dwmblocks modules async
* Allow dwmblocks signal numbers to be changed
* Become synchronous on manual run and make dwmblocks signal code optional
* Merge latest commits and add retries
* Re-add fail-early to sb-price
* Make the retry logic better + other changes
* Only redirect non-empty output: for when services are down
* Also change modification time
* Robustness not needed anymore because of curl's --output, no more empty files
* Use actual locks instead of pgrep
* Change to more suitable lock file location for user programs
* Implement thetubster's changes (fast retry and bug fixes)
Diffstat (limited to '.local/bin/statusbar/sb-price')
| -rwxr-xr-x | .local/bin/statusbar/sb-price | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 6a79f8a..68f5146 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -24,22 +24,27 @@ interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices" pricefile="$dir/$target-$denom" chartfile="$dir/$target-$denom-chart" -filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" -updateprice() { curl -sf \ - --fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \ - --output "$pricefile" --output "$chartfile" || - rm -f "$pricefile" "$chartfile" ;} +checkprice() { + [ "$(stat -c %y "$pricefile" 2>/dev/null | + cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] +} -[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && - updateme="1" +updateprice() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } && + curl -sf \ + --fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \ + --output "$pricefile" --output "$chartfile" && + touch "$pricefile" "$chartfile" +} + +checkprice || updateme="1" case $BLOCK_BUTTON in 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; 2) notify-send -u low "$icon Updating..." "Updating $name price..." ; updateme="1" ; showupdate="1" ;; - 3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")" + 3) uptime="$(date -d "$(stat -c %x "$pricefile" 2>/dev/null)" '+%D at %T' | sed "s|$(date '+%D')|Today|")" notify-send "$icon $name module" "\- <b>Exact price: \$$(cat "$pricefile")</b> - Left click for chart of changes. - Middle click to update. @@ -50,9 +55,22 @@ case $BLOCK_BUTTON in esac [ -n "$updateme" ] && - updateprice "$target" && - [ -n "$showupdate" ] && - notify-send "$icon Update complete." "$name price is now -\$$(cat "$pricefile")" + if [ -n "$showupdate" ]; then + updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")" + else + # shellcheck disable=SC2015 + [ -n "$4" ] && + ( flock -n 9 && + ( tries=0; while [ $tries -ne 100 ]; do + updateprice && break || + { tries=$((tries+1)); sleep .1; } + done + ! checkprice && + until updateprice; do sleep 60; done + pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" + ) & + echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-price.lock" || + updateprice + fi [ -f "$pricefile" ] && printf "%s%s%0.2f" "$icon" "$symb" "$(cat "$pricefile")" |
