diff --git a/themes/engine/scripts/nomarchy-theme-set b/themes/engine/scripts/nomarchy-theme-set index 304d2d7..297cb0a 100755 --- a/themes/engine/scripts/nomarchy-theme-set +++ b/themes/engine/scripts/nomarchy-theme-set @@ -51,25 +51,55 @@ nomarchy-env-update nomarchy-theme-set-templates +# Run the chain of "tell each app the theme changed" steps. Each step is +# optional — the corresponding helper might not be installed, the service +# might not be running, the user might not use Obsidian. Skipping is fine; +# what we don't want is a step that EXISTS, fails for a real reason, and +# leaves the user with a half-applied theme + no idea why. Collect every +# real failure into _theme_set_fails and surface them in one notify-send +# at the end so the user knows exactly what didn't refresh. +_theme_set_fails=() + +_theme_set_try() { + local label="$1"; shift + # First arg after label is the command to test for existence. + # `systemctl` always exists on a NixOS system, so we let it through + # and rely on its own exit code to decide skip vs fail. + if [[ "$1" != "systemctl" ]] && ! command -v "$1" >/dev/null 2>&1; then + return 0 # not installed → silently skip + fi + if ! "$@" >/dev/null 2>&1; then + _theme_set_fails+=("$label") + fi +} + # Walker reads its CSS via @import of ~/.config/nomarchy/current/theme/apps/walker/style.css, # and waybar's shared fallback style does the same with waybar.css. HM's sd-switch # only restarts services whose unit *definition* changed, so when only the imported # file's contents change, neither gets reloaded. Restart them explicitly. -command -v nomarchy-restart-walker >/dev/null 2>&1 && nomarchy-restart-walker || true -command -v nomarchy-restart-waybar >/dev/null 2>&1 && nomarchy-restart-waybar || true +_theme_set_try "Walker" nomarchy-restart-walker +_theme_set_try "Waybar" nomarchy-restart-waybar # Hot-reload long-running TUIs / agents that read their colors from # the active-theme symlink and would otherwise stay on the old palette # until the user restarts them by hand. -command -v nomarchy-restart-btop >/dev/null 2>&1 && nomarchy-restart-btop || true -command -v nomarchy-restart-opencode >/dev/null 2>&1 && nomarchy-restart-opencode || true +_theme_set_try "btop" nomarchy-restart-btop +_theme_set_try "opencode" nomarchy-restart-opencode # Sync palette into Obsidian vaults (no-op when the user has no Obsidian # config or no obsidian.css template in the active theme). -command -v nomarchy-theme-set-obsidian >/dev/null 2>&1 && nomarchy-theme-set-obsidian || true +_theme_set_try "Obsidian" nomarchy-theme-set-obsidian # Reload the wallpaper — its ExecStart path is stable (~/.config/nomarchy/current/background) # so sd-switch does not detect a unit change when only the symlink target moves. -systemctl --user restart nomarchy-wallpaper.service 2>/dev/null || true +_theme_set_try "wallpaper" systemctl --user restart nomarchy-wallpaper.service + +if (( ${#_theme_set_fails[@]} > 0 )); then + if command -v notify-send >/dev/null 2>&1; then + notify-send -u normal "Theme applied with warnings" \ + "Did not refresh: $(IFS=', '; echo "${_theme_set_fails[*]}")" + fi + echo "Warning: failed to refresh: ${_theme_set_fails[*]}" >&2 +fi nomarchy-hook theme-set "$THEME_NAME"