From db894d7ce8d4baaa6c28fd8e6993f7b805291638 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Thu, 25 Feb 2021 21:07:12 +0100 Subject: [PATCH] Add config values to override shuffle/repeat state --- README.md | 2 ++ src/config.rs | 12 +++++++++++- src/queue.rs | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 86f3437..651137f 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,8 @@ Possible configuration values are: * `bitrate`: The audio bitrate to use for streaming, can be 96, 160, or 320 (default is 320) * `album_column`: Show album column for tracks, on by default * `gapless`: Allows gapless playback (default is false) +* `shuffle`: Set default shuffle state +* `repeat`: Set default repeat mode Keybindings can be configured in `[keybindings]` section in `config.toml`, e.g. as such: diff --git a/src/config.rs b/src/config.rs index 87a72b2..f69e743 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,6 +26,8 @@ pub struct ConfigValues { pub bitrate: Option, pub album_column: Option, pub gapless: Option, + pub shuffle: Option, + pub repeat: Option, } #[derive(Serialize, Deserialize, Debug, Default, Clone)] @@ -85,12 +87,20 @@ impl Config { process::exit(1); }); - let userstate = { + let mut userstate = { let path = config_path("userstate.toml"); load_or_generate_default(path, |_| Ok(UserState::default()), true) .expect("could not load user state") }; + if let Some(shuffle) = values.shuffle { + userstate.shuffle = shuffle; + } + + if let Some(repeat) = values.repeat { + userstate.repeat = repeat; + } + Self { values: RwLock::new(values), state: RwLock::new(userstate), diff --git a/src/queue.rs b/src/queue.rs index 0973ab1..13a5065 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -13,8 +13,11 @@ use crate::{config::Config, spotify::PlayerEvent}; #[derive(Display, Clone, Copy, PartialEq, Debug, Serialize, Deserialize)] pub enum RepeatSetting { + #[serde(rename = "off")] None, + #[serde(rename = "playlist")] RepeatPlaylist, + #[serde(rename = "track")] RepeatTrack, }