Fix WebP background migration boundaries
This commit is contained in:
1 parent
a54bf5fd95
commit
b6844dcc33
2 files changed
+69
-8
No files matched your search
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user