merge(pre-release): sync latest integration branch into plex feature

cx
This commit is contained in:
vicrodh committed 2026-02-09 02:25:37 -06:00
commit fb3204f2e4
49 files changed
+4570 -1240

No files matched your search

+144
View File
@@ -0,0 +1,144 @@
//! Factory reset command
//!
//! Deletes all application data, cache, and config directories.
//! This is the nuclear option for unrecoverable states.
use tauri::State;
use crate::api_cache::ApiCacheState;
use crate::artist_blacklist::BlacklistState;
use crate::artist_vectors::ArtistVectorStoreState;
use crate::config::{
audio_settings::AudioSettingsState,
download_settings::DownloadSettingsState,
favorites_cache::FavoritesCacheState,
favorites_preferences::FavoritesPreferencesState,
legal_settings::LegalSettingsState,
playback_preferences::PlaybackPreferencesState,
remote_control_settings::{AllowedOriginsState, RemoteControlSettingsState},
subscription_state::SubscriptionStateState,
tray_settings::TraySettingsState,
};
use crate::library::commands::LibraryState;
use crate::listenbrainz::ListenBrainzSharedState;
use crate::lyrics::LyricsState;
use crate::musicbrainz::MusicBrainzSharedState;
use crate::offline::OfflineState;
use crate::offline_cache::OfflineCacheState;
use crate::reco_store::RecoState;
use crate::session_store::SessionStoreState;
use crate::updates::UpdatesState;
use crate::user_data::UserDataPaths;
use crate::AppState;
use super::user_session::teardown_type_alias_state;
/// Delete all application data, cache, and config.
///
/// Steps:
/// 1. Stop playback
/// 2. Tear down all per-user stores (close DB connections)
/// 3. Clear credentials from keyring
/// 4. Remove ~/.local/share/qbz/
/// 5. Remove ~/.cache/qbz/
/// 6. Remove ~/.config/qbz/
#[tauri::command]
pub async fn factory_reset(
app_state: State<'_, AppState>,
user_paths: State<'_, UserDataPaths>,
session_store: State<'_, SessionStoreState>,
favorites_cache: State<'_, FavoritesCacheState>,
subscription_state: State<'_, SubscriptionStateState>,
playback_prefs: State<'_, PlaybackPreferencesState>,
favorites_prefs: State<'_, FavoritesPreferencesState>,
download_settings: State<'_, DownloadSettingsState>,
audio_settings: State<'_, AudioSettingsState>,
tray_settings: State<'_, TraySettingsState>,
remote_control_settings: State<'_, RemoteControlSettingsState>,
allowed_origins: State<'_, AllowedOriginsState>,
legal_settings: State<'_, LegalSettingsState>,
updates: State<'_, UpdatesState>,
library: State<'_, LibraryState>,
reco: State<'_, RecoState>,
api_cache: State<'_, ApiCacheState>,
artist_vectors: State<'_, ArtistVectorStoreState>,
blacklist: State<'_, BlacklistState>,
offline: State<'_, OfflineState>,
offline_cache: State<'_, OfflineCacheState>,
lyrics: State<'_, LyricsState>,
musicbrainz: State<'_, MusicBrainzSharedState>,
listenbrainz: State<'_, ListenBrainzSharedState>,
) -> Result<(), String> {
log::warn!("FACTORY RESET: Starting — all application data will be deleted");
// 1. Stop playback
let _ = app_state.player.stop();
app_state.media_controls.set_stopped();
// 2. Tear down all per-user stores (close DB connections before deleting files)
session_store.teardown();
let _ = favorites_cache.teardown();
let _ = playback_prefs.teardown();
let _ = favorites_prefs.teardown();
let _ = audio_settings.teardown();
let _ = tray_settings.teardown();
let _ = remote_control_settings.teardown();
let _ = allowed_origins.teardown();
updates.teardown();
library.teardown().await;
reco.teardown().await;
api_cache.teardown().await;
artist_vectors.teardown().await;
blacklist.teardown();
offline.teardown();
offline_cache.teardown().await;
lyrics.teardown().await;
musicbrainz.teardown().await;
listenbrainz.teardown().await;
teardown_type_alias_state(&*subscription_state);
teardown_type_alias_state(&*download_settings);
teardown_type_alias_state(&*legal_settings);
// Clear the active user
user_paths.clear_user();
UserDataPaths::clear_last_user_id();
// 3. Clear credentials from keyring
if let Err(e) = crate::credentials::clear_qobuz_credentials() {
log::error!("FACTORY RESET: Failed to clear credentials: {}", e);
// Continue anyway — deleting the dirs is more important
}
// 4. Remove data directory (~/.local/share/qbz/)
if let Ok(data_dir) = UserDataPaths::global_data_dir() {
if data_dir.exists() {
log::info!("FACTORY RESET: Removing {}", data_dir.display());
if let Err(e) = std::fs::remove_dir_all(&data_dir) {
log::error!("FACTORY RESET: Failed to remove data dir: {}", e);
}
}
}
// 5. Remove cache directory (~/.cache/qbz/)
if let Ok(cache_dir) = UserDataPaths::global_cache_dir() {
if cache_dir.exists() {
log::info!("FACTORY RESET: Removing {}", cache_dir.display());
if let Err(e) = std::fs::remove_dir_all(&cache_dir) {
log::error!("FACTORY RESET: Failed to remove cache dir: {}", e);
}
}
}
// 6. Remove config directory (~/.config/qbz/)
if let Some(config_dir) = dirs::config_dir().map(|d| d.join("qbz")) {
if config_dir.exists() {
log::info!("FACTORY RESET: Removing {}", config_dir.display());
if let Err(e) = std::fs::remove_dir_all(&config_dir) {
log::error!("FACTORY RESET: Failed to remove config dir: {}", e);
}
}
}
log::warn!("FACTORY RESET: Complete — all application data deleted");
Ok(())
}
+2
View File
@@ -6,6 +6,7 @@ pub mod artist_blacklist;
pub mod audio_backends;
pub mod audio_diagnostics;
pub mod auth;
pub mod factory_reset;
pub mod cache;
pub mod credits;
pub mod favorites;
@@ -33,6 +34,7 @@ pub use audio_backends::*;
pub use audio_diagnostics::*;
pub use auth::*;
pub use cache::*;
pub use factory_reset::*;
pub use credits::*;
pub use favorites::*;
pub use lastfm::*;
+70 -51
View File
@@ -36,11 +36,13 @@ pub async fn search_albums(
state: State<'_, AppState>,
blacklist_state: State<'_, BlacklistState>,
) -> Result<SearchResultsPage<Album>, String> {
let client = state.client.lock().await;
let mut results = client
.search_albums(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())?;
let mut results = {
let client = state.client.lock().await;
client
.search_albums(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())?
};
// Filter out albums from blacklisted artists
let original_count = results.items.len();
@@ -64,11 +66,13 @@ pub async fn search_tracks(
state: State<'_, AppState>,
blacklist_state: State<'_, BlacklistState>,
) -> Result<SearchResultsPage<Track>, String> {
let client = state.client.lock().await;
let mut results = client
.search_tracks(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())?;
let mut results = {
let client = state.client.lock().await;
client
.search_tracks(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())?
};
// Filter out tracks from blacklisted artists
let original_count = results.items.len();
@@ -99,11 +103,13 @@ pub async fn search_artists(
state: State<'_, AppState>,
blacklist_state: State<'_, BlacklistState>,
) -> Result<SearchResultsPage<Artist>, String> {
let client = state.client.lock().await;
let mut results = client
.search_artists(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())?;
let mut results = {
let client = state.client.lock().await;
client
.search_artists(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())?
};
// Filter out blacklisted artists
let original_count = results.items.len();
@@ -125,27 +131,30 @@ pub async fn search_all(
blacklist_state: State<'_, BlacklistState>,
) -> Result<SearchAllResults, String> {
log::debug!("search_all called with query: {}", query);
let client = state.client.lock().await;
// Use catalog/search endpoint which returns everything including most_popular
let url = endpoints::build_url(paths::CATALOG_SEARCH);
let response: Value = client
.get_http()
.get(&url)
.header("X-App-Id", client.app_id().await.map_err(|e| e.to_string())?)
.header("X-User-Auth-Token", client.auth_token().await.map_err(|e| e.to_string())?)
.query(&[
("query", query.as_str()),
("limit", "30"),
("offset", "0"),
])
.send()
.await
.map_err(|e| format!("Request failed: {}", e))?
.json()
.await
.map_err(|e| format!("JSON parse failed: {}", e))?;
// Acquire lock only for HTTP request, drop before parsing
let response: Value = {
let client = state.client.lock().await;
client
.get_http()
.get(&url)
.header("X-App-Id", client.app_id().await.map_err(|e| e.to_string())?)
.header("X-User-Auth-Token", client.auth_token().await.map_err(|e| e.to_string())?)
.query(&[
("query", query.as_str()),
("limit", "30"),
("offset", "0"),
])
.send()
.await
.map_err(|e| format!("Request failed: {}", e))?
.json()
.await
.map_err(|e| format!("JSON parse failed: {}", e))?
};
// Parse albums
let albums: SearchResultsPage<Album> = response
@@ -309,8 +318,10 @@ pub async fn get_album(
// Cache miss - fetch from API
log::debug!("Cache miss for album {}, fetching from API", album_id);
let client = state.client.lock().await;
let album = client.get_album(&album_id).await.map_err(|e| e.to_string())?;
let album = {
let client = state.client.lock().await;
client.get_album(&album_id).await.map_err(|e| e.to_string())?
};
// Cache the result
{
@@ -333,11 +344,13 @@ pub async fn get_featured_albums(
genre_id: Option<u64>,
state: State<'_, AppState>,
) -> Result<SearchResultsPage<Album>, String> {
let client = state.client.lock().await;
let result = client
.get_featured_albums(&featured_type, limit.unwrap_or(12), offset.unwrap_or(0), genre_id)
.await
.map_err(|e| e.to_string())?;
let result = {
let client = state.client.lock().await;
client
.get_featured_albums(&featured_type, limit.unwrap_or(12), offset.unwrap_or(0), genre_id)
.await
.map_err(|e| e.to_string())?
};
Ok(result)
}
@@ -366,8 +379,10 @@ pub async fn get_track(
// Cache miss - fetch from API
log::debug!("Cache miss for track {}, fetching from API", track_id);
let client = state.client.lock().await;
let track = client.get_track(track_id).await.map_err(|e| e.to_string())?;
let track = {
let client = state.client.lock().await;
client.get_track(track_id).await.map_err(|e| e.to_string())?
};
// Cache the result
{
@@ -453,11 +468,13 @@ pub async fn get_artist_basic(
// Cache miss - fetch from API (without albums - much faster)
log::debug!("Cache miss for artist_basic {} (locale: {}), fetching from API", artist_id, locale);
let client = state.client.lock().await;
let artist = client
.get_artist_basic(artist_id)
.await
.map_err(|e| e.to_string())?;
let artist = {
let client = state.client.lock().await;
client
.get_artist_basic(artist_id)
.await
.map_err(|e| e.to_string())?
};
// Cache the result
{
@@ -649,11 +666,13 @@ pub async fn get_discover_index(
genre_ids: Option<Vec<u64>>,
state: State<'_, AppState>,
) -> Result<DiscoverResponse, String> {
let client = state.client.lock().await;
let result = client
.get_discover_index(genre_ids)
.await
.map_err(|e| e.to_string())?;
let result = {
let client = state.client.lock().await;
client
.get_discover_index(genre_ids)
.await
.map_err(|e| e.to_string())?
};
Ok(result)
}
+1 -1
View File
@@ -49,7 +49,7 @@ where
}
/// Helper to teardown a type-alias state
fn teardown_type_alias_state<S>(state: &Arc<Mutex<Option<S>>>) {
pub fn teardown_type_alias_state<S>(state: &Arc<Mutex<Option<S>>>) {
if let Ok(mut guard) = state.lock() {
*guard = None;
}