Commit Graph
527 Commits
Author SHA1 Message Date
vicrodh 916b4c145a debug: add aggressive logging to home loading flow (#43)
Log every decision point in loadHome():
- totalVisibleSections count
- mlPromise invoke/resolve/reject with seed counts
- fetchDiscoverData invoke/result with container keys
- checkAllSectionsReady transition with hasContent/error state
- catch block entry (which blocks all content rendering)

Backend: reco_get_home_ml logs call, success with counts, and
explicit error when RecoState.db is None.
2026-02-06 08:25:21 -06:00
vicrodh e14a364484 fix: add API response status logging and 404 handling to client
Add [API] log lines with HTTP status to all client methods for
debugging blank views (#43). Handle 404 explicitly in get_track
(returns TrackUnavailable) and get_album (returns ApiResponse)
instead of attempting JSON deserialization of error responses.
2026-02-06 08:17:44 -06:00
vicrodh 828b31671c fix: invalidate API cache on favorite mutations
add_favorite and remove_favorite now invalidate the corresponding
album/track/artist entry in the API cache after a successful API call.
This prevents stale JSON (missing the updated favorite status) from
being served on the next detail fetch. Added targeted invalidate_album,
invalidate_track, and invalidate_artist methods to ApiCache.
2026-02-06 06:13:14 -06:00
vicrodh 5b8e9920eb feat: cache genres with 7-day TTL
Genre lists from Qobuz are near-static, so caching them avoids
unnecessary API calls. Added cached_genres table with GENRE_TTL_SECS
(7 days), get/set methods, and wired cache into get_genres() command.
Also updated cleanup_expired and clear_all to include the new table.
2026-02-06 06:11:54 -06:00
vicrodh a4eb35002c refactor: centralize API headers into api_headers/authenticated_headers methods
Replace 30+ manual .header("X-App-Id")/("X-User-Auth-Token") calls with
two helper methods:
- api_headers(): always sends X-App-Id, optionally X-User-Auth-Token
- authenticated_headers(): requires auth, fails if not logged in

This fixes the root cause of #43 (get_album/get_track missing auth token)
by making it impossible to forget headers. Also removes DEBUG-43 verbose
response body logging from client.rs since the root cause is resolved.
2026-02-06 05:41:41 -06:00
vicrodh c94df8787f fix: add user auth token to get_album and get_track API calls
These endpoints were missing the X-User-Auth-Token header, causing
Qobuz to return 404 for all album and track detail requests. This is
the root cause of issue #43: blank album pages, "Unknown Artist" and
"0:00" in Recently Played / Continue Listening.

List endpoints (get_featured_albums) and playlist endpoints worked
because they either don't need auth or already included the token.

Closes #43
2026-02-06 05:17:02 -06:00
vicrodh a75f957cc9 add DEBUG-43 logging to album/track detail fetch pipeline
Add info-level logging with [DEBUG-43] prefix to:
- get_album/get_track commands: cache hit/miss/error, API errors
- API client get_album/get_track: request URL, response status, response
  body preview (first 500 chars), parse/deserialize errors

This traces the complete detail fetch path to diagnose why album/track
detail views fail for specific users while list endpoints work fine.
2026-02-06 03:16:18 -06:00
vicrodh b6d2e10471 persist last user_id for session restore across app restarts
Saves the active user_id to a flat-path file on activate_user_session
and clears it on deactivate_user_session (explicit logout). On startup,
if saved credentials and a last_user_id both exist, the per-user session
is restored before loading ToS acceptance or attempting auto-login.

This fixes the chicken-and-egg problem where ToS acceptance lived in the
per-user DB but was needed before login to allow auto-login.
2026-02-06 00:37:52 -06:00
vicrodh 03736ef8f2 exclude qobuz_download tracks from library stats when toggle is off
get_stats() now respects the show_in_library setting so offline cached
tracks don't inflate the Local Library counter when the user has chosen
not to show them there.
2026-02-06 00:30:24 -06:00
vicrodh 6ef50f7dc2 fix offline cache_dir not updating to user-scoped path
OfflineCacheState.cache_dir was set during new_empty() to the flat path
(~/.cache/qbz/audio/) and never updated when init_at() opened the DB at
the user-scoped path. This caused track files and artwork to be
read/written at the wrong location. Wrapped cache_dir in Arc<RwLock<>>
and update it during init_at().
2026-02-06 00:07:14 -06:00
vicrodh 2dfb014a1e fix tokio panic: use async lock in init_at/teardown for tokio-mutex modules
blocking_lock() panics when called from within the tokio async runtime.
Changed init_at() and teardown() to async fn with .lock().await for all
8 modules using tokio::sync::Mutex (library, reco, api_cache,
artist_vectors, musicbrainz, listenbrainz, offline_cache, lyrics).
Updated activate/deactivate_user_session to .await these calls.
2026-02-05 23:47:48 -06:00
vicrodh b936490969 add user_id to LoginResponse and activate/deactivate session commands
LoginResponse now includes user_id from the Qobuz API session.

activate_user_session: called after login with user_id, runs one-time
flat-to-user migration, then initializes all 22+ per-user stores at
~/.local/share/qbz/users/{uid}/ and ~/.cache/qbz/users/{uid}/.
Also runs deferred subscription purge check.

deactivate_user_session: called before logout, tears down all per-user
stores to close database connections and clears the active user.
2026-02-05 23:19:23 -06:00
vicrodh 5a3399c677 switch to two-phase startup: empty per-user states until login
Phase 1 (device-level): Read audio/tray settings from flat path once
for player and tray init. Initialize cast, DLNA, API server.

Phase 2 (per-user): All 22 per-user states init as new_empty().
They get populated after login via activate_user_session.

Subscription purge check deferred to activate_user_session.
2026-02-05 23:15:14 -06:00
vicrodh dbb5d998de update all command handlers for Option-wrapped per-user state
Modify callers in commands/, cast/, library/, and lib.rs to unwrap
Option<Store> with appropriate error messages. Fix drop(db) to
drop(guard__) for correct mutex release.
2026-02-05 23:11:17 -06:00
vicrodh aab3e67641 add per-user isolation support to all remaining modules
Add new_at() constructors, Option<Store> wrappers, new_empty()/init_at()/
teardown() methods, and update all commands to unwrap Option for:
- config: audio_settings, download_settings, favorites_cache,
  favorites_preferences, legal_settings, playback_preferences,
  remote_control_settings, subscription_state, tray_settings
- data: api_cache, artist_blacklist, artist_vectors, library,
  listenbrainz, lyrics, musicbrainz, offline, offline_cache,
  radio_engine, reco_store, updates
2026-02-05 23:11:07 -06:00
vicrodh 48dac0ec3a add per-user isolation support to session_store
- Extract DB init into open_at() shared helper
- Add new_at(base_dir) constructor
- Wrap SessionStoreState inner store in Option<SessionStore>
- Add new_empty(), init_at(), teardown() lifecycle methods
- Update all tauri commands to unwrap Option with user-friendly error
2026-02-05 22:41:39 -06:00
vicrodh 079be6333e add migration module for flat-to-user data layout
One-time migration moves all existing DB files and cache directories
from the flat layout into users/{uid}/ subdirectories. The first user
to log in after the update inherits all existing data. A .migrated
marker file prevents re-running.

Handles WAL/SHM journal files, cross-device moves via copy+delete
fallback, and recursive directory copying.
2026-02-05 22:40:02 -06:00
vicrodh 441acafba5 add UserDataPaths module for per-user data isolation
Central path provider that holds the current user_id behind RwLock.
Provides user-scoped data and cache directory paths:
- ~/.local/share/qbz/users/{uid}/
- ~/.cache/qbz/users/{uid}/

Registered as Tauri managed state. No behavior change yet -
user paths are not used by any module until activate_user_session
is implemented.
2026-02-05 22:38:39 -06:00
vicrodh 7718f10b37 feat(visualizer): update TappedSource to work with f32 samples
Change Source<Item = i16> to Source<Item = f32> throughout.
Remove i16-to-f32 normalization since f32 samples are already in
[-1.0, 1.0] range. Update tests to use f32 sample data.
2026-02-05 16:20:03 -06:00
vicrodh a923798bae feat(audio): add write_f32() and migrate PlaybackEngine to f32 pipeline
PlaybackEngine::append() now accepts Source<Item = f32>.
ALSA Direct thread uses f32 buffer and calls write_f32().

New write_f32() method in AlsaDirectStream converts f32 samples to
hardware format with full 24-bit precision:
- S24_3LE: f32 -> 24-bit packed 3 bytes (SMSL/Topping DACs)
- S32LE: f32 -> i32 full range
- S24LE: f32 -> 24-bit in i32 container
- S16LE: f32 -> i16
- FloatLE: direct write

Old write(&[i16]) kept for safety during migration.
2026-02-05 16:19:27 -06:00
vicrodh 2c276154b8 feat(streaming): change IncrementalStreamingSource output from i16 to f32
Update sample queue, SampleBuffer, and Iterator Item type to f32.
Streaming playback from Qobuz now preserves 24-bit audio data.
2026-02-05 16:17:49 -06:00
vicrodh 1219493dff feat(player): change player module sample type from i16 to f32
Update AudioSpecs, decode_with_symphonia(), decode_with_fallback(),
wrap_source closure, and all Source boxing casts to use f32 samples.
This ensures 24-bit audio data flows through the player without
truncation to 16-bit.
2026-02-05 16:17:27 -06:00
vicrodh ba828866ef feat(rodio): change SymphoniaDecoder output from i16 to f32
Change SampleBuffer<i16> to SampleBuffer<f32> in the vendored rodio
decoder. This preserves 24-bit audio data (f32 has 24 bits of
significand) instead of truncating to 16-bit at decode time.

Affects: symphonia.rs (SampleBuffer, Iterator::Item)
         mod.rs (Decoder, LoopedDecoder, DecoderImpl Iterator::Item)
2026-02-05 16:16:34 -06:00
vicrodh c87f8f982e fix(audio): disable limit-quality-to-device feature (#45)
The device capability detection was unreliable, causing incorrect
downgrades to 16b/44.1kHz on some PipeWire+DAC setups. Disconnect
the quality limiting logic in play_track and prefetch_track, hide
the toggle from settings UI, and default to off. Code preserved
for future fix.
2026-02-05 08:32:13 -06:00
vicrodh de93411de0 fix(snap): allow portal override
cx
2026-02-05 02:21:18 -06:00
vicrodh 6d49e2ce5a chore: bump version to 1.1.8 2026-02-04 20:48:22 -06:00
vicrodh d30c25be85 fix(suggestions): search more tracks and try normalized artist names
1. Artist name normalization fallback:
   - If "Mikael Åkerfeldt" finds no results, also try "Mikael Akerfeldt"
   - Helps with artists whose Qobuz name lacks accents

2. Increased track search limits:
   - Playlist artists: search up to 30 tracks (was 9)
   - API search: fetch 100-500 results to find enough matches
   - Needed because search results mix artist's tracks with appearances

This should fix:
- Missing Opeth tracks (all 9 found were already in playlist)
- Mikael Åkerfeldt not found (Qobuz has "Mikael Akerfeldt")
2026-02-04 20:45:46 -06:00
vicrodh c28c80962b fix(genres): force English locale for genre list API
Ensures genre names are consistent (English) for all users regardless
of their Qobuz registration country. This affects the genre filter
in Home and Favorites views.
2026-02-04 20:40:35 -06:00
vicrodh 39c67123e7 fix(suggestions): force English locale for genre checking
Qobuz returns localized genre names based on user's registered address,
not app language. This caused genre filtering to fail when user sees
"América Latina" instead of "Latin".

Solution: Pass lang=en explicitly when fetching artist albums for genre
verification. This ensures consistent English genre names regardless of
user's registration country.

Also simplified the incompatible genres list since we only need English now.
2026-02-04 20:39:50 -06:00
vicrodh c4432dea80 fix(suggestions): add localized genre names and improve logging
1. Add localized genre names to blocklist:
   - Spanish: "América latina", "música latina", "infantil", etc.
   - French: "variété française", "comptines", etc.
   - German: "Kindermusik", etc.

2. Upgrade step 4a logging to INFO level to debug missing Opeth tracks
   - Shows which playlist artists are being searched
   - Shows how many tracks found vs skipped (already in playlist)
2026-02-04 20:37:35 -06:00
vicrodh 295d0496d2 fix(suggestions): resolve deadlock in Qobuz similar artists fallback
Pass client reference to search_artist_tracks_by_qobuz_id instead of
acquiring a new lock, which caused deadlock when step 4c already held
the qobuz_client lock.
2026-02-04 20:32:44 -06:00
vicrodh f385e3a75b fix(suggestions): add Qobuz similar artists fallback and accent normalization
Two improvements:

1. Accent normalization in artist validation
   - Now "Mikael Åkerfeldt" matches "Mikael Akerfeldt" in Qobuz
   - Uses existing normalize_name() function for comparison

2. Qobuz similar artists as fallback (step 4c)
   - When pool has <20 tracks after MusicBrainz relationships
   - Fetches similar artists from Qobuz API for each playlist artist
   - These artists are guaranteed to exist in Qobuz
   - Still applies genre compatibility filter

This ensures playlists with few MusicBrainz relationships (like solo
artists) still get meaningful suggestions from Qobuz's own similarity
data.
2026-02-04 20:23:29 -06:00
vicrodh c30b367e07 fix(suggestions): expand incompatible genre list
Add more genres and keywords to filter:
- Electronic/Dance: trance, techno, house, EDM, dubstep, etc.
- Spoken word: audiobook, hörbuch, podcast, meditation, ASMR
- Country: country, bluegrass, americana
- New age: healing, spa, yoga, mindfulness
- Additional title keywords: "gelesen von", "read by", "trance mix"

This prevents suggestions like:
- Tony Parsons (trance DJ) in Iron Maiden playlist
- Tony Parsons (German audiobook narrator) in metal playlist
2026-02-04 20:14:34 -06:00
vicrodh c03c5e525c fix(suggestions): add genre validation to filter incompatible artists
When validating if an artist exists in Qobuz, now also checks their
album genres against a blocklist. This prevents false matches like:

- "Martin Lopez" (bachata singer) matching when we want the drummer
- "Martin Mendez" (merengue) matching when we want the bassist

Incompatible genres: bachata, merengue, reggaeton, salsa, cumbia,
k-pop, j-pop, gospel, children's music, etc.

The validation fetches up to 5 albums and checks both genre metadata
and album titles for incompatible keywords.
2026-02-04 19:55:37 -06:00
vicrodh eb7e848e94 fix(suggestions): validate artists exist in Qobuz before searching tracks
Add pre-validation step that checks if an artist has a dedicated Qobuz
page before searching for their tracks. This prevents false matches for:

- Session musicians who don't have their own catalog (e.g., Martin Lopez
  the drummer returning tracks from unrelated Martin Lopez artists)
- Names that exist in MusicBrainz but not in Qobuz's artist database

The validation searches Qobuz artists for exact name match with
albums_count > 0. Also matches tracks by Qobuz artist ID when possible
(more precise than name matching).

Also fix outdated test assertions for config defaults.
2026-02-04 19:46:50 -06:00
vicrodh 4af2b0b1bd fix(suggestions): even stricter name matching for 2-word names
- For 2-word names: require EXACT same words (no extra words allowed)
- 'Martin Lopez' vs 'Tomas Martin Lopez' → REJECT (different word count)
- 'George Harrison' vs 'Harrison, George' → ACCEPT (same words, different order)
2026-02-04 19:41:54 -06:00
vicrodh 3a94e250c7 fix(suggestions): strict artist name matching to prevent false positives
- Add normalize_name() to handle accents (Martín -> Martin)
- Require ALL words of shorter name to match longer name
- Remove permissive 'contains' checks that allowed partial matches
- For 2-3 word names, require 66%+ match ratio
- Prevents 'Martín Méndez' from matching 'Tomas Martin Lopez'
2026-02-04 19:40:54 -06:00
vicrodh ed1bd31554 fix(suggestions): improve pool management and artist identity validation
- Increase pool sizes (INITIAL_POOL 18->30, EXPANDED_POOL 60->100, MAX_POOL 120->200)
- Add auto-refresh when available tracks fall below threshold (MIN_AVAILABLE_THRESHOLD=12)
- Add artist identity validation to filter incompatible genres (prevents merengue in metal playlists)
- Log when artists are skipped due to incompatible disambiguation
- Increase backend defaults (max_artists 20->30, tracks_per_artist 5->6, max_pool_size 100->150)
2026-02-04 19:34:52 -06:00
vicrodh 94c867c934 chore: bump version to 1.1.8-rc-6 for workflow testing 2026-02-04 18:46:58 -06:00
vicrodh deaffa183d feat(home): add Qobuz discover playlists section with tag filter
- Add backend endpoint for /discover/playlists API
- Add PlaylistTagFilter dropdown component for filtering by genre
- Add QobuzPlaylistCard with CSS blur background effect (color-thief style)
- Add HorizontalScrollRow header snippet for custom headers with scroll controls
- Add session cache store for caching API responses
- Add i18n keys for playlist filter and discover section

cc
2026-02-03 21:37:26 -06:00
vicrodh 9341e9ee19 fix: migrate cached_artists table to include locale column
Old database schemas created before locale support was added
caused "no such column: locale" errors when fetching artists.
The migration detects this and drops the old table so it gets
recreated with the correct schema.

Fixes Top Artists section not appearing in Home view.
2026-02-03 17:11:38 -06:00
vicrodh 2818ac4d29 security: improve credential encryption and CORS configurability
Security improvements based on code review:

1. Credential Encryption (Critical)
   - Replace XOR obfuscation with AES-256-GCM encryption
   - Derive key from machine ID (tied to specific machine)
   - Add migration support for legacy XOR format
   - Automatic re-encryption on first load of legacy credentials

2. HTTPS Default (Medium)
   - Change default `secure` setting to `true` for new installs
   - Existing users keep their current setting

3. Configurable CORS Origins (High)
   - Replace hardcoded domain whitelist with SQLite-backed storage
   - Default origins: vicrodh.github.io, control.qbz.lol
   - Add commands: get/add/remove origins, restore defaults
   - Origins can be customized for third-party clients
   - Server restarts automatically when origins change

New dependencies:
   - aes-gcm: AES-256-GCM authenticated encryption
   - sha2: SHA-256 for key derivation
2026-02-03 12:36:18 -06:00
vicrodh 8e7d9de754 docs: add OpenAPI specification for Remote Control API
Add comprehensive OpenAPI 3.1 documentation covering all REST endpoints:
- Connection/auth endpoints (ping, cert)
- Playback control (play, pause, seek, volume, next, previous)
- Queue management (add, shuffle, repeat, play index)
- Search (tracks, albums, artists)
- Favorites management
- Library (album/artist details)
- Real-time updates (SSE and WebSocket)

Also add /api/docs endpoint to serve the spec when Remote Control is active.
This enables developers to build custom clients (web, CLI, mobile).
2026-02-03 11:34:04 -06:00
vicrodh 1039241d28 feat(api): add SSE endpoint for real-time playback updates
Add /api/events endpoint using Server-Sent Events (SSE) as a more
efficient alternative to WebSocket for pushing playback state updates
to PWA clients. SSE provides automatic reconnection and is simpler
to implement on the client side.

- Add tokio-stream dependency with sync feature for BroadcastStream
- Implement sse_handler with 15s keep-alive ping
- Keep /api/ws for backwards compatibility
2026-02-03 10:57:16 -06:00
vicrodh 596efc05ce feat(api): add add-to-queue-next endpoint 2026-02-03 09:31:20 -06:00
vicrodh 477258d94a feat(remote): sync shuffle/repeat between desktop and PWA
- Add shuffle/repeat fields to PlaybackEvent struct
- Emit queue:state event when shuffle/repeat changes via API
- Add queue event listener in desktop frontend
- Include shuffle/repeat in WebSocket broadcasts
- PWA updates shuffle/repeat from WebSocket messages

This enables bidirectional sync: changes from PWA update desktop UI,
and changes from desktop update PWA via WebSocket.
2026-02-03 09:22:55 -06:00
vicrodh 651d0b0792 chore: bump version to 1.1.8-rc-5 2026-02-03 08:28:34 -06:00
vicrodh 027d5d74d2 fix(api): emit playback events immediately to update desktop UI
Add emit_playback_update() to notify both desktop UI (Tauri event) and
PWA (WebSocket) when playback state changes from remote commands.

Previously, desktop UI would only update on the next polling cycle (up
to 5 seconds), making the remote control feel unresponsive.
2026-02-03 08:17:46 -06:00
vicrodh 0651acf1db Add playback preferences API endpoint for remote control
- GET /api/playback/preferences - get current autoplay mode
- POST /api/playback/autoplay - set autoplay mode (continue/track_only/infinite)
2026-02-03 07:54:39 -06:00
vicrodh 8e4d39684a feat(api): add album and artist detail endpoints 2026-02-03 05:52:12 -06:00