feat(desktop,cli): live-reload settings and themes when the CLI changes them
Summary
superset settings ...changes now apply to a running desktop app instantly — theme switches, custom-theme imports, and typography included. No window refocus, no relaunch.- Follow-up to #6402, which shipped the CLI with documented propagation caveats (focus-refetch for settings, restart for themes). This removes both.
Why / Context
The theme lived in app-state.json, read once at boot; regular settings refreshed only on window refocus. That made the in-app story weak (an agent in a Superset terminal changes a setting and the visible app lags behind) and theme changes required a quit → set → relaunch dance where a running app could even clobber the external write.
How It Works
- Desktop: the existing local notifications server (the one agent hooks already POST to) gains
POST /settings-changed. The handler reads no request data — it re-readsthemeStatefrom disk into lowdb's in-memory doc (deliberately only themeState: a fulldb.read()could revert in-memory tabs/agent-session state with unflushed updates) and emits aSETTINGS_EXTERNAL_CHANGEevent through the existingnotifications.subscribetRPC subscription. Fixing memory-vs-disk here also kills the clobber problem at its root: after the nudge, the app's own flushes preserve the CLI's theme. - Renderer: a new
useSettingsExternalChangeListener(mounted in the authenticated layout) applies the canonical theme state via a newapplyExternalThemeStatestore action (wholesale replace + re-apply; malformed custom-theme entries filtered) and invalidates allsettings.*queries so fonts/toggles refetch immediately. - CLI: after every write (
set,reset,theme set/import/remove) it POSTs the nudge — 500 ms timeout, best-effort, silent on failure. Messages adapt to the outcome:Applied to the running desktop app.when acknowledged, the previous focus/restart guidance otherwise (older app versions return 404 → graceful fallback; no version coupling).
Security note
The endpoint is unauthenticated on the localhost server (same as the existing agent-hook routes) but reads nothing from the request and only triggers a re-read of local files plus a renderer refetch — no data exposure, no writable surface.
Manual QA (CDP against the dev desktop, port ownership verified)
-
theme set light/theme set darkwhile the app runs:--sidebarCSS var flips within ~1s, no restart (dark#1a1716↔ lightoklch(0.985 0 0)) -
set terminalFontSize 22with the Appearance page open: live preview label updates14px → 22pxwith zero focus events;resetreturns it - Delivery verified independently via an ad-hoc
notifications.subscribesubscription receivingsettings-external-change - CLI messaging: "Applied to the running desktop app." with the app up; old fallback text with it stopped
- Debugging detour worth recording: initial failures were not the mechanism — the workspace dev DB lacked
users.deletion_requested_at(main's code ahead of the Neon parent branch), so the app sat signed-out on/sign-inwhere the authenticated layout (and listener) never mounts. Fixed viasetup.sh --force+ applying the repo's pendingpackages/dbmigration to the isolated workspace branch.
Testing
bun test(packages/cli): 96 tests including new nudge-helper coverage (ack → true, dead port → fast false, 404/older app → false)bun run typecheckon desktop + cli; targeted biome clean- Desktop unit-test surface for main/renderer event plumbing is thin (no harness for the notifications server); covered by the CDP QA above
Rollout
- No migration, no config. Old CLI + new app: nothing calls the endpoint (inert). New CLI + old app: 404 → fallback messaging identical to today's behavior.
Summary by cubic
Live‑applies CLI‑driven settings and theme changes to a running desktop app. Previously settings refreshed on window focus and themes required a restart; now both update instantly, with fallback when no app is running or on older app versions.
-
Desktop: adds
POST /settings-changedon the local notifications server; re‑reads onlythemeStatefrom disk into lowdb memory and emitsSETTINGS_EXTERNAL_CHANGE; responds with{ success, themeReloaded }. -
Renderer: mounts
useSettingsExternalChangeListenerin the authenticated layout; replaces theme viaapplyExternalThemeState; invalidates allsettings.*queries andFONT_SETTINGS_QUERY_KEY. -
CLI: after
settings set/resetandtheme set/import/remove, sends a 500 ms nudge and adapts messages (“The running desktop app refreshed immediately.” / “Applied to the running desktop app.”) or falls back to focus/restart guidance on failure (e.g., 404 from older apps). -
Security: unauthenticated localhost endpoint that reads no request data and only triggers local re‑read plus renderer refetch.
-
Docs/tests: CLI reference and skill docs updated for live refresh; README demo GIF added; nudge tests cover ack, dead port, and 404.
-
Rollout: no migration. New CLI + old app returns 404 and falls back; old CLI + new app is inert.
Summary by CodeRabbit
- New Features
- CLI settings and theme changes now refresh the running desktop app immediately.
- Theme imports, removals, resets, and updates report whether the refresh succeeded.
- Changes apply when the app regains focus or launches if immediate refresh is unavailable.
- Bug Fixes
- Improved validation and fallback handling for externally applied themes.
- Documentation
- Updated CLI and settings guidance with restart instructions for older app versions.