chore(commands): delete legacy commands module and inline helpers
src-tauri/src/commands/user_session.rs hosted three unregistered #[tauri::command] entries (activate_user_session, deactivate_user_session, get_last_user_id) plus two non-command helpers (init_type_alias_state, teardown_type_alias_state) consumed only by session_lifecycle.rs. - Move init_type_alias_state and teardown_type_alias_state into session_lifecycle.rs (their only caller) as plain pub helpers. - Delete src-tauri/src/commands/user_session.rs and src-tauri/src/commands/mod.rs. - Remove pub mod commands; from lib.rs — the legacy commands namespace is now empty. - Refresh the activate_session doc comment to match the new layout. cc
This commit is contained in:
4 files changed
+32
-81
No files matched your search
@@ -1,9 +0,0 @@
|
||||
//! Legacy commands module.
|
||||
//!
|
||||
//! NOTE:
|
||||
//! The active frontend/runtime contract is V2 (`runtime_*` + `v2_*`) only.
|
||||
//! This module keeps only the minimal internal legacy pieces still referenced
|
||||
//! by non-frontend subsystems while hard-delete migration is in progress.
|
||||
|
||||
pub mod user_session;
|
||||
pub use user_session::*;
|
||||
@@ -1,64 +0,0 @@
|
||||
//! Per-user session activation and teardown
|
||||
//!
|
||||
//! After login, the frontend calls `activate_user_session` with the Qobuz user_id.
|
||||
//! This initializes all per-user database stores at the user-scoped directory.
|
||||
//! On logout, `deactivate_user_session` tears everything down.
|
||||
//!
|
||||
//! These legacy commands now delegate to session_lifecycle module.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::user_data::UserDataPaths;
|
||||
|
||||
/// Helper to init a type-alias state (Arc<Mutex<Option<Store>>>) at a path
|
||||
pub fn init_type_alias_state<S, F>(
|
||||
state: &Arc<Mutex<Option<S>>>,
|
||||
base_dir: &Path,
|
||||
constructor: F,
|
||||
) -> Result<(), String>
|
||||
where
|
||||
F: FnOnce(&Path) -> Result<S, String>,
|
||||
{
|
||||
let store = constructor(base_dir)?;
|
||||
let mut guard = state.lock().map_err(|e| format!("Lock error: {}", e))?;
|
||||
*guard = Some(store);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Helper to teardown a type-alias state
|
||||
pub fn teardown_type_alias_state<S>(state: &Arc<Mutex<Option<S>>>) {
|
||||
if let Ok(mut guard) = state.lock() {
|
||||
*guard = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the last active user_id for session restore on startup.
|
||||
/// Returns None if no previous session or after explicit logout.
|
||||
#[tauri::command]
|
||||
pub fn get_last_user_id() -> Option<u64> {
|
||||
UserDataPaths::load_last_user_id()
|
||||
}
|
||||
|
||||
/// Activate the per-user session after login.
|
||||
///
|
||||
/// This runs the one-time migration (if needed) and initializes all
|
||||
/// per-user database stores at `~/.local/share/qbz/users/{user_id}/`
|
||||
/// and cache stores at `~/.cache/qbz/users/{user_id}/`.
|
||||
///
|
||||
/// This is a legacy command - now delegates to session_lifecycle::activate_session().
|
||||
#[tauri::command]
|
||||
pub async fn activate_user_session(app: tauri::AppHandle, user_id: u64) -> Result<(), String> {
|
||||
log::info!("[Legacy] activate_user_session called - delegating to session_lifecycle");
|
||||
crate::session_lifecycle::activate_session(&app, user_id).await
|
||||
}
|
||||
|
||||
/// Deactivate the per-user session on logout.
|
||||
///
|
||||
/// Tears down all per-user stores, closing database connections.
|
||||
/// This is a legacy command - now delegates to session_lifecycle::deactivate_session().
|
||||
#[tauri::command]
|
||||
pub async fn deactivate_user_session(app: tauri::AppHandle) -> Result<(), String> {
|
||||
log::info!("[Legacy] deactivate_user_session called - delegating to session_lifecycle");
|
||||
crate::session_lifecycle::deactivate_session(&app).await
|
||||
}
|
||||
@@ -35,7 +35,6 @@ pub mod audio;
|
||||
pub mod audio_device_watch;
|
||||
pub mod cache;
|
||||
pub mod cast;
|
||||
pub mod commands;
|
||||
pub mod config;
|
||||
pub mod credentials;
|
||||
pub mod discogs;
|
||||
|
||||
@@ -7,11 +7,36 @@
|
||||
//! from multiple places (runtime_bootstrap, commands, etc.) without
|
||||
//! duplicating the complex state initialization logic.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use tauri::{Emitter, Manager};
|
||||
|
||||
use crate::runtime::{RuntimeEvent, RuntimeManagerState};
|
||||
use crate::user_data::UserDataPaths;
|
||||
|
||||
/// Helper to init a type-alias state (Arc<Mutex<Option<Store>>>) at a path.
|
||||
pub fn init_type_alias_state<S, F>(
|
||||
state: &Arc<Mutex<Option<S>>>,
|
||||
base_dir: &Path,
|
||||
constructor: F,
|
||||
) -> Result<(), String>
|
||||
where
|
||||
F: FnOnce(&Path) -> Result<S, String>,
|
||||
{
|
||||
let store = constructor(base_dir)?;
|
||||
let mut guard = state.lock().map_err(|e| format!("Lock error: {}", e))?;
|
||||
*guard = Some(store);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Helper to teardown a type-alias state.
|
||||
pub fn teardown_type_alias_state<S>(state: &Arc<Mutex<Option<S>>>) {
|
||||
if let Ok(mut guard) = state.lock() {
|
||||
*guard = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Activate a user session from anywhere given an AppHandle.
|
||||
///
|
||||
/// This performs the full session activation:
|
||||
@@ -21,8 +46,8 @@ use crate::user_data::UserDataPaths;
|
||||
/// 4. Updates runtime state
|
||||
/// 5. Emits UserSessionActivated event
|
||||
///
|
||||
/// Note: This is the core logic extracted from `activate_user_session` command.
|
||||
/// It can be called from runtime_bootstrap, v2_login, or the command itself.
|
||||
/// Note: This is the core logic invoked from runtime_bootstrap and v2_login
|
||||
/// after the legacy `activate_user_session` Tauri command was retired.
|
||||
pub async fn activate_session(app: &tauri::AppHandle, user_id: u64) -> Result<(), String> {
|
||||
log::info!("[SessionLifecycle] Activating session");
|
||||
|
||||
@@ -171,12 +196,12 @@ pub async fn activate_session(app: &tauri::AppHandle, user_id: u64) -> Result<()
|
||||
use crate::config::{
|
||||
download_settings::DownloadSettingsStore, subscription_state::SubscriptionStateStore,
|
||||
};
|
||||
crate::commands::user_session::init_type_alias_state(
|
||||
init_type_alias_state(
|
||||
&*subscription_state,
|
||||
&data_dir,
|
||||
SubscriptionStateStore::new_at,
|
||||
)?;
|
||||
crate::commands::user_session::init_type_alias_state(
|
||||
init_type_alias_state(
|
||||
&*download_settings,
|
||||
&data_dir,
|
||||
DownloadSettingsStore::new_at,
|
||||
@@ -327,8 +352,8 @@ pub async fn deactivate_session(app: &tauri::AppHandle) -> Result<(), String> {
|
||||
|
||||
// Type-alias states (per-user settings)
|
||||
// NOTE: LegalSettingsState is GLOBAL (not per-user) - NOT torn down here
|
||||
crate::commands::user_session::teardown_type_alias_state(&*subscription_state);
|
||||
crate::commands::user_session::teardown_type_alias_state(&*download_settings);
|
||||
teardown_type_alias_state(&*subscription_state);
|
||||
teardown_type_alias_state(&*download_settings);
|
||||
|
||||
// Clear the active user but KEEP last_user_id on disk.
|
||||
// Offline mode needs it to load the user's library and settings
|
||||
@@ -420,7 +445,7 @@ pub async fn activate_offline_session(app: &tauri::AppHandle) -> Result<(), Stri
|
||||
// Download settings — needed for "Show in Local Library" toggle
|
||||
{
|
||||
use crate::config::download_settings::DownloadSettingsStore;
|
||||
crate::commands::user_session::init_type_alias_state(
|
||||
init_type_alias_state(
|
||||
&*download_settings,
|
||||
&data_dir,
|
||||
DownloadSettingsStore::new_at,
|
||||
|
||||
Reference in new issue
Block a user