Skip to content

Commit a11e487

Browse files
feat: update twitchdrops_miner to version 1.0.3 and implement first-time setup for configuration
1 parent ffaa411 commit a11e487

4 files changed

Lines changed: 91 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "twitchdrops_miner"
3-
version = "1.0.2"
3+
version = "1.0.3"
44
edition = "2024"
55

66
[dependencies]

src/config.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,76 @@ async fn open_lines (path: &str) -> Result<Lines<BufReader<File>>, Box<dyn Error
2727
Ok(reader)
2828
}
2929

30+
fn print_section(title: &str) {
31+
println!("\n\x1b[90m{}\x1b[0m", "─".repeat(50));
32+
println!("\x1b[90m{}\x1b[0m", title.to_uppercase());
33+
}
34+
3035
impl Config {
36+
pub async fn first_time_setup (&mut self) -> Result<(), Box<dyn Error>> {
37+
print_section("Autostart");
38+
let autostart_question = dialoguer::Confirm::new().with_prompt("▸ Start automatically on login?").default(false).interact()?;
39+
print_section("Discord Webhook");
40+
let webhook_url: String = dialoguer::Input::new().with_prompt("▸ Webhook URL (optional, Enter to skip)").allow_empty(true).interact_text()?;
41+
42+
//proxies list input
43+
print_section("Proxies");
44+
let mut proxies_vec = Vec::new();
45+
loop {
46+
let proxy: String = dialoguer::Input::new().with_prompt("▸ Add proxy (Enter to finish)").allow_empty(true).validate_with(|input: &String| {
47+
let trimmed = input.trim();
48+
if trimmed.is_empty() {
49+
return Ok(());
50+
}
51+
if proxies_vec.contains(&trimmed.to_string()) {
52+
Err("This proxy is already in the list.")
53+
} else {
54+
Ok(())
55+
}
56+
}).interact_text()?;
57+
if proxy.trim().is_empty() {
58+
break;
59+
}
60+
proxies_vec.push(proxy);
61+
}
62+
63+
//games list input
64+
print_section("Game priority list");
65+
let mut games_vec: VecDeque<String> = VecDeque::new();
66+
67+
loop {
68+
let prompt = if games_vec.is_empty() {
69+
"▸ First game (Enter to skip)".to_string()
70+
} else {
71+
format!("▸ #{}", games_vec.len() + 1)
72+
};
73+
let game: String = dialoguer::Input::new().with_prompt(prompt).allow_empty(true).validate_with(|input: &String| {
74+
let trimmed = input.trim();
75+
76+
if trimmed.is_empty() {
77+
return Ok(());
78+
}
79+
80+
if games_vec.contains(&trimmed.to_string()) {
81+
Err("This game is already in the list.")
82+
} else {
83+
Ok(())
84+
}
85+
}).interact_text()?;
86+
87+
if game.trim().is_empty() {
88+
break;
89+
}
90+
games_vec.push_back(game.trim().to_string());
91+
}
92+
93+
self.save_games_list(&games_vec).await?;
94+
self.save_proxies_list(&proxies_vec).await?;
95+
self.autostart = autostart_question;
96+
self.discord_webhook_url = webhook_url;
97+
Ok(())
98+
}
99+
31100
pub fn configure_autostart (&self) -> Result<(), Box<dyn Error>> {
32101
let app_path = {
33102
let path = env::current_exe()?;
@@ -91,6 +160,18 @@ impl Config {
91160
Ok(config)
92161
}
93162

163+
async fn save_games_list (&self, games: &VecDeque<String>) -> Result<(), Box<dyn Error>> {
164+
let to_write = games.iter().map(|g| format!("{}\n", g)).collect::<String>();
165+
fs::write(&self.games_path, to_write).await?;
166+
Ok(())
167+
}
168+
169+
async fn save_proxies_list (&self, proxies: &Vec<String>) -> Result<(), Box<dyn Error>> {
170+
let to_write = proxies.iter().map(|p| format!("{}\n", p)).collect::<String>();
171+
fs::write(&self.proxies_path, to_write).await?;
172+
Ok(())
173+
}
174+
94175
pub async fn load_proxies_list (&self) -> Result<Vec<String>, Box<dyn Error>> {
95176
let mut reader = open_lines(&self.proxies_path).await?;
96177

src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ async fn main () -> Result<(), Box<dyn Error>> {
8383
}
8484

8585
let config_path = home_dir.join("config.json");
86-
if !config_path.exists() {
87-
let config = Config::new().await?;
88-
config.save(&config_path).await?
89-
}
86+
let config = if !config_path.exists() {
87+
let mut config = Config::new().await?;
88+
config.first_time_setup().await?;
89+
config.save(&config_path).await?;
90+
config
91+
} else {
92+
Config::load(&config_path).await?
93+
};
9094

91-
let config = Config::load(&config_path).await?;
9295
config.configure_autostart()?;
9396

9497
let mut proxies = config.load_proxies_list().await?;

0 commit comments

Comments
 (0)