implement logout command

fixes #470
This commit is contained in:
Henrik Friedrichsen
2021-03-22 21:56:22 +01:00
parent 5f87e3cd79
commit a0231362f1
3 changed files with 22 additions and 0 deletions

View File

@@ -134,6 +134,7 @@ pub enum Command {
Insert(Option<String>),
NewPlaylist(String),
Sort(SortKey, SortDirection),
Logout,
}
impl fmt::Display for Command {
@@ -192,6 +193,7 @@ impl fmt::Display for Command {
Command::Insert(_) => "insert".to_string(),
Command::NewPlaylist(name) => format!("new playlist {}", name),
Command::Sort(key, direction) => format!("sort {} {}", key, direction),
Command::Logout => "logout".to_string(),
};
write!(f, "{}", repr)
}
@@ -415,6 +417,7 @@ pub fn parse(input: &str) -> Option<Command> {
None
}
}
"logout" => Some(Command::Logout),
"noop" => Some(Command::Noop),
_ => None,
}

View File

@@ -233,6 +233,16 @@ impl CommandManager {
});
Ok(None)
}
Command::Logout => {
self.spotify.shutdown();
let mut credentials_path = crate::config::cache_path("librespot");
credentials_path.push("credentials.json");
std::fs::remove_file(credentials_path).unwrap();
s.quit();
Ok(None)
}
Command::Jump(_)
| Command::Move(_, _)
| Command::Shift(_, _)

View File

@@ -71,6 +71,7 @@ enum WorkerCommand {
Seek(u32),
SetVolume(u16),
RequestToken(oneshot::Sender<Token>),
Shutdown,
}
#[derive(Clone, Debug, PartialEq)]
@@ -191,6 +192,10 @@ impl futures::Future for Worker {
self.token_task = Spotify::get_token(&self.session, sender);
progress = true;
}
WorkerCommand::Shutdown => {
self.player.stop();
self.session.shutdown();
}
}
}
@@ -943,6 +948,10 @@ impl Spotify {
self.cfg.with_state_mut(|mut s| s.volume = volume);
self.send_worker(WorkerCommand::SetVolume(Self::log_scale(volume)));
}
pub fn shutdown(&self) {
self.send_worker(WorkerCommand::Shutdown);
}
}
#[derive(Debug, PartialEq)]