Skip to content

Commit

Permalink
Make the setup prompt cli only #24
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlexDev23 committed Oct 26, 2024
1 parent 64a89aa commit 2c27d30
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
18 changes: 18 additions & 0 deletions crates/power-daemon-mgr/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::io::{self, Write};

pub fn yn_prompt(prompt: &str) -> bool {
loop {
print!("{} [Y/n]: ", prompt);
io::stdout().flush().unwrap();

let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();

let trimmed_input = input.trim().to_lowercase();
match trimmed_input.as_str() {
"y" | "yes" | "" => return true,
"n" | "no" => return false,
_ => println!("Invalid input. Please enter 'y' or 'n'."),
}
}
}
1 change: 1 addition & 0 deletions crates/power-daemon-mgr/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod helpers;
mod setup;

use std::path::Path;
Expand Down
13 changes: 6 additions & 7 deletions crates/power-daemon-mgr/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use std::{fs, path::Path};
use log::{debug, trace};
use power_daemon::{profiles_generator, Config, DefaultProfileType, SystemInfo};

use crate::helpers::yn_prompt;

pub fn setup(root: &Path) {
let agreed = std::process::Command::new("yad").args([
"--selectable-labels",
"--title",
"Warning: do you want power-options to generate profiles?",
"--text",
"By default, power-options will generate profiles based on the features of your system, <b>and it might apply them</b>.\nPlease refer to the wiki (https://github.com/TheAlexDev23/power-options/wiki/Default-generated-settings) to be aware of potential issues that might arise.\nIf you click cancel, an empty default profile will be generated."
]).spawn().expect("Could not spawn popup").wait().expect("Could not wait from popup").success();
println!("\nWarning: do you want power-options to generate profiles?");
println!("By default, power-options will generate profiles based on the features of your system, and it might apply them. \nPlease refer to the wiki (https://github.com/TheAlexDev23/power-options/wiki/Default-generated-settings) to be aware of potential issues that might arise.");

let agreed = yn_prompt("Are you sure you want to continue? If you answer no an empty default profile would be genereated.");

if agreed {
generate_config_files(root);
Expand Down

0 comments on commit 2c27d30

Please sign in to comment.