fix(v2): restore Plex command surface for LocalLibrary

cx
This commit is contained in:
vicrodh committed 2026-02-16 12:53:20 -06:00
1 parent 8ac5ba92fd
commit e51f367b31
2 files changed
+156 -5

No files matched your search

+144 -5
View File
@@ -363,12 +363,21 @@ pub async fn runtime_bootstrap(
return Ok(status); return Ok(status);
} }
// Step 3: Check for saved credentials and attempt auto-login // Step 3: Check for saved credentials and attempt auto-login.
// NOTE: user_id hint is optional; credentials are the source of truth.
// This keeps bootstrap robust even if last_user_id is missing/corrupt.
let creds = crate::credentials::load_qobuz_credentials(); let creds = crate::credentials::load_qobuz_credentials();
let last_user_id = crate::user_data::UserDataPaths::load_last_user_id(); let last_user_id_hint = crate::user_data::UserDataPaths::load_last_user_id();
if let (Ok(Some(creds)), Some(user_id)) = (creds, last_user_id) { if let Ok(Some(creds)) = creds {
log::info!("[Runtime] Found saved credentials, attempting auto-login for user {}", user_id); if let Some(uid) = last_user_id_hint {
log::info!(
"[Runtime] Found saved credentials, attempting auto-login (user hint: {})",
uid
);
} else {
log::info!("[Runtime] Found saved credentials, attempting auto-login (no user hint)");
}
// Login to legacy client // Login to legacy client
let client = app_state.client.read().await; let client = app_state.client.read().await;
@@ -424,7 +433,7 @@ pub async fn runtime_bootstrap(
} }
} }
} else { } else {
log::info!("[Runtime] No saved credentials or last user ID, staying in InitializedNoAuth"); log::info!("[Runtime] No saved credentials, staying in InitializedNoAuth");
} }
manager.set_bootstrap_in_progress(false).await; manager.set_bootstrap_in_progress(false).await;
@@ -486,6 +495,25 @@ pub struct V2LoginResponse {
pub error_code: Option<String>, pub error_code: Option<String>,
} }
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct V2UserInfo {
pub user_name: String,
pub subscription: String,
pub subscription_valid_until: Option<String>,
}
#[tauri::command]
pub async fn v2_get_user_info(
app_state: State<'_, AppState>,
) -> Result<Option<V2UserInfo>, RuntimeError> {
let client = app_state.client.read().await;
Ok(client.get_user_info().await.map(|(name, subscription, valid_until)| V2UserInfo {
user_name: name,
subscription,
subscription_valid_until: valid_until,
}))
}
/// Auto-login using saved credentials (Phase 2 of runtime initialization) /// Auto-login using saved credentials (Phase 2 of runtime initialization)
/// ///
/// This command: /// This command:
@@ -1197,6 +1225,34 @@ pub async fn v2_plex_ping(
crate::plex::plex_ping(baseUrl, token).await crate::plex::plex_ping(baseUrl, token).await
} }
#[tauri::command]
#[allow(non_snake_case)]
pub async fn v2_plex_get_track_metadata(
baseUrl: String,
token: String,
ratingKey: String,
) -> Result<crate::plex::PlexTrack, String> {
crate::plex::plex_get_track_metadata(baseUrl, token, ratingKey).await
}
#[tauri::command]
#[allow(non_snake_case)]
pub async fn v2_plex_auth_pin_start(
clientIdentifier: String,
) -> Result<crate::plex::PlexPinStartResult, String> {
crate::plex::plex_auth_pin_start(clientIdentifier).await
}
#[tauri::command]
#[allow(non_snake_case)]
pub async fn v2_plex_auth_pin_check(
clientIdentifier: String,
pinId: u64,
code: Option<String>,
) -> Result<crate::plex::PlexPinCheckResult, String> {
crate::plex::plex_auth_pin_check(clientIdentifier, pinId, code).await
}
#[tauri::command] #[tauri::command]
pub fn v2_set_visualizer_enabled( pub fn v2_set_visualizer_enabled(
enabled: bool, enabled: bool,
@@ -1388,6 +1444,11 @@ pub fn v2_plex_cache_save_sections(
crate::plex::plex_cache_save_sections(server_id, sections) crate::plex::plex_cache_save_sections(server_id, sections)
} }
#[tauri::command]
pub fn v2_plex_cache_get_sections() -> Result<Vec<crate::plex::PlexMusicSection>, String> {
crate::plex::plex_cache_get_sections()
}
#[tauri::command] #[tauri::command]
pub fn v2_plex_cache_save_tracks( pub fn v2_plex_cache_save_tracks(
server_id: Option<String>, server_id: Option<String>,
@@ -1402,6 +1463,48 @@ pub fn v2_plex_cache_clear() -> Result<(), String> {
crate::plex::plex_cache_clear() crate::plex::plex_cache_clear()
} }
#[tauri::command]
pub fn v2_plex_cache_get_tracks(
sectionKey: Option<String>,
limit: Option<u32>,
) -> Result<Vec<crate::plex::PlexTrack>, String> {
crate::plex::plex_cache_get_tracks(sectionKey, limit)
}
#[tauri::command]
pub fn v2_plex_cache_get_albums() -> Result<Vec<crate::plex::PlexCachedAlbum>, String> {
crate::plex::plex_cache_get_albums()
}
#[tauri::command]
pub fn v2_plex_cache_search_tracks(
query: String,
limit: Option<u32>,
) -> Result<Vec<crate::plex::PlexCachedTrack>, String> {
crate::plex::plex_cache_search_tracks(query, limit)
}
#[tauri::command]
pub fn v2_plex_cache_get_album_tracks(
albumKey: String,
) -> Result<Vec<crate::plex::PlexCachedTrack>, String> {
crate::plex::plex_cache_get_album_tracks(albumKey)
}
#[tauri::command]
pub fn v2_plex_cache_update_track_quality(
updates: Vec<crate::plex::PlexTrackQualityUpdate>,
) -> Result<usize, String> {
crate::plex::plex_cache_update_track_quality(updates)
}
#[tauri::command]
pub fn v2_plex_cache_get_tracks_needing_hydration(
limit: Option<u32>,
) -> Result<Vec<String>, String> {
crate::plex::plex_cache_get_tracks_needing_hydration(limit)
}
// ==================== Casting / Local Library Commands (V2 Native) ==================== // ==================== Casting / Local Library Commands (V2 Native) ====================
#[tauri::command] #[tauri::command]
@@ -1787,6 +1890,42 @@ pub async fn v2_library_remove_folder(
Ok(()) Ok(())
} }
#[tauri::command]
pub async fn v2_library_check_folder_accessible(path: String) -> Result<bool, String> {
log::info!("[V2] library_check_folder_accessible {}", path);
let path_ref = std::path::Path::new(&path);
if !path_ref.exists() {
return Ok(false);
}
// Avoid UI stalls on slow/unresponsive mounts.
let path_clone = path.clone();
let check_result = tokio::time::timeout(
std::time::Duration::from_secs(6),
tokio::task::spawn_blocking(move || std::fs::read_dir(std::path::Path::new(&path_clone)).is_ok()),
)
.await;
match check_result {
Ok(Ok(accessible)) => Ok(accessible),
Ok(Err(_)) => {
log::warn!("[V2] Failed to spawn blocking task for folder check: {}", path);
Ok(false)
}
Err(_) => {
// Mounted-but-slow network shares can timeout but still be usable.
let exists = std::path::Path::new(&path).exists();
log::warn!(
"[V2] Timeout checking folder accessibility: {} (exists={})",
path,
exists
);
Ok(exists)
}
}
}
#[tauri::command] #[tauri::command]
pub async fn v2_library_clear_artwork_cache() -> Result<u64, String> { pub async fn v2_library_clear_artwork_cache() -> Result<u64, String> {
let artwork_dir = get_artwork_cache_dir(); let artwork_dir = get_artwork_cache_dir();
+12
View File
@@ -1160,6 +1160,7 @@ pub fn run() {
commands_v2::v2_init_client, commands_v2::v2_init_client,
commands_v2::v2_auto_login, commands_v2::v2_auto_login,
commands_v2::v2_manual_login, commands_v2::v2_manual_login,
commands_v2::v2_get_user_info,
commands_v2::v2_save_credentials, commands_v2::v2_save_credentials,
commands_v2::v2_clear_saved_credentials, commands_v2::v2_clear_saved_credentials,
commands_v2::v2_set_api_locale, commands_v2::v2_set_api_locale,
@@ -1180,6 +1181,9 @@ pub fn run() {
commands_v2::v2_plex_ping, commands_v2::v2_plex_ping,
commands_v2::v2_plex_get_music_sections, commands_v2::v2_plex_get_music_sections,
commands_v2::v2_plex_get_section_tracks, commands_v2::v2_plex_get_section_tracks,
commands_v2::v2_plex_get_track_metadata,
commands_v2::v2_plex_auth_pin_start,
commands_v2::v2_plex_auth_pin_check,
commands_v2::v2_plex_play_track, commands_v2::v2_plex_play_track,
commands_v2::v2_set_visualizer_enabled, commands_v2::v2_set_visualizer_enabled,
commands_v2::v2_get_developer_settings, commands_v2::v2_get_developer_settings,
@@ -1198,8 +1202,15 @@ pub fn run() {
commands_v2::v2_set_blacklist_enabled, commands_v2::v2_set_blacklist_enabled,
commands_v2::v2_clear_artist_blacklist, commands_v2::v2_clear_artist_blacklist,
commands_v2::v2_plex_open_auth_url, commands_v2::v2_plex_open_auth_url,
commands_v2::v2_plex_cache_get_sections,
commands_v2::v2_plex_cache_save_sections, commands_v2::v2_plex_cache_save_sections,
commands_v2::v2_plex_cache_save_tracks, commands_v2::v2_plex_cache_save_tracks,
commands_v2::v2_plex_cache_get_tracks,
commands_v2::v2_plex_cache_get_albums,
commands_v2::v2_plex_cache_get_album_tracks,
commands_v2::v2_plex_cache_search_tracks,
commands_v2::v2_plex_cache_update_track_quality,
commands_v2::v2_plex_cache_get_tracks_needing_hydration,
commands_v2::v2_plex_cache_clear, commands_v2::v2_plex_cache_clear,
commands_v2::v2_cast_start_discovery, commands_v2::v2_cast_start_discovery,
commands_v2::v2_cast_stop_discovery, commands_v2::v2_cast_stop_discovery,
@@ -1232,6 +1243,7 @@ pub fn run() {
commands_v2::v2_airplay_set_volume, commands_v2::v2_airplay_set_volume,
commands_v2::v2_clear_offline_cache, commands_v2::v2_clear_offline_cache,
commands_v2::v2_library_remove_folder, commands_v2::v2_library_remove_folder,
commands_v2::v2_library_check_folder_accessible,
commands_v2::v2_library_clear_artwork_cache, commands_v2::v2_library_clear_artwork_cache,
commands_v2::v2_library_clear_thumbnails_cache, commands_v2::v2_library_clear_thumbnails_cache,
commands_v2::v2_library_play_track, commands_v2::v2_library_play_track,