diff --git a/bin/omarchy-theme-set b/bin/omarchy-theme-set index 28b8ca8b2928..e85c043d6105 100755 --- a/bin/omarchy-theme-set +++ b/bin/omarchy-theme-set @@ -376,6 +376,13 @@ report_ignored_theme_files() { echo "Ignored in $USER_THEMES_PATH/$THEME_NAME: ${IGNORED_THEME_FILES[*]}" >&2 echo "A theme installed from a git repo cannot supply Lua, a terminal config, or vscode.json." >&2 + + # The menu discards stderr, so show the refusal when switching themes. + [[ $THEME_NAME == "$PREVIOUS_THEME_NAME" ]] && return 0 + + omarchy-notification-send -t 10000 \ + --body-text "$(omarchy-i18n theme.refusedFiles "${IGNORED_THEME_FILES[*]}")" \ + "$(omarchy-i18n theme.partNotApplied "$THEME_NAME")" >/dev/null 2>&1 || true } # A folder of exactly the given name wins, so a hand-made "Walk Handmade Theme" or "Gruvbox" is reachable; diff --git a/default/i18n/en/cli.json b/default/i18n/en/cli.json index 25d89fd00d1c..284a4c098e89 100644 --- a/default/i18n/en/cli.json +++ b/default/i18n/en/cli.json @@ -445,6 +445,8 @@ "theme.commandsFailed": "%1 failed. See %2", "theme.noBackground": "No background was found for theme", "theme.notAppliedEverywhere": "Theme not applied everywhere", + "theme.partNotApplied": "Part of %1 was not applied", + "theme.refusedFiles": "An installed theme cannot supply: %1", "theme.removeExtraTitle": "Remove extra theme", "theme.removed": "Theme removed", "theme.repoPlaceholder": "Git repo URL (https or git@host:org/repo.git)", diff --git a/test/shell.d/theme-staging-test.sh b/test/shell.d/theme-staging-test.sh index e2aca9ec8350..71201e1a7478 100755 --- a/test/shell.d/theme-staging-test.sh +++ b/test/shell.d/theme-staging-test.sh @@ -19,9 +19,22 @@ mkdir -p "$state" "$themes" marker="omarchy-theme-staging-marker" +# A refusal is only useful if it reaches the person who switched the theme, so +# record what would have been sent rather than trusting the stderr lines. +notifications="$test_tmp/notifications" +stub_bin="$test_tmp/stub-bin" +mkdir -p "$stub_bin" +cat >"$stub_bin/omarchy-notification-send" <<'STUB' +#!/bin/bash +printf '%s\n' "$@" >>"$OMARCHY_TEST_NOTIFICATIONS" +STUB +chmod +x "$stub_bin/omarchy-notification-send" + set_theme() { - HOME="$home" OMARCHY_PATH="$ROOT" PATH="$ROOT/bin:$PATH" \ + : >"$notifications" + HOME="$home" OMARCHY_PATH="$ROOT" PATH="$stub_bin:$ROOT/bin:$PATH" \ OMARCHY_THEME_HEADLESS=1 OMARCHY_THEME_SKIP_BACKGROUND=1 \ + OMARCHY_TEST_NOTIFICATIONS="$notifications" \ XDG_RUNTIME_DIR="$test_tmp" \ bash "$ROOT/bin/omarchy-theme-set" "$1" 2>"$test_tmp/stderr" || return $? } @@ -97,6 +110,14 @@ assert_staged backgrounds/1-real.png "an image in backgrounds/ is staged" assert_not_staged unlock.png "a symlink is not followed out of the theme" assert_not_staged vscode.json "vscode.json names an extension to install and is not staged" +grep -q 'hyprland.lua' "$notifications" || + fail "the refusal is announced, not left on stderr" "$(cat "$notifications")" +grep -qx -- '--body-text' "$notifications" || + fail "refused filenames are sent as literal text" "$(cat "$notifications")" +grep -q 'not applied' "$notifications" || + fail "the announcement says something was not applied" "$(cat "$notifications")" +pass "an installed theme's refused files are announced to the user" + assert_staged icons.theme "the theme's icon set name is staged" grep -q 'Yaru-red' "$(staged icons.theme)" || fail "the staged icons.theme is the theme's" assert_staged btop.theme "the theme's btop colours are staged" @@ -119,6 +140,10 @@ grep -q 'hyprland.lua' "$test_tmp/stderr" || fail "omarchy-theme-set names the f pass "an installed theme keeps its colour and loses everything that runs code" +set_theme hostile || fail "omarchy-theme-set reapplies the current theme" +grep -q 'hyprland.lua' "$test_tmp/stderr" || fail "refreshing still reports refused files on stderr" +[[ ! -s $notifications ]] || fail "refreshing the current theme does not announce the refusal again" + # A theme's files are staged verbatim, so a symlinked one would stage a copy # of whatever it points at. linked="$themes/linked" @@ -187,6 +212,16 @@ assert_staged vscode.json "a theme the user wrote keeps every file it ships" pass "a theme the user wrote is not held to the installed-theme list" +# Nothing was refused, so nothing should be announced: the notification has to +# report a real loss, not fire on every theme switch. +clean="$themes/clean" +mkdir -p "$clean/.git" +write_colors "$clean/colors.toml" +set_theme clean || fail "omarchy-theme-set applies an installed theme with no disallowed files" +[[ ! -s $notifications ]] || + fail "a theme with nothing refused announces nothing" "$(cat "$notifications")" +pass "a theme with nothing refused announces nothing" + # A working copy symlinked into the themes folder is the user's own too. ln -s "$mine" "$themes/mine-link" set_theme mine-link || fail "omarchy-theme-set applies a symlinked working copy"