From 515f73b259e12c210d325c59e802bed572b850ec Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sun, 26 Apr 2026 18:14:14 -0600 Subject: [PATCH] refactor(v2): inline offline scrobble/playlist delegates Inlines the bodies of `create_pending_playlist`, `get_pending_playlist_count`, `queue_scrobble`, `get_queued_scrobbles`, `get_queued_scrobble_count`, and `cleanup_sent_scrobbles` from crate::offline::commands::* directly into commands_v2/legacy_compat.rs. The legacy bodies were uniform: lock state.store, unwrap optional store, delegate to a method on the store struct. Inlined verbatim with the String error type mapped to RuntimeError::Internal at each return path. The store-side OfflineStore methods (data layer) are untouched. Deletes the legacy #[tauri::command] definitions in offline/mod.rs. Other functions in the offline::commands module remain (still called from commands_v2/library.rs delegates, which are step 8 scope). No frontend invoke changes required. Step 6 of the legacy cleanup plan, group C (offline scrobble/playlist). cc --- src-tauri/src/commands_v2/legacy_compat.rs | 78 +++++++++++++--- src-tauri/src/offline/mod.rs | 103 --------------------- 2 files changed, 64 insertions(+), 117 deletions(-) diff --git a/src-tauri/src/commands_v2/legacy_compat.rs b/src-tauri/src/commands_v2/legacy_compat.rs index e00543307..f54f97e14 100644 --- a/src-tauri/src/commands_v2/legacy_compat.rs +++ b/src-tauri/src/commands_v2/legacy_compat.rs @@ -453,20 +453,36 @@ pub fn v2_create_pending_playlist( localTrackPaths: Vec, state: State<'_, OfflineState>, ) -> Result { - crate::offline::commands::create_pending_playlist( - name, - description, - isPublic, - trackIds, - localTrackPaths, - state, - ) - .map_err(RuntimeError::Internal) + let guard__ = state + .store + .lock() + .map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?; + let store = guard__ + .as_ref() + .ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?; + store + .create_pending_playlist( + &name, + description.as_deref(), + isPublic, + &trackIds, + &localTrackPaths, + ) + .map_err(RuntimeError::Internal) } #[tauri::command] pub fn v2_get_pending_playlist_count(state: State<'_, OfflineState>) -> Result { - crate::offline::commands::get_pending_playlist_count(state).map_err(RuntimeError::Internal) + let guard__ = state + .store + .lock() + .map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?; + let store = guard__ + .as_ref() + .ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?; + store + .get_pending_playlist_count() + .map_err(RuntimeError::Internal) } #[tauri::command] @@ -477,7 +493,15 @@ pub fn v2_queue_scrobble( timestamp: i64, state: State<'_, OfflineState>, ) -> Result { - crate::offline::commands::queue_scrobble(artist, track, album, timestamp, state) + let guard__ = state + .store + .lock() + .map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?; + let store = guard__ + .as_ref() + .ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?; + store + .queue_scrobble(&artist, &track, album.as_deref(), timestamp) .map_err(RuntimeError::Internal) } @@ -487,12 +511,30 @@ pub fn v2_get_queued_scrobbles( limit: Option, state: State<'_, OfflineState>, ) -> Result, RuntimeError> { - crate::offline::commands::get_queued_scrobbles(limit, state).map_err(RuntimeError::Internal) + let guard__ = state + .store + .lock() + .map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?; + let store = guard__ + .as_ref() + .ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?; + store + .get_queued_scrobbles(limit.unwrap_or(50)) + .map_err(RuntimeError::Internal) } #[tauri::command] pub fn v2_get_queued_scrobble_count(state: State<'_, OfflineState>) -> Result { - crate::offline::commands::get_queued_scrobble_count(state).map_err(RuntimeError::Internal) + let guard__ = state + .store + .lock() + .map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?; + let store = guard__ + .as_ref() + .ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?; + store + .get_queued_scrobble_count() + .map_err(RuntimeError::Internal) } #[tauri::command] @@ -501,7 +543,15 @@ pub fn v2_cleanup_sent_scrobbles( olderThanDays: Option, state: State<'_, OfflineState>, ) -> Result { - crate::offline::commands::cleanup_sent_scrobbles(olderThanDays, state) + let guard__ = state + .store + .lock() + .map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?; + let store = guard__ + .as_ref() + .ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?; + store + .cleanup_sent_scrobbles(olderThanDays.unwrap_or(7)) .map_err(RuntimeError::Internal) } diff --git a/src-tauri/src/offline/mod.rs b/src-tauri/src/offline/mod.rs index b7854fa86..87f8a6b71 100644 --- a/src-tauri/src/offline/mod.rs +++ b/src-tauri/src/offline/mod.rs @@ -935,32 +935,6 @@ pub mod commands { // === Pending Playlist Sync Commands === - /// Create a playlist while offline (queued for sync) - #[tauri::command] - pub fn create_pending_playlist( - name: String, - description: Option, - is_public: bool, - track_ids: Vec, - local_track_paths: Vec, - state: State<'_, OfflineState>, - ) -> Result { - let guard__ = state - .store - .lock() - .map_err(|e| format!("Lock error: {}", e))?; - let store = guard__ - .as_ref() - .ok_or("No active session - please log in")?; - store.create_pending_playlist( - &name, - description.as_deref(), - is_public, - &track_ids, - &local_track_paths, - ) - } - /// Get all playlists pending sync #[tauri::command] pub fn get_pending_playlists( @@ -994,19 +968,6 @@ pub mod commands { store.add_tracks_to_pending_playlist(pending_id, &qobuz_track_ids, &local_track_paths) } - /// Get count of pending playlists - #[tauri::command] - pub fn get_pending_playlist_count(state: State<'_, OfflineState>) -> Result { - let guard__ = state - .store - .lock() - .map_err(|e| format!("Lock error: {}", e))?; - let store = guard__ - .as_ref() - .ok_or("No active session - please log in")?; - store.get_pending_playlist_count() - } - /// Update Qobuz playlist ID without marking as synced (for partial sync recovery) #[tauri::command] pub fn update_pending_playlist_qobuz_id( @@ -1059,41 +1020,6 @@ pub mod commands { // === Scrobble Queue Commands === - /// Queue a scrobble for later submission (when offline) - #[tauri::command] - pub fn queue_scrobble( - artist: String, - track: String, - album: Option, - timestamp: i64, - state: State<'_, OfflineState>, - ) -> Result { - let guard__ = state - .store - .lock() - .map_err(|e| format!("Lock error: {}", e))?; - let store = guard__ - .as_ref() - .ok_or("No active session - please log in")?; - store.queue_scrobble(&artist, &track, album.as_deref(), timestamp) - } - - /// Get queued scrobbles (up to limit, default 50 for Last.fm batch) - #[tauri::command] - pub fn get_queued_scrobbles( - limit: Option, - state: State<'_, OfflineState>, - ) -> Result, String> { - let guard__ = state - .store - .lock() - .map_err(|e| format!("Lock error: {}", e))?; - let store = guard__ - .as_ref() - .ok_or("No active session - please log in")?; - store.get_queued_scrobbles(limit.unwrap_or(50)) - } - /// Mark scrobbles as sent after successful Last.fm submission #[tauri::command] pub fn mark_scrobbles_sent( @@ -1109,33 +1035,4 @@ pub mod commands { .ok_or("No active session - please log in")?; store.mark_scrobbles_sent(&ids) } - - /// Get count of queued (unsent) scrobbles - #[tauri::command] - pub fn get_queued_scrobble_count(state: State<'_, OfflineState>) -> Result { - let guard__ = state - .store - .lock() - .map_err(|e| format!("Lock error: {}", e))?; - let store = guard__ - .as_ref() - .ok_or("No active session - please log in")?; - store.get_queued_scrobble_count() - } - - /// Cleanup old sent scrobbles - #[tauri::command] - pub fn cleanup_sent_scrobbles( - older_than_days: Option, - state: State<'_, OfflineState>, - ) -> Result { - let guard__ = state - .store - .lock() - .map_err(|e| format!("Lock error: {}", e))?; - let store = guard__ - .as_ref() - .ok_or("No active session - please log in")?; - store.cleanup_sent_scrobbles(older_than_days.unwrap_or(7)) - } }