@@ -5,7 +5,7 @@ use crate::{
5
5
main_loop:: { self , CredentialsProvider } ,
6
6
} ;
7
7
#[ cfg( feature = "dbus_keyring" ) ]
8
- use keyring:: Keyring ;
8
+ use keyring:: Entry ;
9
9
use librespot_connect:: discovery:: discovery;
10
10
use librespot_core:: {
11
11
authentication:: Credentials ,
@@ -17,7 +17,7 @@ use librespot_playback::{
17
17
config:: AudioFormat ,
18
18
mixer:: { self , Mixer } ,
19
19
} ;
20
- use log:: info;
20
+ use log:: { error , info, warn } ;
21
21
use std:: str:: FromStr ;
22
22
23
23
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
86
86
let username = config. username ;
87
87
#[ allow( unused_mut) ] // mut is needed behind the dbus_keyring flag.
88
88
let mut password = config. password ;
89
+
89
90
#[ 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
+ }
98
105
}
99
106
}
100
107
0 commit comments