fix(api): respect user locale for artist biography
- Add locale field to QobuzClient for API language preference - Pass lang parameter to Qobuz artist detail endpoints - Create set_api_locale command to update client locale - Sync API locale with UI i18n settings automatically - Render artist biography HTML tags properly using @html - Fix syntax error in FavoritesView (missing comma) cp
This commit is contained in:
1 parent
72693e184f
commit
42349f14dd
6 files changed
+49
-7
No files matched your search
@@ -19,6 +19,7 @@ pub struct QobuzClient {
|
||||
tokens: Arc<RwLock<Option<BundleTokens>>>,
|
||||
session: Arc<RwLock<Option<UserSession>>>,
|
||||
validated_secret: Arc<RwLock<Option<String>>>,
|
||||
locale: Arc<RwLock<String>>,
|
||||
}
|
||||
|
||||
impl QobuzClient {
|
||||
@@ -34,6 +35,7 @@ impl QobuzClient {
|
||||
tokens: Arc::new(RwLock::new(None)),
|
||||
session: Arc::new(RwLock::new(None)),
|
||||
validated_secret: Arc::new(RwLock::new(None)),
|
||||
locale: Arc::new(RwLock::new("en".to_string())),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -44,6 +46,16 @@ impl QobuzClient {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the locale for API requests
|
||||
pub async fn set_locale(&self, locale: String) {
|
||||
*self.locale.write().await = locale;
|
||||
}
|
||||
|
||||
/// Get the current locale
|
||||
async fn locale(&self) -> String {
|
||||
self.locale.read().await.clone()
|
||||
}
|
||||
|
||||
/// Get app ID
|
||||
async fn app_id(&self) -> Result<String> {
|
||||
self.tokens
|
||||
@@ -327,9 +339,11 @@ impl QobuzClient {
|
||||
offset: Option<u32>,
|
||||
) -> Result<Artist> {
|
||||
let url = endpoints::build_url(paths::ARTIST_GET);
|
||||
let locale = self.locale().await;
|
||||
let mut query = vec![
|
||||
("artist_id", artist_id.to_string()),
|
||||
("extra", "albums,tracks_appears_on,playlists".to_string()),
|
||||
("lang", locale),
|
||||
];
|
||||
if let Some(l) = limit {
|
||||
query.push(("limit", l.to_string()));
|
||||
@@ -360,7 +374,11 @@ impl QobuzClient {
|
||||
offset: Option<u32>,
|
||||
) -> Result<Artist> {
|
||||
let url = endpoints::build_url(paths::ARTIST_GET);
|
||||
let mut query = vec![("artist_id", artist_id.to_string())];
|
||||
let locale = self.locale().await;
|
||||
let mut query = vec![
|
||||
("artist_id", artist_id.to_string()),
|
||||
("lang", locale),
|
||||
];
|
||||
if with_albums {
|
||||
query.push(("extra", "albums".to_string()));
|
||||
}
|
||||
|
||||
@@ -141,3 +141,11 @@ pub async fn auto_login(state: State<'_, AppState>) -> Result<LoginResponse, Str
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn set_api_locale(locale: String, state: State<'_, AppState>) -> Result<(), String> {
|
||||
log::info!("Command: set_api_locale {}", locale);
|
||||
let client = state.client.lock().await;
|
||||
client.set_locale(locale).await;
|
||||
Ok(())
|
||||
}
|
||||
@@ -260,6 +260,7 @@ pub fn run() {
|
||||
commands::logout,
|
||||
commands::is_logged_in,
|
||||
commands::get_user_info,
|
||||
commands::set_api_locale,
|
||||
// Credential persistence commands
|
||||
commands::has_saved_credentials,
|
||||
commands::save_credentials,
|
||||
|
||||
Reference in new issue
Block a user