From 865e25e9b12748bfc64fa954a1a881d8b81f728e Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sat, 7 Feb 2026 11:56:34 -0600 Subject: [PATCH] fix(listenbrainz): restore token and enabled state during session init init_at() loaded credentials from the user-scoped SQLite cache but never called restore_token() on the in-memory client. The client remained empty, so get_status() always returned disconnected after app restart. Also restore the enabled flag from persisted settings. Fixes #54 cc --- src-tauri/src/listenbrainz/mod.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/listenbrainz/mod.rs b/src-tauri/src/listenbrainz/mod.rs index 22c43e12c..011b3053b 100644 --- a/src-tauri/src/listenbrainz/mod.rs +++ b/src-tauri/src/listenbrainz/mod.rs @@ -102,17 +102,22 @@ impl ListenBrainzSharedState { let new_cache = ListenBrainzCache::new(&db_path)?; log::info!("ListenBrainz cache initialized at {:?}", db_path); - // Restore credentials from new cache - let (token, user_name) = { - let (token, user_name) = new_cache.get_credentials().unwrap_or((None, None)); - (token, user_name) - }; + // Restore credentials and enabled state from new cache + let (token, user_name) = new_cache.get_credentials().unwrap_or((None, None)); + let enabled = new_cache.is_enabled().unwrap_or(true); let mut guard = self.cache.lock().await; *guard = Some(new_cache); + drop(guard); - if token.is_some() && user_name.is_some() { - log::info!("ListenBrainz: restored session for user {:?}", user_name); + // Restore enabled state and credentials to in-memory client + { + let client = self.client.lock().await; + client.set_enabled(enabled).await; + if let (Some(tok), Some(uname)) = (token, user_name) { + log::info!("ListenBrainz: restoring session for user {:?}", uname); + client.restore_token(tok, uname).await; + } } Ok(())