Repository navigation
Heal broken background symlink during theme refresh #10731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
epkoen
wants to merge
7
commits into
omacom:quattro
Choose a base branch
from
epkoen:fix/theme-refresh-broken-background-link
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
820016f
Heal broken background symlink during theme refresh
epkoen fb0e92d
Merge quattro into fix/theme-refresh-broken-background-link
omarchybot a4b2d3a
Match a background's stem literally
omarchybot 3d5ecbe
Stub the session hooks in the theme refresh test
omarchybot 33ecffb
Merge quattro into fix/theme-refresh-broken-background-link
omarchybot 3853eae
Refresh a missing wallpaper only when the theme has one to offer
omarchybot ef73a69
Stub the retints in the theme refresh test directly
omarchybot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # omarchy-theme-refresh runs omarchy-theme-set with OMARCHY_THEME_SKIP_BACKGROUND=1 | ||
| # so template regenerations do not cycle the user's wallpaper. When background | ||
| # files are renamed, converted (such as .jpg to .webp), or removed upstream, | ||
| # theme refresh must heal dangling symlinks rather than leave a broken path. | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| test_tmp=$(mktemp -d) | ||
| trap 'rm -rf "$test_tmp"' EXIT | ||
|
|
||
| home="$test_tmp/home" | ||
| state="$home/.local/state/omarchy/current" | ||
| custom_themes="$home/.config/omarchy/themes" | ||
| mock_root="$test_tmp/root" | ||
| stock_themes="$mock_root/themes" | ||
| runtime_dir="$test_tmp/runtime" | ||
|
|
||
| mkdir -p "$state" "$custom_themes" "$stock_themes" "$runtime_dir" | ||
| mkdir -p "$mock_root/default/themed" | ||
| cp -r "$ROOT/default/themed"/* "$mock_root/default/themed/" 2>/dev/null || true | ||
|
|
||
| theme_name="test-theme" | ||
| theme_dir="$stock_themes/$theme_name" | ||
| mkdir -p "$theme_dir/backgrounds" | ||
|
|
||
| cat >"$theme_dir/colors.toml" <<'TOML' | ||
| mode = "dark" | ||
| accent = "#7aa2f7" | ||
| selection = "#292e42" | ||
| muted = "#414868" | ||
| background = "#1a1b26" | ||
| foreground = "#a9b1d6" | ||
| TOML | ||
|
|
||
| printf 'jpg image 0\n' >"$theme_dir/backgrounds/0-intro.jpg" | ||
| printf 'jpg image 1\n' >"$theme_dir/backgrounds/1-cosmic.jpg" | ||
| printf 'jpg image 2\n' >"$theme_dir/backgrounds/2-meadow.jpg" | ||
|
|
||
| # Non-headless runs reach the session hooks, which signal terminals and change desktop settings. | ||
| # The post-theme commands start through bash -lc, whose profile restores a dev-linked bin, so drop them. | ||
| stub_bin="$test_tmp/bin" | ||
| mkdir -p "$stub_bin" | ||
| printf '#!/bin/bash\n[[ $1 == -lc ]] && exit 0\nexec /bin/bash "$@"\n' >"$stub_bin/bash" | ||
| for command in omarchy-shell omarchy-hook omarchy-notification-send omarchy-theme-set-herdr-machines omarchy-theme-bg-cache; do | ||
| printf '#!/bin/bash\nexit 0\n' >"$stub_bin/$command" | ||
| done | ||
| chmod +x "$stub_bin"/* | ||
|
|
||
| run_theme_set() { | ||
| HOME="$home" OMARCHY_PATH="$mock_root" PATH="$stub_bin:$ROOT/bin:$PATH" \ | ||
| XDG_RUNTIME_DIR="$runtime_dir" \ | ||
| env "$@" bash "$ROOT/bin/omarchy-theme-set" "$theme_name" 2>"$test_tmp/stderr" || return $? | ||
| } | ||
|
|
||
| run_theme_refresh() { | ||
| HOME="$home" OMARCHY_PATH="$mock_root" PATH="$stub_bin:$ROOT/bin:$PATH" \ | ||
| XDG_RUNTIME_DIR="$runtime_dir" \ | ||
| OMARCHY_THEME_SKIP_BACKGROUND=1 \ | ||
| env "$@" bash "$ROOT/bin/omarchy-theme-set" "$theme_name" 2>"$test_tmp/stderr" || return $? | ||
| } | ||
|
|
||
| bg_link="$state/background" | ||
|
|
||
| # 1. Initial theme set establishes the background symlink. | ||
| run_theme_set OMARCHY_THEME_HEADLESS=1 || fail "initial theme set succeeds" | ||
| [[ -L $bg_link ]] || fail "theme set creates the background symlink" | ||
| initial_target=$(readlink -f "$bg_link") | ||
| [[ -f $initial_target ]] || fail "initial background symlink resolves to an existing file" | ||
|
|
||
| # 2. When the background file is still present, theme refresh does not cycle the wallpaper. | ||
| run_theme_refresh OMARCHY_THEME_HEADLESS=1 || fail "theme refresh succeeds" | ||
| refreshed_target=$(readlink -f "$bg_link") | ||
| [[ $refreshed_target == "$initial_target" ]] || \ | ||
| fail "theme refresh preserves the active background when still present" | ||
|
|
||
| pass "theme refresh preserves the active background when its file exists" | ||
|
|
||
| # 3. Simulate upstream converting backgrounds from .jpg to .webp. | ||
| # Set active link explicitly to 1-cosmic.jpg. | ||
| ln -nsf "$state/theme/backgrounds/1-cosmic.jpg" "$bg_link" | ||
| rm -f "$theme_dir/backgrounds/1-cosmic.jpg" | ||
| printf 'webp image 1\n' >"$theme_dir/backgrounds/1-cosmic.webp" | ||
|
|
||
| run_theme_refresh OMARCHY_THEME_HEADLESS=0 || fail "theme refresh succeeds after image format update" | ||
| [[ -e $bg_link ]] || fail "theme refresh does not leave a dangling symlink" | ||
| healed_target=$(readlink -f "$bg_link") | ||
| [[ $healed_target == "$state/theme/backgrounds/1-cosmic.webp" ]] || \ | ||
| fail "theme refresh matches converted background by filename stem" "$healed_target" | ||
|
|
||
| pass "theme refresh matches converted background extensions by stem" | ||
|
|
||
| # 4. When the active background is deleted with no matching stem, it falls back to an available background. | ||
| ln -nsf "$state/theme/backgrounds/deleted-art.png" "$bg_link" | ||
| run_theme_refresh OMARCHY_THEME_HEADLESS=0 || fail "theme refresh succeeds after missing background" | ||
| [[ -e $bg_link ]] || fail "theme refresh recovers from a missing background" | ||
| fallback_target=$(readlink -f "$bg_link") | ||
| [[ -f $fallback_target ]] || fail "recovered background link points to an existing file" | ||
|
|
||
| pass "theme refresh heals a dangling symlink when the file is removed" | ||
|
|
||
| # 5. Headless theme refresh also heals a dangling background symlink. | ||
| ln -nsf "$state/theme/backgrounds/vanished.png" "$bg_link" | ||
| run_theme_refresh OMARCHY_THEME_HEADLESS=1 || fail "headless theme refresh succeeds" | ||
| [[ -e $bg_link ]] || fail "headless theme refresh does not leave a dangling symlink" | ||
| headless_target=$(readlink -f "$bg_link") | ||
| [[ -f $headless_target ]] || fail "headless healed background points to a valid file" | ||
|
|
||
| pass "headless theme refresh repairs a dangling background symlink" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Knowledge Base Used: Theme switching and application sync
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!