diff --git a/crates/power-daemon-mgr/src/helpers.rs b/crates/power-daemon-mgr/src/helpers.rs new file mode 100644 index 0000000..edcf38d --- /dev/null +++ b/crates/power-daemon-mgr/src/helpers.rs @@ -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'."), + } + } +} diff --git a/crates/power-daemon-mgr/src/main.rs b/crates/power-daemon-mgr/src/main.rs index d75b87f..bd8609a 100644 --- a/crates/power-daemon-mgr/src/main.rs +++ b/crates/power-daemon-mgr/src/main.rs @@ -1,3 +1,4 @@ +mod helpers; mod setup; use std::path::Path; diff --git a/crates/power-daemon-mgr/src/setup.rs b/crates/power-daemon-mgr/src/setup.rs index 34963ad..bee2ecb 100644 --- a/crates/power-daemon-mgr/src/setup.rs +++ b/crates/power-daemon-mgr/src/setup.rs @@ -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, 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.\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);