From 801e847c8804e7291396d2e509d2ebc4f6691080 Mon Sep 17 00:00:00 2001 From: inemajo Date: Sun, 26 Feb 2023 20:46:41 +0100 Subject: [PATCH] commands: Adding "disconnect" command to force socket shutdown (#1057) * commands: Adding "disconnect" command to force socket shutdown * Rename to `reconnect` * Add documentation to README Related to: #628 #1033 --------- Co-authored-by: Henrik Friedrichsen --- README.md | 1 + src/command.rs | 4 ++++ src/commands.rs | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 79495a2..da83aad 100644 --- a/README.md +++ b/README.md @@ -326,6 +326,7 @@ Note: \ - mandatory arg; [BAR] - optional arg | `exec` \ | Execute a command in the system shell.
\* Command output is printed to the terminal, so redirection (`2> /dev/null`) may be necessary. | | `noop` | Do nothing. Useful for disabling default keybindings. See [custom keybindings](#custom-keybindings). | | `reload` | Reload the configuration from disk. See [Configuration](#configuration). | +| `reconnect` | Reconnect to Spotify (useful when session has expired or connection was lost | ## Remote control (IPC) diff --git a/src/command.rs b/src/command.rs index 1f6d846..eec0ef2 100644 --- a/src/command.rs +++ b/src/command.rs @@ -157,6 +157,7 @@ pub enum Command { ShowRecommendations(TargetMode), Redraw, Execute(String), + Reconnect, } impl fmt::Display for Command { @@ -216,6 +217,7 @@ impl fmt::Display for Command { | Command::ReloadConfig | Command::Noop | Command::Logout + | Command::Reconnect | Command::Redraw => vec![], }; repr_tokens.append(&mut extras_args); @@ -266,6 +268,7 @@ impl Command { Command::ShowRecommendations(_) => "similar", Command::Redraw => "redraw", Command::Execute(_) => "exec", + Command::Reconnect => "reconnect", } } } @@ -721,6 +724,7 @@ pub fn parse(input: &str) -> Result, CommandParseError> { } "redraw" => Command::Redraw, "exec" => Command::Execute(args.join(" ")), + "reconnect" => Command::Reconnect, _ => { return Err(NoSuchCommand { cmd: command.into(), diff --git a/src/commands.rs b/src/commands.rs index 7e4a2bb..e6d186b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -269,6 +269,10 @@ impl CommandManager { log::info!("Exit code: {}", result); Ok(None) } + Command::Reconnect => { + self.spotify.shutdown(); + Ok(None) + } Command::Queue | Command::PlayNext