diff --git a/images/thread_model.png b/images/thread_model.png index 442113a..3b4659a 100644 Binary files a/images/thread_model.png and b/images/thread_model.png differ diff --git a/src/README.md b/src/README.md index 7e5c976..f7aff25 100644 --- a/src/README.md +++ b/src/README.md @@ -53,7 +53,9 @@ This is how Gupax works internally when starting up: 2. **AUTO** - If `auto_update` == `true`, spawn auto-updating thread - - If `auto_select` == `true`, spawn community node ping thread + - If `auto_ping` == `true`, spawn community node ping thread + - If `auto_p2pool` == `true`, spawn P2Pool + - If `auto_xmrig` == `true`, spawn XMRig 3. **MAIN** - All data should be initialized at this point, either via `state.toml` or default options diff --git a/src/constants.rs b/src/constants.rs index 55cb0b2..8fdf566 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -121,6 +121,8 @@ pub const GUPAX_UPDATE_VIA_TOR: &str = "Update through the Tor network. Tor is e pub const GUPAX_UPDATE_VIA_TOR: &'static str = "WARNING: This option is unstable on macOS. Update through the Tor network. Tor is embedded within Gupax; a Tor system proxy is not required"; pub const GUPAX_ASK_BEFORE_QUIT: &str = "Ask before quitting Gupax"; pub const GUPAX_SAVE_BEFORE_QUIT: &str = "Automatically save any changed settings before quitting"; +pub const GUPAX_AUTO_P2POOL: &str = "Automatically start P2Pool on Gupax startup. If you are using [P2Pool Simple], this will NOT wait for your [Auto-Ping] to finish, it will start P2Pool on the pool you already have selected. This option will fail if your P2Pool settings aren't valid!"; +pub const GUPAX_AUTO_XMRIG: &str = "Automatically start XMRig on Gupax startup. This option will fail if your XMRig settings aren't valid!"; pub const GUPAX_WIDTH: &str = "Set the width of the Gupax window"; pub const GUPAX_HEIGHT: &str = "Set the height of the Gupax window"; pub const GUPAX_LOCK_WIDTH: &str = "Automatically match the HEIGHT against the WIDTH in a 4:3 ratio"; diff --git a/src/disk.rs b/src/disk.rs index 24d6862..5e7240e 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -142,6 +142,8 @@ impl State { simple: true, auto_update: true, auto_node: true, + auto_p2pool: true, + auto_xmrig: true, ask_before_quit: true, save_before_quit: true, #[cfg(not(target_os = "macos"))] @@ -579,6 +581,8 @@ pub struct Gupax { pub simple: bool, pub auto_update: bool, pub auto_node: bool, + pub auto_p2pool: bool, + pub auto_xmrig: bool, pub ask_before_quit: bool, pub save_before_quit: bool, pub update_via_tor: bool, diff --git a/src/gupax.rs b/src/gupax.rs index 9907f71..066df38 100644 --- a/src/gupax.rs +++ b/src/gupax.rs @@ -114,12 +114,17 @@ impl Gupax { ui.horizontal(|ui| { ui.group(|ui| { - let width = (width - SPACE*7.5)/4.0; + let width = (width - SPACE*12.0)/6.0; let height = height/10.0; - ui.add_sized([width, height], Checkbox::new(&mut self.auto_update, "Auto-update")).on_hover_text(GUPAX_AUTO_UPDATE); - ui.separator(); + ui.style_mut().override_text_style = Some(egui::TextStyle::Small); ui.add_sized([width, height], Checkbox::new(&mut self.update_via_tor, "Update via Tor")).on_hover_text(GUPAX_UPDATE_VIA_TOR); ui.separator(); + ui.add_sized([width, height], Checkbox::new(&mut self.auto_update, "Auto-Update")).on_hover_text(GUPAX_AUTO_UPDATE); + ui.separator(); + ui.add_sized([width, height], Checkbox::new(&mut self.auto_p2pool, "Auto-P2Pool")).on_hover_text(GUPAX_AUTO_P2POOL); + ui.separator(); + ui.add_sized([width, height], Checkbox::new(&mut self.auto_xmrig, "Auto-XMRig")).on_hover_text(GUPAX_AUTO_XMRIG); + ui.separator(); ui.add_sized([width, height], Checkbox::new(&mut self.ask_before_quit, "Ask before quit")).on_hover_text(GUPAX_ASK_BEFORE_QUIT); ui.separator(); ui.add_sized([width, height], Checkbox::new(&mut self.save_before_quit, "Save before quit")).on_hover_text(GUPAX_SAVE_BEFORE_QUIT); diff --git a/src/helper.rs b/src/helper.rs index 009df88..1c7f4b6 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -405,8 +405,7 @@ impl Helper { } // The P2Pool watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works. - #[tokio::main] - async fn spawn_p2pool_watchdog(process: Arc>, gui_api: Arc>, pub_api: Arc>, priv_api: Arc>, args: Vec, mut path: std::path::PathBuf) { + fn spawn_p2pool_watchdog(process: Arc>, gui_api: Arc>, pub_api: Arc>, priv_api: Arc>, args: Vec, mut path: std::path::PathBuf) { // 1a. Create PTY let pty = portable_pty::native_pty_system(); let pair = pty.openpty(portable_pty::PtySize { @@ -714,8 +713,7 @@ impl Helper { } // The P2Pool watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works. - #[tokio::main] - async fn spawn_xmrig_watchdog(process: Arc>, gui_api: Arc>, pub_api: Arc>, priv_api: Arc>, args: Vec, mut path: std::path::PathBuf, sudo: Arc>) { + fn spawn_xmrig_watchdog(process: Arc>, gui_api: Arc>, pub_api: Arc>, priv_api: Arc>, args: Vec, mut path: std::path::PathBuf, sudo: Arc>) { // 1a. Create PTY let pty = portable_pty::native_pty_system(); let mut pair = pty.openpty(portable_pty::PtySize { diff --git a/src/main.rs b/src/main.rs index 560333f..450b6c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -601,13 +601,40 @@ fn init_auto(app: &mut App) { } // [Auto-Ping] - let auto_node = app.og.lock().unwrap().p2pool.auto_node; - let simple = app.og.lock().unwrap().p2pool.simple; - if auto_node && simple { + if app.state.p2pool.auto_node && app.state.p2pool.simple { Ping::spawn_thread(&app.ping) } else { info!("Skipping auto-ping..."); } + + // [Auto-P2Pool] + if app.state.gupax.auto_p2pool { + if !Regexes::addr_ok(&app.regex, &app.state.p2pool.address) { + warn!("Gupax | P2Pool address is not valid! Skipping auto-p2pool..."); + } else if !Gupax::path_is_exe(&app.state.gupax.p2pool_path) { + warn!("Gupax | P2Pool path is not an executable! Skipping auto-p2pool..."); + } else { + Helper::start_p2pool(&app.helper, &app.state.p2pool, &app.state.gupax.absolute_p2pool_path); + } + } else { + info!("Skipping auto-xmrig..."); + } + + // [Auto-XMRig] + if app.state.gupax.auto_xmrig { + if !Gupax::path_is_exe(&app.state.gupax.xmrig_path) { + warn!("Gupax | XMRig path is not an executable! Skipping auto-xmrig..."); + } else { + if cfg!(windows) { + Helper::start_xmrig(&app.helper, &app.state.xmrig, &app.state.gupax.absolute_xmrig_path, Arc::clone(&app.sudo)); + } else { + app.sudo.lock().unwrap().signal = ProcessSignal::Start; + app.error_state.ask_sudo(&app.sudo); + } + } + } else { + info!("Skipping auto-xmrig..."); + } } //---------------------------------------------------------------------------------------------------- Reset functions