From ec640581bc3d7e503d28f3d4435efc6270c2f9a7 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Fri, 15 Oct 2021 17:19:09 +0200 Subject: [PATCH] Add `initial_screen` config variable Resolves #616 --- README.md | 6 ++++-- src/config.rs | 1 + src/main.rs | 14 ++++++++++++-- src/ui/layout.rs | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 48e5b2e..f37e371 100644 --- a/README.md +++ b/README.md @@ -83,12 +83,12 @@ ncspot is available via Scoop: `scoop install ncspot` ## Audio backends By default ncspot is built using the PulseAudio backend. To make it use the -PortAudio backend (e.g. for *BSD or macOS) or Rodio backend (e.g. for Windows), +PortAudio backend (e.g. for *BSD or macOS) or Rodio backend (e.g. for Windows), you need to recompile ncspot with the respective features: * `cargo run --no-default-features --features portaudio_backend,cursive/pancurses-backend` -* `cargo run --no-default-features --features +* `cargo run --no-default-features --features rodio_backend,cursive/pancurses-backend` ### Key Bindings @@ -189,6 +189,8 @@ Possible configuration values are: * `command_key`: Key to open command line , set to `:` by default +* `initial_screen`: Screen to show after startup + <`"library"|"search"|"queue"|"cover" (if enabled)`> (default is `"library"`) * `use_nerdfont`: Turn nerdfont glyphs on/off * `flip_status_indicators`: By default the statusbar will show a play icon when a track is playing and a pause icon when playback is stopped. If this setting diff --git a/src/config.rs b/src/config.rs index 2bf7a54..8cae271 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,6 +17,7 @@ pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b"; #[derive(Clone, Serialize, Deserialize, Debug, Default)] pub struct ConfigValues { pub command_key: Option, + pub initial_screen: Option, pub default_keybindings: Option, pub keybindings: Option>, pub theme: Option, diff --git a/src/main.rs b/src/main.rs index 2d82c77..abd26f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use cursive::traits::Identifiable; use librespot_core::authentication::Credentials; use librespot_core::cache::Cache; use librespot_playback::audio_backend; -use log::{info, trace}; +use log::{error, info, trace}; mod album; mod artist; @@ -230,7 +230,17 @@ async fn main() -> Result<(), String> { layout.add_screen("cover", coverview.with_name("cover")); // initial screen is library - layout.set_screen("library"); + let initial_screen = cfg + .values() + .initial_screen + .clone() + .unwrap_or("library".to_string()); + if layout.has_screen(&initial_screen) { + layout.set_screen(initial_screen); + } else { + error!("Invalid screen name: {}", initial_screen); + layout.set_screen("library"); + } let cmd_key = |cfg: Arc| cfg.values().command_key.unwrap_or(':'); diff --git a/src/ui/layout.rs b/src/ui/layout.rs index d24a2b9..d6ab4fd 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -86,6 +86,10 @@ impl Layout { self } + pub fn has_screen(&self, id: &str) -> bool { + self.screens.contains_key(id) + } + pub fn set_screen>(&mut self, id: S) { if let Some(view) = self.get_top_view() { view.on_leave();