Add initial_screen config variable

Resolves #616
This commit is contained in:
Henrik Friedrichsen
2021-10-15 17:19:09 +02:00
parent 49f2d40b44
commit ec640581bc
4 changed files with 21 additions and 4 deletions

View File

@@ -83,12 +83,12 @@ ncspot is available via Scoop: `scoop install ncspot`
## Audio backends ## Audio backends
By default ncspot is built using the PulseAudio backend. To make it use the 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: you need to recompile ncspot with the respective features:
* `cargo run --no-default-features --features * `cargo run --no-default-features --features
portaudio_backend,cursive/pancurses-backend` portaudio_backend,cursive/pancurses-backend`
* `cargo run --no-default-features --features * `cargo run --no-default-features --features
rodio_backend,cursive/pancurses-backend` rodio_backend,cursive/pancurses-backend`
### Key Bindings ### Key Bindings
@@ -189,6 +189,8 @@ Possible configuration values are:
* `command_key`: Key to open command line <single character>, set to `:` by * `command_key`: Key to open command line <single character>, set to `:` by
default default
* `initial_screen`: Screen to show after startup
<`"library"|"search"|"queue"|"cover" (if enabled)`> (default is `"library"`)
* `use_nerdfont`: Turn nerdfont glyphs on/off <true/false> * `use_nerdfont`: Turn nerdfont glyphs on/off <true/false>
* `flip_status_indicators`: By default the statusbar will show a play icon when * `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 a track is playing and a pause icon when playback is stopped. If this setting

View File

@@ -17,6 +17,7 @@ pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b";
#[derive(Clone, Serialize, Deserialize, Debug, Default)] #[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct ConfigValues { pub struct ConfigValues {
pub command_key: Option<char>, pub command_key: Option<char>,
pub initial_screen: Option<String>,
pub default_keybindings: Option<bool>, pub default_keybindings: Option<bool>,
pub keybindings: Option<HashMap<String, String>>, pub keybindings: Option<HashMap<String, String>>,
pub theme: Option<ConfigTheme>, pub theme: Option<ConfigTheme>,

View File

@@ -16,7 +16,7 @@ use cursive::traits::Identifiable;
use librespot_core::authentication::Credentials; use librespot_core::authentication::Credentials;
use librespot_core::cache::Cache; use librespot_core::cache::Cache;
use librespot_playback::audio_backend; use librespot_playback::audio_backend;
use log::{info, trace}; use log::{error, info, trace};
mod album; mod album;
mod artist; mod artist;
@@ -230,7 +230,17 @@ async fn main() -> Result<(), String> {
layout.add_screen("cover", coverview.with_name("cover")); layout.add_screen("cover", coverview.with_name("cover"));
// initial screen is library // 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<Config>| cfg.values().command_key.unwrap_or(':'); let cmd_key = |cfg: Arc<Config>| cfg.values().command_key.unwrap_or(':');

View File

@@ -86,6 +86,10 @@ impl Layout {
self self
} }
pub fn has_screen(&self, id: &str) -> bool {
self.screens.contains_key(id)
}
pub fn set_screen<S: Into<String>>(&mut self, id: S) { pub fn set_screen<S: Into<String>>(&mut self, id: S) {
if let Some(view) = self.get_top_view() { if let Some(view) = self.get_top_view() {
view.on_leave(); view.on_leave();