update at 2026-03-21 18:44:12
This commit is contained in:
@@ -6,6 +6,8 @@ KINDLE_TARGET="kindle"
|
||||
THEME_FILTER=""
|
||||
ORIENTATION_FILTER=""
|
||||
CLOCK_REGION_JSON="$ROOT_DIR/calendar/dist/clock-region.json"
|
||||
LOCATION_LAT=""
|
||||
LOCATION_LON=""
|
||||
|
||||
print_usage() {
|
||||
cat <<'EOF'
|
||||
@@ -50,20 +52,6 @@ if [ -n "$ORIENTATION_FILTER" ] && [ -z "$THEME_FILTER" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$ROOT_DIR/calendar"
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
npm run export:themes -- --theme "$THEME_FILTER" --orientation "$ORIENTATION_FILTER" >/dev/null
|
||||
CLOCK_REGION_JSON="$ROOT_DIR/calendar/dist/themes/$THEME_FILTER/$ORIENTATION_FILTER/kindlebg.clock-region.json"
|
||||
else
|
||||
npm run export:themes -- --theme "$THEME_FILTER" >/dev/null
|
||||
CLOCK_REGION_JSON=""
|
||||
fi
|
||||
else
|
||||
npm run export:themes >/dev/null
|
||||
fi
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
clock_region_value() {
|
||||
key=$1
|
||||
python3 - "$CLOCK_REGION_JSON" "$key" <<'PY'
|
||||
@@ -98,19 +86,69 @@ sync_dashboard_runtime() {
|
||||
"$ROOT_DIR/dash/src/local/env.sh" \
|
||||
"$ROOT_DIR/dash/src/local/fetch-dashboard.sh" \
|
||||
"$ROOT_DIR/dash/src/local/clock-index.sh" \
|
||||
"$ROOT_DIR/dash/src/local/location-env.sh" \
|
||||
"$ROOT_DIR/dash/src/local/location-sync.sh" \
|
||||
"$ROOT_DIR/dash/src/local/render-clock.lua" \
|
||||
"$ROOT_DIR/dash/src/local/render-clock.sh" \
|
||||
"$ROOT_DIR/dash/src/local/touch-home-service.sh" \
|
||||
"$ROOT_DIR/dash/src/local/theme-menu-service.sh" \
|
||||
"$ROOT_DIR/dash/src/local/theme-json.lua" \
|
||||
"$ROOT_DIR/dash/src/local/sync-theme-backgrounds.sh" \
|
||||
"$ROOT_DIR/dash/src/local/theme-sync.sh" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/local/
|
||||
|
||||
ssh "$KINDLE_TARGET" "chmod +x /mnt/us/dashboard/start.sh /mnt/us/dashboard/dash.sh /mnt/us/dashboard/stop.sh /mnt/us/dashboard/launch-from-kual.sh /mnt/us/dashboard/launch-theme-from-kual.sh /mnt/us/dashboard/switch-theme.sh /mnt/us/dashboard/local/fetch-dashboard.sh /mnt/us/dashboard/local/clock-index.sh /mnt/us/dashboard/local/render-clock.sh /mnt/us/dashboard/local/touch-home-service.sh /mnt/us/dashboard/local/theme-menu-service.sh /mnt/us/dashboard/local/theme-sync.sh"
|
||||
ssh "$KINDLE_TARGET" "chmod +x /mnt/us/dashboard/start.sh /mnt/us/dashboard/dash.sh /mnt/us/dashboard/stop.sh /mnt/us/dashboard/launch-from-kual.sh /mnt/us/dashboard/launch-theme-from-kual.sh /mnt/us/dashboard/switch-theme.sh /mnt/us/dashboard/local/fetch-dashboard.sh /mnt/us/dashboard/local/clock-index.sh /mnt/us/dashboard/local/location-env.sh /mnt/us/dashboard/local/location-sync.sh /mnt/us/dashboard/local/render-clock.sh /mnt/us/dashboard/local/touch-home-service.sh /mnt/us/dashboard/local/theme-menu-service.sh /mnt/us/dashboard/local/sync-theme-backgrounds.sh /mnt/us/dashboard/local/theme-sync.sh"
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/dashboard/local/state"
|
||||
ssh "$KINDLE_TARGET" "date '+%s' >/mnt/us/dashboard/local/state/background-updated-at"
|
||||
}
|
||||
|
||||
resolve_kindle_location_override() {
|
||||
location_output=""
|
||||
|
||||
if ! location_output=$(ssh "$KINDLE_TARGET" "/mnt/us/dashboard/local/location-env.sh --refresh-if-needed" 2>/dev/null); then
|
||||
echo "Skipped Kindle location override: unable to resolve remote location"
|
||||
return
|
||||
fi
|
||||
|
||||
LOCATION_LAT=$(printf '%s\n' "$location_output" | awk -F= '/^export LOCATION_LAT=/{gsub("'"'"'", "", $2); print $2; exit}')
|
||||
LOCATION_LON=$(printf '%s\n' "$location_output" | awk -F= '/^export LOCATION_LON=/{gsub("'"'"'", "", $2); print $2; exit}')
|
||||
|
||||
if [ -z "$LOCATION_LAT" ] || [ -z "$LOCATION_LON" ]; then
|
||||
echo "Skipped Kindle location override: remote coordinates unavailable"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Using Kindle location override: ${LOCATION_LAT},${LOCATION_LON}"
|
||||
}
|
||||
|
||||
export_theme_bundle_locally() {
|
||||
cd "$ROOT_DIR/calendar"
|
||||
set -- npm run export:themes --
|
||||
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
set -- "$@" --theme "$THEME_FILTER"
|
||||
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
set -- "$@" --orientation "$ORIENTATION_FILTER"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$LOCATION_LAT" ] && [ -n "$LOCATION_LON" ]; then
|
||||
set -- "$@" --location-lat "$LOCATION_LAT" --location-lon "$LOCATION_LON"
|
||||
fi
|
||||
|
||||
"$@" >/dev/null
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
CLOCK_REGION_JSON="$ROOT_DIR/calendar/dist/themes/$THEME_FILTER/$ORIENTATION_FILTER/kindlebg.clock-region.json"
|
||||
else
|
||||
CLOCK_REGION_JSON=""
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
sync_kual_extension() {
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/extensions/kindle-dash"
|
||||
rsync -av --no-o --no-g \
|
||||
@@ -124,15 +162,15 @@ sync_theme_bundle() {
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/
|
||||
|
||||
if [ -z "$THEME_FILTER" ]; then
|
||||
if [ -f "$ROOT_DIR/calendar/dist/kindlebg.png" ]; then
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/dist/kindlebg.png" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/
|
||||
fi
|
||||
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/dist/themes/" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/themes/
|
||||
|
||||
if [ -d "$ROOT_DIR/calendar/kindle-backgrounds" ]; then
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/kindle-backgrounds/" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/kindle-backgrounds/
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -140,6 +178,21 @@ sync_theme_bundle() {
|
||||
"$ROOT_DIR/calendar/dist/themes/$THEME_FILTER.json" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/themes/
|
||||
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/dashboard/kindle-backgrounds"
|
||||
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
flat_background_path="$ROOT_DIR/calendar/kindle-backgrounds/$THEME_FILTER-$ORIENTATION_FILTER.png"
|
||||
if [ -f "$flat_background_path" ]; then
|
||||
rsync -av --no-o --no-g \
|
||||
"$flat_background_path" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/kindle-backgrounds/
|
||||
fi
|
||||
else
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/kindle-backgrounds/$THEME_FILTER-"*.png \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/kindle-backgrounds/
|
||||
fi
|
||||
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/dashboard/themes/$THEME_FILTER/$ORIENTATION_FILTER"
|
||||
rsync -av --no-o --no-g \
|
||||
@@ -154,6 +207,40 @@ sync_theme_bundle() {
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/themes/$THEME_FILTER/
|
||||
}
|
||||
|
||||
refresh_current_background_cache() {
|
||||
# 不能再把本地默认导出的 kindlebg.png 直接覆盖到设备根目录;
|
||||
# 否则设备当前主题若不是默认主题,重启后就会出现“背景回默认、时钟还按旧主题画”的分叉。
|
||||
# 这里统一在 Kindle 端按当前 theme-runtime.env 重新生成根目录背景缓存。
|
||||
if ssh "$KINDLE_TARGET" "/mnt/us/dashboard/local/fetch-dashboard.sh --local-only /mnt/us/dashboard/kindlebg.png"; then
|
||||
ssh "$KINDLE_TARGET" "date '+%s' >/mnt/us/dashboard/local/state/background-updated-at"
|
||||
echo "Current background cache refreshed on device"
|
||||
else
|
||||
echo "Skipped current background cache refresh: current runtime theme assets unavailable"
|
||||
fi
|
||||
}
|
||||
|
||||
refresh_current_theme_runtime() {
|
||||
# 主题包同步完之后,设备上的 theme-runtime.env 仍可能停留在旧坐标。
|
||||
# render-clock / fetch-dashboard 实际都读这份运行时快照,
|
||||
# 所以这里必须按“当前主题 + 当前方向”在 Kindle 本地重写一次,
|
||||
# 让时钟位置和背景图一起跟随最新的 calendar 导出结果。
|
||||
if ssh "$KINDLE_TARGET" "set -eu
|
||||
theme_id=default
|
||||
orientation=portrait
|
||||
if [ -f /mnt/us/dashboard/local/theme.env ]; then
|
||||
# shellcheck disable=SC1091
|
||||
. /mnt/us/dashboard/local/theme.env
|
||||
theme_id=\${THEME_ID:-\$theme_id}
|
||||
orientation=\${ORIENTATION:-\$orientation}
|
||||
fi
|
||||
/mnt/us/dashboard/local/theme-sync.sh --local-only --theme \"\$theme_id\" --orientation \"\$orientation\" >/dev/null
|
||||
"; then
|
||||
echo "Current theme runtime refreshed on device"
|
||||
else
|
||||
echo "Skipped current theme runtime refresh: unable to resolve current theme locally"
|
||||
fi
|
||||
}
|
||||
|
||||
update_default_clock_region_env() {
|
||||
if [ -z "$CLOCK_REGION_JSON" ] || [ ! -f "$CLOCK_REGION_JSON" ]; then
|
||||
echo "Skipped CLOCK_REGION_* env update: no single background region selected"
|
||||
@@ -185,9 +272,13 @@ update_default_clock_region_env() {
|
||||
}
|
||||
|
||||
sync_dashboard_runtime
|
||||
resolve_kindle_location_override
|
||||
export_theme_bundle_locally
|
||||
sync_theme_bundle
|
||||
sync_kual_extension
|
||||
update_default_clock_region_env
|
||||
refresh_current_theme_runtime
|
||||
refresh_current_background_cache
|
||||
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
|
||||
Reference in New Issue
Block a user