From 709c399e31ed2194e557caa6f5760b32c5b321a3 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Wed, 8 Apr 2026 17:59:33 -0600 Subject: [PATCH] refactor: extract commands_v2/session.rs cc --- src-tauri/src/commands_v2/mod.rs | 142 +-------------------------- src-tauri/src/commands_v2/session.rs | 142 +++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 140 deletions(-) create mode 100644 src-tauri/src/commands_v2/session.rs diff --git a/src-tauri/src/commands_v2/mod.rs b/src-tauri/src/commands_v2/mod.rs index 26204ec01..d266cb952 100644 --- a/src-tauri/src/commands_v2/mod.rs +++ b/src-tauri/src/commands_v2/mod.rs @@ -98,146 +98,8 @@ pub use catalog::*; mod integrations; pub use integrations::*; -// ==================== Session Persistence Commands (V2) ==================== - -/// Save session position (V2) -#[tauri::command] -#[allow(non_snake_case)] -pub async fn v2_save_session_position( - positionSecs: u64, - session_state: State<'_, crate::session_store::SessionStoreState>, -) -> Result<(), RuntimeError> { - let guard = session_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".to_string()))?; - store - .save_position(positionSecs) - .map_err(|e| RuntimeError::Internal(e)) -} - -/// Save session volume (V2) -#[tauri::command] -pub async fn v2_save_session_volume( - volume: f32, - session_state: State<'_, crate::session_store::SessionStoreState>, -) -> Result<(), RuntimeError> { - let guard = session_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".to_string()))?; - store - .save_volume(volume) - .map_err(|e| RuntimeError::Internal(e)) -} - -/// Save session playback mode (V2) -#[tauri::command] -#[allow(non_snake_case)] -pub async fn v2_save_session_playback_mode( - shuffle: bool, - repeatMode: String, - session_state: State<'_, crate::session_store::SessionStoreState>, -) -> Result<(), RuntimeError> { - let guard = session_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".to_string()))?; - store - .save_playback_mode(shuffle, &repeatMode) - .map_err(|e| RuntimeError::Internal(e)) -} - -/// Save session state - full state (V2) -#[tauri::command] -#[allow(non_snake_case)] -pub async fn v2_save_session_state( - queueTracks: Vec, - currentIndex: Option, - currentPositionSecs: u64, - volume: f32, - shuffleEnabled: bool, - repeatMode: String, - wasPlaying: bool, - lastView: Option, - viewContextId: Option, - viewContextType: Option, - session_state: State<'_, crate::session_store::SessionStoreState>, -) -> Result<(), RuntimeError> { - let session = crate::session_store::PersistedSession { - queue_tracks: queueTracks, - current_index: currentIndex, - current_position_secs: currentPositionSecs, - volume, - shuffle_enabled: shuffleEnabled, - repeat_mode: repeatMode, - was_playing: wasPlaying, - saved_at: 0, // Will be set by save_session - last_view: lastView.unwrap_or_else(|| "home".to_string()), - view_context_id: viewContextId, - view_context_type: viewContextType, - }; - - let guard = session_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".to_string()))?; - store - .save_session(&session) - .map_err(|e| RuntimeError::Internal(e))?; - log::debug!( - "[V2] save_session_state: index={:?} pos={}", - currentIndex, - currentPositionSecs - ); - Ok(()) -} - -/// Load session state (V2) -#[tauri::command] -pub async fn v2_load_session_state( - session_state: State<'_, crate::session_store::SessionStoreState>, -) -> Result { - let guard = session_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".to_string()))?; - store.load_session().map_err(|e| RuntimeError::Internal(e)) -} - -/// Clear session (V2) -#[tauri::command] -pub async fn v2_clear_session( - session_state: State<'_, crate::session_store::SessionStoreState>, -) -> Result<(), RuntimeError> { - let guard = session_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".to_string()))?; - store - .clear_session() - .map_err(|e| RuntimeError::Internal(e))?; - log::info!("[V2] clear_session"); - Ok(()) -} +mod session; +pub use session::*; mod legacy_compat; pub use legacy_compat::*; diff --git a/src-tauri/src/commands_v2/session.rs b/src-tauri/src/commands_v2/session.rs new file mode 100644 index 000000000..5d88f1b60 --- /dev/null +++ b/src-tauri/src/commands_v2/session.rs @@ -0,0 +1,142 @@ +use tauri::State; + +use crate::runtime::RuntimeError; + +/// Save session position (V2) +#[tauri::command] +#[allow(non_snake_case)] +pub async fn v2_save_session_position( + positionSecs: u64, + session_state: State<'_, crate::session_store::SessionStoreState>, +) -> Result<(), RuntimeError> { + let guard = session_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".to_string()))?; + store + .save_position(positionSecs) + .map_err(|e| RuntimeError::Internal(e)) +} + +/// Save session volume (V2) +#[tauri::command] +pub async fn v2_save_session_volume( + volume: f32, + session_state: State<'_, crate::session_store::SessionStoreState>, +) -> Result<(), RuntimeError> { + let guard = session_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".to_string()))?; + store + .save_volume(volume) + .map_err(|e| RuntimeError::Internal(e)) +} + +/// Save session playback mode (V2) +#[tauri::command] +#[allow(non_snake_case)] +pub async fn v2_save_session_playback_mode( + shuffle: bool, + repeatMode: String, + session_state: State<'_, crate::session_store::SessionStoreState>, +) -> Result<(), RuntimeError> { + let guard = session_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".to_string()))?; + store + .save_playback_mode(shuffle, &repeatMode) + .map_err(|e| RuntimeError::Internal(e)) +} + +/// Save session state - full state (V2) +#[tauri::command] +#[allow(non_snake_case)] +pub async fn v2_save_session_state( + queueTracks: Vec, + currentIndex: Option, + currentPositionSecs: u64, + volume: f32, + shuffleEnabled: bool, + repeatMode: String, + wasPlaying: bool, + lastView: Option, + viewContextId: Option, + viewContextType: Option, + session_state: State<'_, crate::session_store::SessionStoreState>, +) -> Result<(), RuntimeError> { + let session = crate::session_store::PersistedSession { + queue_tracks: queueTracks, + current_index: currentIndex, + current_position_secs: currentPositionSecs, + volume, + shuffle_enabled: shuffleEnabled, + repeat_mode: repeatMode, + was_playing: wasPlaying, + saved_at: 0, // Will be set by save_session + last_view: lastView.unwrap_or_else(|| "home".to_string()), + view_context_id: viewContextId, + view_context_type: viewContextType, + }; + + let guard = session_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".to_string()))?; + store + .save_session(&session) + .map_err(|e| RuntimeError::Internal(e))?; + log::debug!( + "[V2] save_session_state: index={:?} pos={}", + currentIndex, + currentPositionSecs + ); + Ok(()) +} + +/// Load session state (V2) +#[tauri::command] +pub async fn v2_load_session_state( + session_state: State<'_, crate::session_store::SessionStoreState>, +) -> Result { + let guard = session_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".to_string()))?; + store.load_session().map_err(|e| RuntimeError::Internal(e)) +} + +/// Clear session (V2) +#[tauri::command] +pub async fn v2_clear_session( + session_state: State<'_, crate::session_store::SessionStoreState>, +) -> Result<(), RuntimeError> { + let guard = session_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".to_string()))?; + store + .clear_session() + .map_err(|e| RuntimeError::Internal(e))?; + log::info!("[V2] clear_session"); + Ok(()) +}