Skip to content

Commit 39044e9

Browse files
committed
update keyring to 2.0
1 parent c8d6b33 commit 39044e9

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fern = { version = "0.6.0", features = ["syslog-4"] }
1919
futures = "0.3.15"
2020
gethostname = "0.2.0"
2121
hex = "0.4"
22-
keyring = { version = "0.10.1", optional = true }
22+
keyring = { version = "2.0", optional = true }
2323
libc = "0.2.82"
2424
log = "0.4.6"
2525
rspotify = { version = "0.11.5", features = ["client-ureq", "ureq-rustls-tls"], default-features = false, optional = true }

src/setup.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
main_loop::{self, CredentialsProvider},
66
};
77
#[cfg(feature = "dbus_keyring")]
8-
use keyring::Keyring;
8+
use keyring::Entry;
99
use librespot_connect::discovery::discovery;
1010
use librespot_core::{
1111
authentication::Credentials,
@@ -17,7 +17,7 @@ use librespot_playback::{
1717
config::AudioFormat,
1818
mixer::{self, Mixer},
1919
};
20-
use log::info;
20+
use log::{error, info, warn};
2121
use std::str::FromStr;
2222

2323
pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLoop {
@@ -86,15 +86,22 @@ pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLo
8686
let username = config.username;
8787
#[allow(unused_mut)] // mut is needed behind the dbus_keyring flag.
8888
let mut password = config.password;
89+
8990
#[cfg(feature = "dbus_keyring")]
90-
{
91-
// We only need to check if an actual user has been specified as
92-
// spotifyd can run without being signed in too.
93-
if username.is_some() && config.use_keyring {
94-
info!("Checking keyring for password");
95-
let keyring = Keyring::new("spotifyd", username.as_ref().unwrap());
96-
let retrieved_password = keyring.get_password();
97-
password = password.or_else(|| retrieved_password.ok());
91+
if config.use_keyring {
92+
match (&username, &password) {
93+
(None, _) => warn!("Can't query the keyring without a username"),
94+
(Some(_), Some(_)) => {
95+
info!("Keyring is ignored, since you already configured a password")
96+
}
97+
(Some(username), None) => {
98+
info!("Checking keyring for password");
99+
let entry = Entry::new("spotifyd", username);
100+
match entry.and_then(|e| e.get_password()) {
101+
Ok(retrieved_password) => password = Some(retrieved_password),
102+
Err(e) => error!("Keyring did not return any results: {e}"),
103+
}
104+
}
98105
}
99106
}
100107

0 commit comments

Comments
 (0)