test login credentials before entering main program

closes #58

this is a bit messy, as librespot panics, when authentication fails. thus, we
test the credentials in a separate thread to handle the panic.

see also: https://github.com/librespot-org/librespot/issues/108
This commit is contained in:
Henrik Friedrichsen
2019-04-15 21:59:19 +02:00
parent ea4ea5a853
commit 8738472e87
2 changed files with 41 additions and 17 deletions

View File

@@ -220,6 +220,17 @@ impl Spotify {
spotify
}
pub fn test_credentials(credentials: Credentials) -> bool {
let th = thread::spawn(|| {
let mut core = Core::new().unwrap();
let config = SessionConfig::default();
let handle = core.handle();
core.run(Session::connect(config, credentials, None, handle)).unwrap();
});
th.join().is_ok()
}
fn create_session(core: &mut Core, credentials: Credentials) -> Session {
let session_config = SessionConfig::default();
let cache = Cache::new(config::cache_path("librespot"), true);