Skip to content

refactor(app): make the display state private - #581

Merged
LargeModGames merged 5 commits into
mainfrom
refactor/private-display-domains
Sep 26, 2026
Merged

LargeModGames merged 5 commits into
mainfrom
refactor/private-display-domains

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

This makes most of the display state on App private, so each write goes through a method that bumps the matching DisplayRevisions counter from the PR below. A frontend can then redraw a domain only when its revision moved. DisplayDomain gains Party, Devices, Search, Lyrics, Artist, Library and Queue.

What changed:

  1. devices, search_results, party_status and party_session are private. Writes go through set_devices, set_search_results, set_party_status, set_party_session and party_session_mut. set_search_results now owns the cursor clamp, and clamp_search_cursors is private. Readers outside core/app use getters.
  2. lyrics, lyrics_status and lyrics_synced are private behind App::set_lyrics. The LRCLIB answer is applied by a pure apply_lyrics_response.
  3. The artist, album and show pages stay public and bump the Artist revision where their producers finish (App::bump_display in infra/network/metadata.rs, and in core/app/library.rs). DjState gets a revision that its mutators bump: turn start and finish, transcript lines, the step, the vibe, library indexing and the two toggles.
  4. The library pages, the playlist lists and folders, the saved-id sets, the user and the five per-source sidebar lists are private, with one getter and one _mut accessor per field. The accessor bumps the Library revision. The in-app pagers and sorts use it too.
  5. queue stays public. note_playback_change becomes note_display_changes, which also compares the Spotify queue mirror, the native queue and the queue-slot track at the same boundaries and bumps Queue on a difference. It compares by reference and clones only on a change.
  6. show_source_search_tracks bumps Search without the clamp, so a decoded-source search leaves the hidden result blocks' cursors for the next Spotify search, as before.
  7. tools/gates.count: pub_fields_on_app 139 -> 117, app_field_writes_in_tui_handlers 186 -> 147.

The setters bump only DisplayRevisions. The plugin data generations (PluginDataKind) bump where they did before, so plugins see no change.

No behaviour change.

Testing

The suites ran on the top of the stack (feat/gui-onboarding), which contains this PR:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --locked -- -D warnings on slim, headless, headless-streaming, mcp-only, ai-dj-only, default, the gui leg and the five-sources set with audio-viz-cpal: all Finished, no warnings.
  • cargo test --locked, 0 failed on every leg: slim 1253 passed, headless 851 passed, mcp-only 1377 passed, ai-dj-only 1530 passed (the four dead-code warnings in infra/dj test helpers predate this stack), default 1630 passed, gui leg 1369 passed.

On this PR's own head: cargo clippy --locked -- -D warnings on slim, headless and default: clean. cargo test --no-default-features --features telemetry,tui gates: ok. 10 passed. bash tools/check_gates_ratchet.sh against the PR below: ok.

Additional notes

Part 4 of 7 of a stack (#578 to #584). Base: #580.

The Linux all-sources test leg and the macOS job run only in CI.

Known trade-offs:

  • A _mut accessor bumps Library when it is called, whether or not the caller then writes. That can cause an extra redraw, never a missed one.
  • DjState.revision does not move for the setup picker or prompt edits. Those are presentation state.
  • Nothing outside tests reads the new revisions here. App::display_revisions is cfg(any(test, feature = "gui")).

Follow-ups:

  • The track table (track_table, playlist_track_*, recently_played) stays public with no revision.
  • App::raise_spotify_key_tier (from fix(spotify): handle removed endpoints for Development Mode apps #577) changes the artist page's empty Top Tracks text without an Artist bump. Nothing sends the artist page to a frontend yet, so it can bump when something does.

💬 Questions or want to chat with other contributors? Join the spotatui Discord.

Summary by CodeRabbit

  • Bug Fixes
    • Search results now consistently reset or clamp table cursors when replaced.
    • Updates to playlists, search results, lyrics, devices, artist information, queues, and party and DJ state are reflected more reliably in the display.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: bff413c1-931c-42df-93aa-3342b3619fcd

📥 Commits

Reviewing files that changed from the base of the PR and between e3d06fb and 77b19c3.

📒 Files selected for processing (70)
  • .github/copilot-instructions.md
  • AGENTS.md
  • CLAUDE.md
  • src/cli/cli_app.rs
  • src/cli/handle.rs
  • src/core/action/apply.rs
  • src/core/action/tests.rs
  • src/core/app/construction.rs
  • src/core/app/display_revisions.rs
  • src/core/app/dj.rs
  • src/core/app/library.rs
  • src/core/app/lyrics.rs
  • src/core/app/mod.rs
  • src/core/app/models.rs
  • src/core/app/party.rs
  • src/core/app/persistence.rs
  • src/core/app/playback_routing.rs
  • src/core/app/playlist_pages.rs
  • src/core/app/playlists.rs
  • src/core/app/queue.rs
  • src/core/app/tick.rs
  • src/core/app/transport.rs
  • src/core/app/view.rs
  • src/core/driver/mod.rs
  • src/core/plugin_api.rs
  • src/infra/dj/agent.rs
  • src/infra/dj/mod.rs
  • src/infra/local/dispatch.rs
  • src/infra/network/dj.rs
  • src/infra/network/library.rs
  • src/infra/network/metadata.rs
  • src/infra/network/mod.rs
  • src/infra/network/playback.rs
  • src/infra/network/search.rs
  • src/infra/network/user.rs
  • src/infra/network/utils.rs
  • src/infra/player/events.rs
  • src/infra/qobuz/dispatch.rs
  • src/infra/queue/dispatch.rs
  • src/infra/radio/dispatch.rs
  • src/infra/scripting/engine.rs
  • src/infra/scripting/tests.rs
  • src/infra/subsonic/dispatch.rs
  • src/infra/youtube/dispatch.rs
  • src/runtime/pump.rs
  • src/runtime/streaming/launch.rs
  • src/tui/handlers/album_list.rs
  • src/tui/handlers/album_tracks.rs
  • src/tui/handlers/artists.rs
  • src/tui/handlers/dialog.rs
  • src/tui/handlers/episode_table.rs
  • src/tui/handlers/local_browser.rs
  • src/tui/handlers/lyrics_view.rs
  • src/tui/handlers/mod.rs
  • src/tui/handlers/mouse.rs
  • src/tui/handlers/party.rs
  • src/tui/handlers/playlist.rs
  • src/tui/handlers/podcasts.rs
  • src/tui/handlers/search_results.rs
  • src/tui/handlers/select_device.rs
  • src/tui/handlers/track_table.rs
  • src/tui/runner.rs
  • src/tui/ui/artist.rs
  • src/tui/ui/library.rs
  • src/tui/ui/lyrics.rs
  • src/tui/ui/player.rs
  • src/tui/ui/popups.rs
  • src/tui/ui/search.rs
  • src/tui/ui/tables.rs
  • tools/gates.count

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

App state access now uses accessors instead of public fields. The change adds display revision tracking for additional state domains and updates state producers, callers, and tests to use the new APIs.

Changes

App State and Display Updates

Layer / File(s) Summary
App state accessors and contracts
src/core/app/*, AGENTS.md, CLAUDE.md, .github/copilot-instructions.md
App fields become private, and accessors are added for library, playlist, device, search, lyrics, and party state. Search-result replacement clamps cursors and bumps the Search revision.
Display revision updates
src/core/app/*, src/infra/dj/*, src/infra/network/dj.rs, src/core/action/tests.rs
Display revisions are added for more App domains and DJ state. Mutations and queue-view changes update the relevant revision. Tests check selected revision changes and stability.
Infrastructure state publishing
src/infra/network/*, src/infra/{local,qobuz,radio,subsonic,youtube}/*
Network and source handlers use App accessors to publish or read state. Lyrics responses are applied through a helper that sets lyric data and status.
Accessor adoption across callers
src/cli/*, src/core/plugin_api.rs, src/tui/*, src/infra/scripting/*, src/runtime/*, src/core/driver/mod.rs
CLI, plugin, TUI, scripting, and runtime code use App accessors instead of direct field access. Supporting tests and migration counters are updated.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 77b19

No identified issue blocks merging after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 77b19

The new accessors and revision counters affect several parts of the app. The examined party and plugin paths do not show expanded access or authority, but the wider migration has not been fully verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The examined plugin request path still routes data requests through App events rather than through the new mutable display-state accessors; the extent of other consumers was not fully checked.

Trust Boundaries and Controls

  • observed — Examined party consumers render sessions according to party status, and the interface offers the control-mode toggle from the Hosting branch rather than the Joined branch. The accessor itself adds no role check.

Resilience and Maintainability Implications

  • observed — Examined party cleanup paths clear the session after departure, room closure, or relay error. The new setter advances the Party revision when that state is published.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the allowed conventional-commit prefix refactor(app): and clearly describes the main change, making display state private.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
✨ Simplify code
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LargeModGames LargeModGames changed the title refactor/private display domains refactor(app): make the display state private Sep 26, 2026
@LargeModGames
LargeModGames force-pushed the refactor/private-display-domains branch from 190a0ad to 1e7efb7 Compare September 26, 2026 10:48
@LargeModGames

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Base automatically changed from feat/display-revisions to main September 26, 2026 11:25
Each field now changes only through an App setter that bumps its display revision: set_devices, set_search_results (which also clamps the search cursors, now private) and the party setters. The decoded-source searches go through the same funnel. Readers outside core/app use getters. Plugin data generations are unchanged.
Lyrics change only through App::set_lyrics, which bumps the Lyrics display revision; the LRCLIB answer is applied by a pure apply_lyrics_response. The artist, album and show pages bump the Artist revision where their producers finish, and DjState carries its own revision that every mutator of the DJ panel bumps.
The saved library pages, the playlist lists and folders, the saved-id sets, the user and the five per-source sidebar lists now change only through a _mut accessor that bumps the Library display revision. Readers outside core/app use getters. The in-app pagers and sorts go through the same accessor.
The boundary method that counts playback changes now also compares the queue a frontend shows (the Spotify queue mirror, the native queue and the track in the queue slot) and bumps a Queue display revision when it differs. The comparison allocates only on a change.
…the queue in place

A decoded-source search bumps the Search revision without the cursor clamp, so the hidden result blocks keep their cursors for the next Spotify search as before. The queue comparison reads the live queue by reference and clones only on a change. The radio and DJ revision tests now assert what they record.
@LargeModGames
LargeModGames force-pushed the refactor/private-display-domains branch from 1e7efb7 to 77b19c3 Compare September 26, 2026 11:25
@LargeModGames

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@LargeModGames
LargeModGames merged commit 4884ffb into main Sep 26, 2026
31 checks passed
@LargeModGames
LargeModGames deleted the refactor/private-display-domains branch September 26, 2026 11:43
LargeModGames added a commit that referenced this pull request Sep 26, 2026
# Summary

`spotatui-gui` was a placeholder that exited. It now boots like the
terminal UI (the same instance lock, `boot` and `prepare_frontend`),
serves an embedded page and a WebSocket on `127.0.0.1`, and opens the
browser at it.

What changed:

1. `src/gui/server.rs`: a loopback server on `httparse` and
`tokio_tungstenite::accept_hdr_async`. It checks `Host`, `Origin` and
`Sec-Fetch-Site` against DNS rebinding and cross-site pages, sends
`no-store`, `nosniff` and a strict CSP, and bounds each request and
handshake at 5 s.
2. The browser opens at `/#code=<code>`. The code is single-use, lives
60 s and is traded for a session token in `hello`. On Linux the server
also refuses loopback peers of other users (`/proc/net/tcp`).
3. `src/gui/protocol.rs` and `src/gui/bridge.rs`: `ClientMessage` in
(`action` through `App::apply`, `quit`), `Message` out: `hello`, a
resync, then each channel whose display revision moved (route, status,
theme, playback, devices, queue) and a position `tick` about every 250
ms.
4. `src/runtime/gui.rs`: a tick loop without a terminal. It boots with
`no_update: true` and quits on Ctrl-C, a `quit` from the page, or a
minute with no page.
5. `build.rs` embeds `gui/dist`. Without it `/` answers 503 with a build
hint.
6. `src/bin/spotatui-gui.rs` calls `run_gui`. A windowed release build
on Windows with no console shows its startup error in a message box.
7. `src/infra/loopback.rs` shares the token helpers with the MCP control
socket.
8. A `gui` leg in `ci.yml` (check, clippy, test), the third leg without
`tui`.

Deliberate behaviour changes a user can see:

1. Default and release builds: none. `gui` is off by default and no
release enables it.
2. `spotatui-gui` runs instead of exiting, and refuses to start beside
another spotatui UI.
3. On a fresh profile it stops and asks for one run of the terminal
`spotatui` first.

# Testing

The suites ran on the top of the stack (`feat/gui-onboarding`), which
contains this PR:

- `cargo fmt --all -- --check`: clean.
- `cargo clippy --locked -- -D warnings` on slim, headless,
headless-streaming, mcp-only, ai-dj-only, default, the `gui` leg and the
five-sources set with `audio-viz-cpal`: all `Finished`, no warnings.
- `cargo test --locked`, `0 failed` on every leg: slim `1253 passed`,
headless `851 passed`, mcp-only `1377 passed`, ai-dj-only `1530 passed`
(the four dead-code warnings in `infra/dj` test helpers predate this
stack), default `1630 passed`, `gui` leg `1369 passed`.

On this PR's own head: `cargo clippy --locked -- -D warnings` on slim,
headless, default and the `gui` leg (`--no-default-features --features
telemetry,gui,streaming,discord-rpc,self-update,scripting,mcp-server,mpris`):
clean. `cargo test --no-default-features --features telemetry,tui
gates`: `ok. 10 passed`. `bash tools/check_gates_ratchet.sh` against the
PR below: `ok`.

# Additional notes

Part 5 of 7 of a stack (#578 to #584). Base: #581.

Rebased onto #574 and #577. Beyond mechanical merges, the last commit
makes `run_gui` open its log through the same `start_logging` as
`run_cli`: `SPOTATUI_LOG`, a bare `--debug` (the crash notice asks for
it), and the startup header.

Not verified here: the Linux peer check and the MPRIS build without
`tui` run only in the `gui` CI leg, and no CI job builds `gui` on macOS.
A live pass on Windows ran against the top of the stack before the
rebase. This layer alone ships no page.

Residual risk: the launch code sits in the browser's command line while
it starts. macOS has no peer check, so another local user there could
race it. A private redirect file would keep the code out of argv, but
snap-confined browsers cannot read one.

`Source`, `Party`, `Search`, `Lyrics`, `Artist` and `Library` have
revisions but no message yet. The next PR adds the page, and the top PR
moves the first-launch questions into it.

---
<sub>💬 Questions or want to chat with other contributors? Join the
[spotatui Discord](https://spotatui.com/discord).</sub>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added a browser-based frontend, available through the GUI app. It
opens in your default browser and supports playback, queue, theme,
device, and other app updates.
  * Added secure local access controls for browser connections.
  * Added a GUI feature configuration to the CI matrix.

* **Improvements**
* Help, version, and command-line usage errors now appear before a log
file is created.
* Shared startup and shutdown behavior now supports both the terminal
and browser frontends.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant