Repository navigation
refactor(app): make the display state private - #581
Conversation
|
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 configurationConfiguration used: Repository: LargeModGames/spotatui/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (70)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughApp 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. ChangesApp State and Display Updates
Priority: ⬇️ Low Estimated code review effort: 4 (Complex) | ~45 minutes Change: Refactor Merge Risk: ⚪ Minimal · up to No identified issue blocks merging after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to 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 Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
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. Comment |
190a0ad to
1e7efb7
Compare
|
@coderabbitai review |
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
1e7efb7 to
77b19c3
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
# 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 -->
Summary
This makes most of the display state on
Appprivate, so each write goes through a method that bumps the matchingDisplayRevisionscounter from the PR below. A frontend can then redraw a domain only when its revision moved.DisplayDomaingainsParty,Devices,Search,Lyrics,Artist,LibraryandQueue.What changed:
devices,search_results,party_statusandparty_sessionare private. Writes go throughset_devices,set_search_results,set_party_status,set_party_sessionandparty_session_mut.set_search_resultsnow owns the cursor clamp, andclamp_search_cursorsis private. Readers outsidecore/appuse getters.lyrics,lyrics_statusandlyrics_syncedare private behindApp::set_lyrics. The LRCLIB answer is applied by a pureapply_lyrics_response.Artistrevision where their producers finish (App::bump_displayininfra/network/metadata.rs, and incore/app/library.rs).DjStategets arevisionthat its mutators bump: turn start and finish, transcript lines, the step, the vibe, library indexing and the two toggles._mutaccessor per field. The accessor bumps theLibraryrevision. The in-app pagers and sorts use it too.queuestays public.note_playback_changebecomesnote_display_changes, which also compares the Spotify queue mirror, the native queue and the queue-slot track at the same boundaries and bumpsQueueon a difference. It compares by reference and clones only on a change.show_source_search_tracksbumpsSearchwithout the clamp, so a decoded-source search leaves the hidden result blocks' cursors for the next Spotify search, as before.tools/gates.count:pub_fields_on_app139 -> 117,app_field_writes_in_tui_handlers186 -> 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 warningson slim, headless, headless-streaming, mcp-only, ai-dj-only, default, theguileg and the five-sources set withaudio-viz-cpal: allFinished, no warnings.cargo test --locked,0 failedon every leg: slim1253 passed, headless851 passed, mcp-only1377 passed, ai-dj-only1530 passed(the four dead-code warnings ininfra/djtest helpers predate this stack), default1630 passed,guileg1369 passed.On this PR's own head:
cargo clippy --locked -- -D warningson slim, headless and default: clean.cargo test --no-default-features --features telemetry,tui gates:ok. 10 passed.bash tools/check_gates_ratchet.shagainst the PR below:ok.Additional notes
Part 4 of 7 of a stack (#578 to #584). Base: #580.
The Linux
all-sourcestest leg and the macOS job run only in CI.Known trade-offs:
_mutaccessor bumpsLibrarywhen it is called, whether or not the caller then writes. That can cause an extra redraw, never a missed one.DjState.revisiondoes not move for the setup picker or prompt edits. Those are presentation state.App::display_revisionsiscfg(any(test, feature = "gui")).Follow-ups:
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 anArtistbump. 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