From 1b999e3d9ba5627351c03a06a563177e0ff4b579 Mon Sep 17 00:00:00 2001 From: hinto-janaiyo <hinto.janaiyo@protonmail.com> Date: Sat, 10 Dec 2022 21:48:25 -0500 Subject: [PATCH] main/helper: change [Start] button, change [Sudo] input order --- src/constants.rs | 1 + src/helper.rs | 25 ++++++++++++++----------- src/main.rs | 30 +++++++++++++++--------------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 57d9632..55cb0b2 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -69,6 +69,7 @@ pub const RED: egui::Color32 = egui::Color32::from_rgb(230, 50, 50); pub const GREEN: egui::Color32 = egui::Color32::from_rgb(100, 230, 100); pub const YELLOW: egui::Color32 = egui::Color32::from_rgb(230, 230, 100); pub const BRIGHT_YELLOW: egui::Color32 = egui::Color32::from_rgb(250, 250, 100); +pub const WHITE: egui::Color32 = egui::Color32::WHITE; pub const GRAY: egui::Color32 = egui::Color32::GRAY; pub const LIGHT_GRAY: egui::Color32 = egui::Color32::LIGHT_GRAY; pub const BLACK: egui::Color32 = egui::Color32::BLACK; diff --git a/src/helper.rs b/src/helper.rs index e620c72..009df88 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -632,8 +632,8 @@ impl Helper { // Before that though, add the ["--prompt"] flag and set it // to emptyness so that it doesn't show up in the output. if cfg!(unix) { - args.push("--stdin".to_string()); args.push(r#"--prompt="#.to_string()); + args.push("--".to_string()); args.push(path.display().to_string()); } @@ -718,7 +718,7 @@ impl Helper { async fn spawn_xmrig_watchdog(process: Arc<Mutex<Process>>, gui_api: Arc<Mutex<PubXmrigApi>>, pub_api: Arc<Mutex<PubXmrigApi>>, priv_api: Arc<Mutex<PrivXmrigApi>>, args: Vec<String>, mut path: std::path::PathBuf, sudo: Arc<Mutex<SudoState>>) { // 1a. Create PTY let pty = portable_pty::native_pty_system(); - let pair = pty.openpty(portable_pty::PtySize { + let mut pair = pty.openpty(portable_pty::PtySize { rows: 100, cols: 1000, pixel_width: 0, @@ -732,7 +732,16 @@ impl Helper { // 1c. Create child let child_pty = Arc::new(Mutex::new(pair.slave.spawn_command(cmd).unwrap())); - // 2. Set process state + // 2. Input [sudo] pass, wipe, then drop. + if cfg!(unix) { + // 1d. Sleep to wait for [sudo]'s non-echo prompt (on Unix). + // this prevents users pass from showing up in the STDOUT. + std::thread::sleep(std::time::Duration::from_secs(3)); + writeln!(pair.master, "{}", sudo.lock().unwrap().pass); + SudoState::wipe(&sudo); + } + + // 3. Set process state let mut lock = process.lock().unwrap(); lock.state = ProcessState::Alive; lock.signal = ProcessSignal::None; @@ -740,15 +749,9 @@ impl Helper { lock.child = Some(Arc::clone(&child_pty)); let reader = pair.master.try_clone_reader().unwrap(); // Get STDOUT/STDERR before moving the PTY lock.stdin = Some(pair.master); - - // 3. Input [sudo] pass, wipe, then drop. - if cfg!(unix) { - writeln!(lock.stdin.as_mut().unwrap(), "{}", sudo.lock().unwrap().pass); - SudoState::wipe(&sudo); - } drop(lock); - // 3. Spawn PTY read thread + // 4. Spawn PTY read thread let output_full = Arc::clone(&process.lock().unwrap().output_full); let output_buf = Arc::clone(&process.lock().unwrap().output_buf); thread::spawn(move || { @@ -762,7 +765,7 @@ impl Helper { // let regex = P2poolRegex::new(); let start = process.lock().unwrap().start; - // 4. Loop as watchdog + // 5. Loop as watchdog info!("XMRig | Entering watchdog mode... woof!"); loop { // Set timer diff --git a/src/main.rs b/src/main.rs index f45e321..560333f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1152,9 +1152,9 @@ impl eframe::App for App { let width = (ui.available_width()/3.0)-5.0; if self.p2pool.lock().unwrap().is_waiting() { ui.add_enabled_ui(false, |ui| { - ui.add_sized([width, height], Button::new("⟲")).on_hover_text("Restart P2Pool"); - ui.add_sized([width, height], Button::new("⏹")).on_hover_text("Stop P2Pool"); - ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start P2Pool"); + ui.add_sized([width, height], Button::new("⟲")).on_disabled_hover_text("Restart P2Pool"); + ui.add_sized([width, height], Button::new("⏹")).on_disabled_hover_text("Stop P2Pool"); + ui.add_sized([width, height], Button::new("▶")).on_disabled_hover_text("Start P2Pool"); }); } else if self.p2pool.lock().unwrap().is_alive() { if ui.add_sized([width, height], Button::new("⟲")).on_hover_text("Restart P2Pool").clicked() { @@ -1164,12 +1164,12 @@ impl eframe::App for App { Helper::stop_p2pool(&self.helper); } ui.add_enabled_ui(false, |ui| { - ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start P2Pool"); + ui.add_sized([width, height], Button::new("▶")).on_disabled_hover_text("Start P2Pool"); }); } else { ui.add_enabled_ui(false, |ui| { - ui.add_sized([width, height], Button::new("⟲")).on_hover_text("Restart P2Pool"); - ui.add_sized([width, height], Button::new("⏹")).on_hover_text("Stop P2Pool"); + ui.add_sized([width, height], Button::new("⟲")).on_disabled_hover_text("Restart P2Pool"); + ui.add_sized([width, height], Button::new("⏹")).on_disabled_hover_text("Stop P2Pool"); }); // Check if address is okay before allowing to start. let mut text = String::new(); @@ -1180,7 +1180,7 @@ impl eframe::App for App { ui.set_enabled(false); text = P2POOL_PATH_NOT_EXE.to_string(); } - if ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start P2Pool").on_disabled_hover_text(text).clicked() { + if ui.add_sized([width, height], Button::new("▶")).on_hover_text("Start P2Pool").on_disabled_hover_text(text).clicked() { Helper::start_p2pool(&self.helper, &self.state.p2pool, &self.state.gupax.absolute_p2pool_path); } } @@ -1201,9 +1201,9 @@ impl eframe::App for App { let width = (ui.available_width()/3.0)-5.0; if self.xmrig.lock().unwrap().is_waiting() { ui.add_enabled_ui(false, |ui| { - ui.add_sized([width, height], Button::new("⟲")).on_hover_text("Restart XMRig"); - ui.add_sized([width, height], Button::new("⏹")).on_hover_text("Stop XMRig"); - ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start XMRig"); + ui.add_sized([width, height], Button::new("⟲")).on_disabled_hover_text("Restart XMRig"); + ui.add_sized([width, height], Button::new("⏹")).on_disabled_hover_text("Stop XMRig"); + ui.add_sized([width, height], Button::new("▶")).on_disabled_hover_text("Start XMRig"); }); } else if self.xmrig.lock().unwrap().is_alive() { if ui.add_sized([width, height], Button::new("⟲")).on_hover_text("Restart XMRig").clicked() { @@ -1226,12 +1226,12 @@ impl eframe::App for App { } } ui.add_enabled_ui(false, |ui| { - ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start XMRig"); + ui.add_sized([width, height], Button::new("▶")).on_disabled_hover_text("Start XMRig"); }); } else { ui.add_enabled_ui(false, |ui| { - ui.add_sized([width, height], Button::new("⟲")).on_hover_text("Restart XMRig"); - ui.add_sized([width, height], Button::new("⏹")).on_hover_text("Stop XMRig"); + ui.add_sized([width, height], Button::new("⟲")).on_disabled_hover_text("Restart XMRig"); + ui.add_sized([width, height], Button::new("⏹")).on_disabled_hover_text("Stop XMRig"); }); let mut text = String::new(); if !Gupax::path_is_exe(&self.state.gupax.xmrig_path) { @@ -1239,11 +1239,11 @@ impl eframe::App for App { text = XMRIG_PATH_NOT_EXE.to_string(); } #[cfg(target_os = "windows")] - if ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start XMRig").on_disabled_hover_text(text).clicked() { + if ui.add_sized([width, height], Button::new("▶")).on_hover_text("Start XMRig").on_disabled_hover_text(text).clicked() { Helper::start_xmrig(&self.helper, &self.state.xmrig, &self.state.gupax.absolute_xmrig_path, Arc::clone(&self.sudo)); } #[cfg(target_family = "unix")] - if ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start XMRig").on_disabled_hover_text(text).clicked() { + if ui.add_sized([width, height], Button::new("▶")).on_hover_text("Start XMRig").on_disabled_hover_text(text).clicked() { self.sudo.lock().unwrap().signal = ProcessSignal::Start; self.error_state.ask_sudo(&self.sudo); }