Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions scripts/colors/apply-spicetify-theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,53 @@ sync_live_user_css() {
cp "$user_css" "$live_user_css"
}

find_spicetify_wrapper_source() {
local candidate base

# setup/spotify.sh builds this asset for source-built Spicetify packages that
# omit it. This theme script does not build dependencies; it only preserves a
# working patched Spotify bundle across later theme reapplies.
if [[ -s "/opt/spicetify-cli/jsHelper/spicetifyWrapper.js" ]]; then
printf '%s\n' "/opt/spicetify-cli/jsHelper/spicetifyWrapper.js"
return 0
fi

for base in "$HOME/.cache/paru/clone/spicetify-cli" "$HOME/.cache/yay/spicetify-cli"; do
[[ -d "$base" ]] || continue
candidate="$(
find "$base" -maxdepth 5 -type f -path '*/jsHelper/spicetifyWrapper.js' -print 2>/dev/null \
| sort -Vr \
| head -n1
)"
if [[ -s "$candidate" ]]; then
printf '%s\n' "$candidate"
return 0
fi
done
}

sync_spicetify_wrapper() {
local xpui_dir="$1"
local index_html="$xpui_dir/index.html"
local live_wrapper="$xpui_dir/helper/spicetifyWrapper.js"

[[ -f "$index_html" ]] || return 1
grep -q "helper/spicetifyWrapper.js" "$index_html" || return 0
[[ -s "$live_wrapper" ]] && return 0

local wrapper_source=""
wrapper_source="$(find_spicetify_wrapper_source || true)"

if [[ -z "$wrapper_source" ]]; then
log "spicetifyWrapper.js is missing; run setup-spotify or pnpm build:wrapper in the Spicetify source tree"
return 1
fi

mkdir -p "$xpui_dir/helper"
cp "$wrapper_source" "$live_wrapper"
log "Synced missing spicetifyWrapper.js from $wrapper_source"
}

# ─── Main logic ────────────────────────────────────────────────────────────────

main() {
Expand Down Expand Up @@ -521,6 +568,10 @@ main() {
local spotify_running=false
is_process_running "spotify" && spotify_running=true

if [[ -n "$xpui_dir" ]]; then
sync_spicetify_wrapper "$xpui_dir" || true
fi

if [[ -n "$xpui_dir" ]] && is_live_install_patched "$xpui_dir"; then
if sync_live_user_css "$theme_dir/user.css" "$xpui_dir"; then
log "Synced live Spotify user.css"
Expand All @@ -544,6 +595,11 @@ main() {
exit 1
fi

xpui_dir="$(get_spotify_xpui_dir "$spicetify_config")"
if [[ -n "$xpui_dir" ]]; then
sync_spicetify_wrapper "$xpui_dir" || true
fi

# Some spicetify versions launch Spotify as a side effect despite -n.
# Kill it if it wasn't running before we called apply.
if ! $spotify_running && is_process_running "spotify"; then
Expand Down
19 changes: 19 additions & 0 deletions scripts/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,22 @@ Constants exposed after sourcing: `DISTRO_ID`, `DISTRO_LIKE`, `SETUP_TAG`,
the user can recover from manually should print actionable instructions.
- **One concern per script.** If a recipe grows beyond ~80 lines, factor a
helper into `_lib.sh` instead of duplicating logic.

## Spotify / Spicetify Notes

`spotify.sh` intentionally repairs a missing `spicetifyWrapper.js` before it
runs `spicetify backup apply`. Spicetify v2.44+ generates this file during the
release build from `src/jsHelper/spicetifyWrapper`. Some source-built Linux
packages have shipped `/opt/spicetify-cli/jsHelper` without running
`scripts/build-wrapper.mjs`; Spicetify still injects
`helper/spicetifyWrapper.js` into Spotify's `index.html`, and Spotify opens to
a blank XPUI surface when that helper is absent.

The recipe only builds the wrapper when `/opt/spicetify-cli/jsHelper/
spicetifyWrapper.js` is missing. It first reuses cached AUR source from `paru`
or `yay`; if no cache exists and the installed Spicetify version is a release
tag, it downloads the matching source tarball from GitHub. Node/npm are only
installed on-demand for this repair path. After Spicetify applies, the recipe
also verifies Spotify's patched XPUI helper directory contains the wrapper,
because a broken package asset directory can otherwise recreate the blank-window
state on every reapply.
10 changes: 9 additions & 1 deletion scripts/setup/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@ setup_fail() {
setup_notify "$msg" "dialog-error"
}

setup_err_trap() {
local status="$1"
local line="$2"
setup_fail "$SETUP_TITLE failed at line $line"
setup_finish_pause
exit "$status"
}

setup_init() {
SETUP_TAG="setup-$1"
SETUP_TITLE="$2"
trap 'setup_fail "$SETUP_TITLE failed at line $LINENO"' ERR
trap 'setup_err_trap "$?" "$LINENO"' ERR
setup_notify "Starting…" "download"
printf '\033[1;35m▶ %s\033[0m (distro: %s)\n' "$SETUP_TITLE" "$DISTRO_ID"
}
Expand Down
Loading