From b6844dcc331aa4192fe5ea90e06f4cd3b45780a6 Mon Sep 17 00:00:00 2001 From: manuaudio Date: Thu, 8 Oct 2026 08:52:21 -0700 Subject: [PATCH] Fix WebP background migration boundaries --- migrations/1791470456.sh | 40 +++++++++++++++---- .../shell.d/webp-background-migration-test.sh | 37 ++++++++++++++++- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/migrations/1791470456.sh b/migrations/1791470456.sh index 539e0ed7..5213458c 100644 --- a/migrations/1791470456.sh +++ b/migrations/1791470456.sh @@ -1,30 +1,56 @@ echo "Repair background selections after bundled images moved to WebP" +theme_webp_source() { + local theme="$1" + local background="$2" + local original_name=${background##*/} + local replacement_name="${original_name%.*}.webp" + local user_theme_backgrounds="$HOME/.config/omarchy/themes/$theme/backgrounds" + local bundled_theme_backgrounds="$OMARCHY_PATH/themes/$theme/backgrounds" + + if [[ -f $user_theme_backgrounds/$original_name || -f $bundled_theme_backgrounds/$original_name ]]; then + return 1 + elif [[ -f $user_theme_backgrounds/$replacement_name ]]; then + printf '%s\n' "$user_theme_backgrounds/$replacement_name" + elif [[ -f $bundled_theme_backgrounds/$replacement_name ]]; then + printf '%s\n' "$bundled_theme_backgrounds/$replacement_name" + else + return 1 + fi +} + replacement_webp() { local background="$1" local theme="${2:-}" local replacement - [[ ! -e $background ]] || return 1 - case ${background,,} in *.jpg | *.jpeg | *.png) replacement="${background%.*}.webp" ;; *) return 1 ;; esac - if [[ ! -f $replacement ]]; then - [[ -n $theme && ${background%/*} == "$HOME/.local/state/omarchy/current/theme/backgrounds" ]] || return 1 - [[ -f $OMARCHY_PATH/themes/$theme/backgrounds/${replacement##*/} ]] || return 1 + if [[ -n $theme && ${background%/*} == "$HOME/.local/state/omarchy/current/theme/backgrounds" ]]; then + theme_webp_source "$theme" "$background" >/dev/null || return 1 + printf '%s\n' "$replacement" + return 0 fi + [[ ! -e $background && -f $replacement ]] || return 1 printf '%s\n' "$replacement" } -current_background="$HOME/.local/state/omarchy/current/background" +current_dir="$HOME/.local/state/omarchy/current" +current_background="$current_dir/background" if [[ -L $current_background ]]; then + active_theme=$(cat "$current_dir/theme.name" 2>/dev/null || true) background=$(readlink "$current_background") - if replacement=$(replacement_webp "$background"); then + if replacement=$(replacement_webp "$background" "$active_theme"); then + if [[ ! -f $replacement ]]; then + source=$(theme_webp_source "$active_theme" "$background") + cp "$source" "$replacement" + fi ln -sfn "$replacement" "$current_background" + omarchy-shell -q background set "$replacement" fi fi diff --git a/test/shell.d/webp-background-migration-test.sh b/test/shell.d/webp-background-migration-test.sh index 59eefe9e..1d98eba3 100644 --- a/test/shell.d/webp-background-migration-test.sh +++ b/test/shell.d/webp-background-migration-test.sh @@ -8,14 +8,23 @@ test_dir=$(mktemp -d) trap 'rm -rf "$test_dir"' EXIT home="$test_dir/home" migration="$ROOT/migrations/1791470456.sh" +mkdir -p "$test_dir/bin" +call_log="$test_dir/shell-calls" +cat >"$test_dir/bin/omarchy-shell" <<'SH' +#!/bin/bash +printf '%s\n' "$*" >>"$CALL_LOG" +SH +chmod +x "$test_dir/bin/omarchy-shell" reset_home() { rm -rf "$home" mkdir -p "$home/.local/state/omarchy/current/theme/backgrounds" "$home/.local/state/omarchy/theme-backgrounds" + : >"$call_log" } run_migration() { - HOME="$home" OMARCHY_PATH="$ROOT" bash -euo pipefail "$migration" >"$test_dir/output" + HOME="$home" OMARCHY_PATH="$ROOT" CALL_LOG="$call_log" PATH="$test_dir/bin:$PATH" \ + bash -euo pipefail "$migration" >"$test_dir/output" } backgrounds="$home/.local/state/omarchy/current/theme/backgrounds" @@ -30,6 +39,7 @@ printf '%s\n' "$backgrounds/2-swirl-buck.jpg" >"$remembered" printf '%s\n' "$backgrounds/omarchy.png" >"$remembered_png" run_migration [[ $(readlink "$current") == "$backgrounds/current.webp" ]] || fail "the current background moves from the removed JPEG to its WebP replacement" +[[ $(<"$call_log") == "-q background set $backgrounds/current.webp" ]] || fail "the running shell is told about the repaired current background" [[ $(<"$remembered") == "$backgrounds/2-swirl-buck.webp" ]] || fail "an inactive theme's remembered JPEG moves to its bundled WebP replacement" [[ $(<"$remembered_png") == "$backgrounds/omarchy.webp" ]] || fail "an inactive theme's remembered PNG moves to its bundled WebP replacement" pass "converted bundled backgrounds keep their current and remembered selections" @@ -56,3 +66,28 @@ run_migration [[ $(readlink "$current") == "$backgrounds/missing.jpeg" ]] || fail "a dangling selection without an exact WebP replacement is preserved" [[ $(<"$remembered") == "$backgrounds/missing.png" ]] || fail "a dangling remembered selection without an exact WebP replacement is preserved" pass "unrelated dangling background paths are left alone" + +reset_home +mkdir -p "$home/.config/omarchy/themes/custom/backgrounds" +touch "$backgrounds/cover.webp" "$home/.config/omarchy/themes/custom/backgrounds/cover.jpg" +custom_remembered="$home/.local/state/omarchy/theme-backgrounds/custom" +printf '%s\n' "$backgrounds/cover.jpg" >"$custom_remembered" +run_migration +[[ $(<"$custom_remembered") == "$backgrounds/cover.jpg" ]] || fail "an inactive custom theme's existing JPEG is not confused with the active theme's WebP" +pass "remembered selections are checked against their named theme" + +reset_home +touch "$backgrounds/2-swirl-buck.jpg" +printf '%s\n' "$backgrounds/2-swirl-buck.jpg" >"$remembered" +run_migration +[[ $(<"$remembered") == "$backgrounds/2-swirl-buck.webp" ]] || fail "an active-theme filename collision does not hide an inactive theme's WebP replacement" +pass "active theme files do not control inactive remembered repairs" + +reset_home +printf 'tokyo-night\n' >"$home/.local/state/omarchy/current/theme.name" +touch "$backgrounds/2-swirl-buck.jpg" +ln -s "$backgrounds/2-swirl-buck.jpg" "$current" +run_migration +[[ -f $backgrounds/2-swirl-buck.webp ]] || fail "the active staged theme receives its bundled WebP replacement" +[[ $(readlink "$current") == "$backgrounds/2-swirl-buck.webp" ]] || fail "a selected staged JPEG moves before a later refresh can strand it" +pass "the active staged theme is repaired before its old bundled image disappears"