Merge pull request #1187 from jokester/fix/prevent-overwrite-to-unchanged-cred

do not overwrite unchanged cached Credentials (#1168)
This commit is contained in:
Roderick van Domburg 2023-07-13 21:23:42 +02:00 committed by GitHub
commit 8e43c3f097
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View file

@ -27,7 +27,7 @@ impl From<AuthenticationError> for Error {
}
/// The credentials are used to log into the Spotify API.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct Credentials {
pub username: String,

View file

@ -176,7 +176,13 @@ impl Session {
self.set_username(&reusable_credentials.username);
if let Some(cache) = self.cache() {
if store_credentials {
cache.save_credentials(&reusable_credentials);
let cred_changed = cache
.credentials()
.map(|c| c != reusable_credentials)
.unwrap_or(true);
if cred_changed {
cache.save_credentials(&reusable_credentials);
}
}
}

View file

@ -47,8 +47,8 @@ impl Open for JackSink {
let client_name = client_name.unwrap_or_else(|| "librespot".to_string());
let (client, _status) =
Client::new(&client_name[..], ClientOptions::NO_START_SERVER).unwrap();
let ch_r = client.register_port("out_0", AudioOut::default()).unwrap();
let ch_l = client.register_port("out_1", AudioOut::default()).unwrap();
let ch_r = client.register_port("out_0", AudioOut).unwrap();
let ch_l = client.register_port("out_1", AudioOut).unwrap();
// buffer for samples from librespot (~10ms)
let (tx, rx) = sync_channel::<f32>(NUM_CHANNELS as usize * 1024 * AudioFormat::F32.size());
let jack_data = JackData {