Refresh the current palette before installing T3 Code
This commit is contained in:
2 files changed
+90
-27
No files matched your search
@@ -7,40 +7,22 @@ set -e
|
|||||||
|
|
||||||
T3CODE_HOME="${T3CODE_HOME:-$HOME/.t3}"
|
T3CODE_HOME="${T3CODE_HOME:-$HOME/.t3}"
|
||||||
T3CODE_STATE_DIR="$T3CODE_HOME/userdata"
|
T3CODE_STATE_DIR="$T3CODE_HOME/userdata"
|
||||||
T3CODE_SETTINGS_PATH="$T3CODE_STATE_DIR/settings.json"
|
|
||||||
|
|
||||||
# Ask T3 Code to open on the palette this machine publishes. `t3 theme set`
|
|
||||||
# is the supported way, but the desktop package ships only the GUI -- the CLI
|
|
||||||
# is a separate npm distribution -- so fall back to the setting it writes.
|
|
||||||
# Both run before the first launch, so neither races a running server.
|
|
||||||
set_default_theme() {
|
|
||||||
if omarchy-cmd-present t3; then
|
|
||||||
t3 theme set omarchy --base-dir "$T3CODE_HOME" >/dev/null && return
|
|
||||||
fi
|
|
||||||
|
|
||||||
local tmp
|
|
||||||
mkdir -p "$T3CODE_STATE_DIR"
|
|
||||||
[[ -f $T3CODE_SETTINGS_PATH ]] || echo '{}' >"$T3CODE_SETTINGS_PATH"
|
|
||||||
|
|
||||||
tmp=$(mktemp "$T3CODE_SETTINGS_PATH.XXXXXX")
|
|
||||||
if jq '.defaultTheme = "omarchy"' "$T3CODE_SETTINGS_PATH" >"$tmp"; then
|
|
||||||
mv "$tmp" "$T3CODE_SETTINGS_PATH"
|
|
||||||
else
|
|
||||||
rm -f "$tmp"
|
|
||||||
echo "Could not set the default theme in $T3CODE_SETTINGS_PATH." >&2
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "Installing T3 Code..."
|
echo "Installing T3 Code..."
|
||||||
omarchy-pkg-add t3code-bin
|
omarchy-pkg-add t3code-bin
|
||||||
|
|
||||||
# The palette itself, and the request to open on it, are both first-run
|
|
||||||
# concerns. `defaultTheme` only decides what a client with no theme of its own
|
|
||||||
# starts on, so choosing a theme in T3 Code later is never overridden.
|
|
||||||
echo "Matching T3 Code to the current theme..."
|
echo "Matching T3 Code to the current theme..."
|
||||||
mkdir -p "$T3CODE_STATE_DIR"
|
mkdir -p "$T3CODE_STATE_DIR"
|
||||||
|
|
||||||
|
# An updated user's current theme may have been staged before this template existed.
|
||||||
|
if [[ ! -f $HOME/.local/state/omarchy/current/theme/t3code.json ]]; then
|
||||||
|
omarchy-theme-refresh
|
||||||
|
fi
|
||||||
|
|
||||||
omarchy-theme-set-t3code
|
omarchy-theme-set-t3code
|
||||||
set_default_theme
|
|
||||||
|
# The packaged CLI selects the published palette before the app's first launch.
|
||||||
|
t3 theme set omarchy --base-dir "$T3CODE_HOME"
|
||||||
|
|
||||||
echo "Opening T3 Code..."
|
echo "Opening T3 Code..."
|
||||||
setsid uwsm-app -- gtk-launch t3code >/dev/null 2>&1 &
|
setsid uwsm-app -- gtk-launch t3code >/dev/null 2>&1 &
|
||||||
|
|||||||
Executable
+81
@@ -0,0 +1,81 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||||
|
|
||||||
|
test_tmp=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$test_tmp"' EXIT
|
||||||
|
|
||||||
|
test_home="$test_tmp/home"
|
||||||
|
mock_bin="$test_tmp/bin"
|
||||||
|
mkdir -p "$mock_bin"
|
||||||
|
|
||||||
|
# Run the real theme refresh, renderer and publisher in a throwaway home.
|
||||||
|
# Only package installation, the T3 CLI and desktop launch are stubbed.
|
||||||
|
cat >"$mock_bin/omarchy-pkg-add" <<'SH'
|
||||||
|
#!/bin/bash
|
||||||
|
[[ $1 == "t3code-bin" ]]
|
||||||
|
SH
|
||||||
|
|
||||||
|
cat >"$mock_bin/t3" <<'SH'
|
||||||
|
#!/bin/bash
|
||||||
|
[[ $1 == "theme" && $2 == "set" && $3 == "omarchy" && $4 == "--base-dir" && $5 == "$T3CODE_HOME" ]] || exit 1
|
||||||
|
palette="$T3CODE_HOME/userdata/themes/omarchy.json"
|
||||||
|
if [[ ! -f $palette ]] || ! jq -e '.name == "Omarchy" and (.accent | test("^#[0-9a-fA-F]{6}$"))' "$palette" >/dev/null; then
|
||||||
|
echo "No published Omarchy theme"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ ${OMARCHY_TEST_T3_FAIL:-0} == "1" ]]; then
|
||||||
|
echo "T3 theme selection failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "T3 selected Omarchy"
|
||||||
|
SH
|
||||||
|
|
||||||
|
cat >"$mock_bin/setsid" <<'SH'
|
||||||
|
#!/bin/bash
|
||||||
|
exit 0
|
||||||
|
SH
|
||||||
|
chmod +x "$mock_bin"/*
|
||||||
|
|
||||||
|
run_installer() {
|
||||||
|
HOME="$test_home" T3CODE_HOME="$test_tmp/custom t3 home" \
|
||||||
|
OMARCHY_PATH="$ROOT" PATH="$mock_bin:$ROOT/bin:$PATH" \
|
||||||
|
OMARCHY_THEME_HEADLESS=1 XDG_RUNTIME_DIR="$test_tmp" \
|
||||||
|
"$ROOT/bin/omarchy-install-ai-t3-code" >"$test_tmp/output" 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
state="$test_home/.local/state/omarchy/current"
|
||||||
|
palette="$test_tmp/custom t3 home/userdata/themes/omarchy.json"
|
||||||
|
settings="$test_tmp/custom t3 home/userdata/settings.json"
|
||||||
|
mkdir -p "$state/theme"
|
||||||
|
echo 'tokyo-night' >"$state/theme.name"
|
||||||
|
cp "$ROOT/themes/tokyo-night/colors.toml" "$state/theme/colors.toml"
|
||||||
|
|
||||||
|
run_installer || fail "installing after an update succeeds" "$(cat "$test_tmp/output")"
|
||||||
|
[[ -f $state/theme/t3code.json && -f $palette ]] || fail "the missing palette is rendered and published"
|
||||||
|
cmp -s "$state/theme/t3code.json" "$palette" || fail "T3 receives the current theme's palette"
|
||||||
|
grep -q 'T3 selected Omarchy' "$test_tmp/output" || fail "the published palette is selected"
|
||||||
|
grep -q 'Opening T3 Code' "$test_tmp/output" || fail "the themed app opens"
|
||||||
|
[[ ! -e $test_home/.t3 ]] || fail "the custom T3 home is respected"
|
||||||
|
pass "an update with no staged T3 palette renders, publishes and selects it before launch"
|
||||||
|
|
||||||
|
# Preserve an already rendered palette, including a user-supplied color.
|
||||||
|
jq '.accent = "#abcdef"' "$state/theme/t3code.json" >"$test_tmp/palette.json"
|
||||||
|
cp "$test_tmp/palette.json" "$state/theme/t3code.json"
|
||||||
|
run_installer || fail "installing with an existing palette succeeds" "$(cat "$test_tmp/output")"
|
||||||
|
cmp -s "$test_tmp/palette.json" "$palette" || fail "an existing palette is published without re-staging"
|
||||||
|
pass "an existing palette is used without refreshing the current theme"
|
||||||
|
|
||||||
|
printf '{"defaultTheme":"dark","keep":"existing settings"}\n' >"$settings"
|
||||||
|
cp "$settings" "$test_tmp/settings-before.json"
|
||||||
|
if OMARCHY_TEST_T3_FAIL=1 run_installer; then
|
||||||
|
fail "a failed T3 theme selection fails the installer"
|
||||||
|
fi
|
||||||
|
grep -q 'T3 theme selection failed' "$test_tmp/output" || fail "the CLI failure is visible"
|
||||||
|
if grep -Eq 'Opening T3 Code|T3 Code has been installed' "$test_tmp/output"; then
|
||||||
|
fail "a failed selection does not report successful setup"
|
||||||
|
fi
|
||||||
|
cmp -s "$test_tmp/settings-before.json" "$settings" || fail "a failed selection does not rewrite settings"
|
||||||
|
pass "a CLI failure remains visible and leaves the existing settings intact"
|
||||||
Reference in new issue
Block a user