add proxy configuration value

+ document possible configuration options

fixes #109
This commit is contained in:
Henrik Friedrichsen
2019-11-21 22:45:09 +01:00
parent ff000077ad
commit 177c4893e0
7 changed files with 42 additions and 13 deletions

1
Cargo.lock generated
View File

@@ -1544,6 +1544,7 @@ dependencies = [
"tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"webbrowser 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@@ -36,6 +36,7 @@ dbus = { version = "0.6.4", optional = true }
rand = "0.6.5"
webbrowser = "0.5"
clipboard = { version = "0.5", optional = true }
url = "1.7"
[dependencies.librespot]
version = "0.1.0"

View File

@@ -91,7 +91,12 @@ the search view.
## Configuration
Configuration is saved to `~/.config/ncspot/config.toml`.
Configuration is saved to `~/.config/ncspot/config.toml`. Possible configuration
values are:
* `proxy`: Set an HTTP proxy
* `use_nerdfont`: Turn nerdfont glyphs on/off <true/false>
* `theme`: Set a custom color palette (see below)
### Theming

View File

@@ -8,11 +8,12 @@ use directories::ProjectDirs;
pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b";
#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct Config {
pub keybindings: Option<HashMap<String, Command>>,
pub theme: Option<ConfigTheme>,
pub use_nerdfont: Option<bool>,
pub proxy: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]

View File

@@ -31,6 +31,7 @@ extern crate chrono;
extern crate fern;
extern crate rand;
extern crate url;
use std::fs;
use std::path::PathBuf;
@@ -161,7 +162,7 @@ fn main() {
let mut credentials = get_credentials(false);
while !spotify::Spotify::test_credentials(credentials.clone()) {
while !spotify::Spotify::test_credentials(cfg.clone(), credentials.clone()) {
credentials = get_credentials(true);
}
@@ -172,7 +173,11 @@ fn main() {
let event_manager = EventManager::new(cursive.cb_sink().clone());
let spotify = Arc::new(spotify::Spotify::new(event_manager.clone(), credentials));
let spotify = Arc::new(spotify::Spotify::new(
cfg.clone(),
event_manager.clone(),
credentials,
));
let queue = Arc::new(queue::Queue::new(spotify.clone()));

View File

@@ -1,3 +1,4 @@
use config::Config;
use librespot::core::authentication::Credentials;
use librespot::core::cache::Cache;
use librespot::core::config::SessionConfig;
@@ -33,6 +34,7 @@ use futures::Future;
use futures::Stream;
use tokio_core::reactor::Core;
use tokio_timer;
use url::Url;
use std::sync::RwLock;
use std::thread;
@@ -197,7 +199,7 @@ impl futures::Future for Worker {
}
impl Spotify {
pub fn new(events: EventManager, credentials: Credentials) -> Spotify {
pub fn new(cfg: Config, events: EventManager, credentials: Credentials) -> Spotify {
let player_config = PlayerConfig {
bitrate: Bitrate::Bitrate320,
normalisation: false,
@@ -208,7 +210,9 @@ impl Spotify {
let (tx, rx) = mpsc::unbounded();
{
let events = events.clone();
thread::spawn(move || Self::worker(events, rx, player_config, credentials, user_tx));
thread::spawn(move || {
Self::worker(cfg, events, rx, player_config, credentials, user_tx)
});
}
let spotify = Spotify {
@@ -226,10 +230,18 @@ impl Spotify {
spotify
}
pub fn test_credentials(credentials: Credentials) -> bool {
let th = thread::spawn(|| {
pub fn session_config(cfg: &Config) -> SessionConfig {
let mut session_config = SessionConfig::default();
if let Some(ref proxy) = cfg.proxy {
session_config.proxy = Url::parse(&proxy).ok();
}
session_config
}
pub fn test_credentials(cfg: Config, credentials: Credentials) -> bool {
let th = thread::spawn(move || {
let mut core = Core::new().unwrap();
let config = SessionConfig::default();
let config = Self::session_config(&cfg);
let handle = core.handle();
core.run(Session::connect(config, credentials, None, handle))
@@ -238,8 +250,8 @@ impl Spotify {
th.join().is_ok()
}
fn create_session(core: &mut Core, credentials: Credentials) -> Session {
let session_config = SessionConfig::default();
fn create_session(cfg: &Config, core: &mut Core, credentials: Credentials) -> Session {
let session_config = Self::session_config(cfg);
let cache = Cache::new(config::cache_path("librespot"), true);
let handle = core.handle();
debug!("opening spotify session");
@@ -279,6 +291,7 @@ impl Spotify {
}
fn worker(
cfg: Config,
events: EventManager,
commands: mpsc::UnboundedReceiver<WorkerCommand>,
player_config: PlayerConfig,
@@ -287,7 +300,7 @@ impl Spotify {
) {
let mut core = Core::new().unwrap();
let session = Self::create_session(&mut core, credentials);
let session = Self::create_session(&cfg, &mut core, credentials);
user_tx
.send(session.username())
.expect("could not pass username back to Spotify::new");

View File

@@ -57,7 +57,10 @@ impl ContextMenu {
content.add_item("Share", ContextMenuAction::ShareUrl(url));
}
if let Some(t) = item.track() {
content.add_item("Add to playlist", ContextMenuAction::AddToPlaylist(Box::new(t)))
content.add_item(
"Add to playlist",
ContextMenuAction::AddToPlaylist(Box::new(t)),
)
}
// open detail view of artist/album