2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/platform/common/spinning_zsync

50 lines
1.7 KiB
Bash
Executable File
Raw Blame History

#!/bin/sh
# Figure out whether that's a delta or a full download given the number of arguments passed...
if [ $# -lt 7 ]; then
ZSYNC_MESSAGE="Downloading update data"
else
ZSYNC_MESSAGE="Computing zsync delta"
fi
# Small zsync wrapper so we can get a pretty spinner while it works...
./fbink -q -y -7 -pmh "${ZSYNC_MESSAGE} !"
# Clear any potential leftover from the local OTA tarball creation.
./fbink -q -y -6 -pm ' '
# Spin in the background while we work ;).
(
# See https://stackoverflow.com/questions/2685435 for inspiration
# as well as https://www.npmjs.com/package/cli-spinners
# & https://github.com/swelljoe/spinner
# http://www.fileformat.info/info/unicode/block/block_elements/list.htm
##
# Simple bars, they look better when a bit smoother, with a snappier interval (~250ms)
#SPINNER="<22> ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁"
#SPINNER="<22> ▏ ▎ ▍ ▌ ▋ ▊ ▉ █ ▉ ▊ ▋ ▌ ▍ ▎ ▏"
# Spinning blocks
SPINNER="▖ ▘ ▝ ▗"
#SPINNER="▜ ▟ ▙ ▛"
# Snaking blocks
#SPINNER="▌ ▀ ▐ ▄"
#SPINNER="▌ ▛ ▀ ▜ ▐ ▟ ▄ ▙"
while :; do
for spin in ${SPINNER}; do
usleep 500000 2>/dev/null || sleep 0.5
# NOTE: Throw stderr to the void because I'm cheating w/ U+FFFD for a blank character,
# which FBInk replaces by a blank, but not before shouting at us on stderr ;).
./fbink -q -y -7 -pmh "${ZSYNC_MESSAGE} ${spin}" 2>/dev/null
done
done
) &
# Launch zsync, and remember its exit code...
./zsync "$@"
rc=$?
# Kill the spinner subshell now that we're done
kill -15 $!
# And return with zsync's exit code, not kill's ;).
exit ${rc}