Skip to content

Commit

Permalink
fix: use dialoguer for reading password and username
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Feb 22, 2022
1 parent d8af1af commit 521b35e
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 13 deletions.
50 changes: 46 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scrob-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async-trait = "0.1.21"
futures = "0.3"
env_logger = "0.9.0"
clap = { version = "2.34.0", features = ["suggestions", "color"] }
text_io = "0.1.9"
confy = "0.4.0"
dialoguer = "0.10.0"


config = { path = "../config" }
Expand Down
32 changes: 25 additions & 7 deletions scrob-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
use clap::clap_app;
use config as meta;
use log::trace;
use text_io::read;

use dialoguer::{theme::ColorfulTheme, Input, Password};
use env_logger;
use scrob_core::core::core;
use scrob_core::Preferences;
use types::config::ScrobConfig;

fn config_unix() {
let cfg: ScrobConfig = confy::load("scrob")
.expect("Error loading config. Have you logged in yet? Login with 'login' subcommand");
todo!("Not implemented yet");
}

fn main() {
env_logger::init();

Expand All @@ -31,23 +37,35 @@ fn main() {

trace!("Cli: {:?}", matches);
if let Some(_) = matches.subcommand_matches("login") {
println!("Enter your last.fm username\n");

// read until a newline (but not including it)
let username: String = read!("{}\n");
let username: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("last.fm username")
.interact_text()
.unwrap();

println!("Enter your last.fm password\n");
let password: String = read!("{}\n");
let password = Password::with_theme(&ColorfulTheme::default())
.with_prompt("password")
.interact()
.unwrap();

println!("Logged in successfully!\n");
println!("Login details saved to config folder");

let cfg = ScrobConfig {
version: 1,
password: password,
username: username,
..Default::default()
};

confy::store("scrob", &cfg).expect("Failed to store config");
return;
}

if let Some(_) = matches.subcommand_matches("config") {
#[cfg(unix)]
config_unix();

return;
}

let prefs = Preferences {
Expand Down
6 changes: 5 additions & 1 deletion scrob-core/src/integrations/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ impl BaseIntegrationTrait for Discord {
}

let app_desc = format!("{} {}", meta::APP_NAME, meta::APP_VERSION);
trace!("setting discord activity with image '{}' and app desc '{}'", song.source.as_str(), app_desc);
trace!(
"setting discord activity with image '{}' and app desc '{}'",
song.source.as_str(),
app_desc
);
let assets = activity::Assets::new()
.large_image(song.source.as_str())
.large_text(app_desc.as_str())
Expand Down
26 changes: 26 additions & 0 deletions types/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@ use serde::{Deserialize, Serialize};

use crate::integrations::{Event, Integrations};

#[derive(Serialize, Deserialize, Clone)]
pub struct DiscordSettings {
pub enabled: bool,
pub blacklist_apps: Vec<String>,
pub blacklist_urls: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct ScrobbleSettings {
pub enabled: bool,
pub blacklist_apps: Vec<String>,
pub blacklist_urls: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct ScrobConfig {
pub version: u8,
pub password: String,
pub username: String,
pub discord: DiscordSettings,
pub scrobble: ScrobbleSettings,
}

/// `MyConfig` implements `Default`
Expand All @@ -16,6 +32,16 @@ impl ::std::default::Default for ScrobConfig {
version: 1,
password: "".into(),
username: "".into(),
scrobble: ScrobbleSettings {
enabled: true,
blacklist_apps: vec![],
blacklist_urls: vec![],
},
discord: DiscordSettings {
enabled: true,
blacklist_apps: vec![],
blacklist_urls: vec![],
},
}
}
}
Expand Down

0 comments on commit 521b35e

Please sign in to comment.