feat: add save current command

This commit is contained in:
hrdl
2023-07-06 16:21:34 +02:00
committed by Henrik Friedrichsen
parent 2c61a965f1
commit f74661a15d
2 changed files with 11 additions and 1 deletions

View File

@@ -132,6 +132,7 @@ pub enum Command {
Play,
UpdateLibrary,
Save,
SaveCurrent,
SaveQueue,
Delete,
Focus(String),
@@ -213,6 +214,7 @@ impl fmt::Display for Command {
| Command::Play
| Command::UpdateLibrary
| Command::Save
| Command::SaveCurrent
| Command::SaveQueue
| Command::Delete
| Command::Back
@@ -242,6 +244,7 @@ impl Command {
Command::Play => "play",
Command::UpdateLibrary => "update",
Command::Save => "save",
Command::SaveCurrent => "save current",
Command::SaveQueue => "save queue",
Command::Delete => "delete",
Command::Focus(_) => "focus",
@@ -388,6 +391,7 @@ pub fn parse(input: &str) -> Result<Vec<Command>, CommandParseError> {
"update" => Command::UpdateLibrary,
"save" => match args.first().cloned() {
Some("queue") => Ok(Command::SaveQueue),
Some("current") => Ok(Command::SaveCurrent),
Some(arg) => Err(BadEnumArg {
arg: arg.into(),
accept: vec!["**omit**".into(), "queue".into()],

View File

@@ -12,7 +12,7 @@ use crate::ext_traits::CursiveExt;
use crate::library::Library;
use crate::queue::{Queue, RepeatSetting};
use crate::spotify::{Spotify, VOLUME_PERCENT};
use crate::traits::{IntoBoxedViewExt, ViewExt};
use crate::traits::{IntoBoxedViewExt, ListItem, ViewExt};
use crate::ui::contextmenu::{
AddToPlaylistMenu, ContextMenu, SelectArtistActionMenu, SelectArtistMenu,
};
@@ -272,6 +272,12 @@ impl CommandManager {
self.spotify.shutdown();
Ok(None)
}
Command::SaveCurrent => {
if let Some(mut track) = self.queue.get_current() {
track.save(&self.library);
}
Ok(None)
}
Command::Queue
| Command::PlayNext