From e0ece356a0e70f9d1c0204efc4c44df3e7482f33 Mon Sep 17 00:00:00 2001 From: Cyrix126 Date: Wed, 2 Oct 2024 18:18:04 +0200 Subject: [PATCH] feat: add warning popup for windows about xmrig outside of Gupaxx if an xmrig instance run on Windows OS outside of Gupaxx, the later can freeze since xmrig has been started without "below priority". A popup warning the user in the case a xmrig instance is detected whithout the xmrig process started in Gupaxx is added in this commit. --- src/app/eframe_impl.rs | 15 ++++++++++++++- src/app/mod.rs | 5 ++++- src/utils/errors.rs | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/app/eframe_impl.rs b/src/app/eframe_impl.rs index 3165b0f..dd4a0aa 100644 --- a/src/app/eframe_impl.rs +++ b/src/app/eframe_impl.rs @@ -1,4 +1,8 @@ use super::App; +#[cfg(target_os = "windows")] +use crate::errors::{process_running, ErrorButtons, ErrorFerris}; +#[cfg(target_os = "windows")] +use crate::helper::ProcessName; use crate::helper::ProcessState; use crate::macros::lock; use crate::SECOND; @@ -63,7 +67,16 @@ impl eframe::App for App { self.size.y = ui.available_height(); }); self.resize(ctx); - + // check for windows that a local instance of xmrig is not running outside of Gupaxx. Important because it could lead to crashes on this platform. + // Warn only once per restart of Gupaxx. + #[cfg(target_os = "windows")] + if !self.xmrig_outside_warning_acknowledge + && process_running(ProcessName::Xmrig) + && !xmrig_is_alive + { + self.error_state.set("An instance of xmrig is running outside of Gupaxx.\nThis is not supported and could lead to crashes on this platform.\nPlease stop your local instance and start xmrig from Gupaxx Xmrig tab.", ErrorFerris::Error, ErrorButtons::Okay); + self.xmrig_outside_warning_acknowledge = true; + } // If there's an error, display [ErrorState] on the whole screen until user responds debug!("App | Checking if there is an error in [ErrorState]"); if self.error_state.error { diff --git a/src/app/mod.rs b/src/app/mod.rs index 1407c3c..7e57f80 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -144,6 +144,8 @@ pub struct App { pub pool_path: PathBuf, // Pool file path pub version: &'static str, // Gupax version pub name_version: String, // [Gupax vX.X.X] + #[cfg(target_os = "windows")] + pub xmrig_outside_warning_acknowledge: bool, } impl App { @@ -306,6 +308,8 @@ impl App { pool_path: PathBuf::new(), version: GUPAX_VERSION, name_version: format!("Gupaxx {}", GUPAX_VERSION), + #[cfg(target_os = "windows")] + xmrig_outside_warning_acknowledge: false, }; //---------------------------------------------------------------------------------------------------- App init data that *could* panic info!("App Init | Getting EXE path..."); @@ -601,7 +605,6 @@ impl App { error!("Unix | Regular user not detected: [{:?}]", id); app.error_state.set(format!("Gupaxx was launched as: [{:?}]\nPlease launch Gupax with regular user permissions.", id), ErrorFerris::Panic, ErrorButtons::Quit); } - // macOS re-locates "dangerous" applications into some read-only "/private" directory. // It _seems_ to be fixed by moving [Gupax.app] into "/Applications". // So, detect if we are in in "/private" and warn the user. diff --git a/src/utils/errors.rs b/src/utils/errors.rs index 3735094..0873058 100644 --- a/src/utils/errors.rs +++ b/src/utils/errors.rs @@ -1,5 +1,11 @@ use std::sync::{Arc, Mutex}; +#[cfg(target_os = "windows")] +use sysinfo::System; + +#[cfg(target_os = "windows")] +use crate::helper::ProcessName; + use super::sudo::SudoState; //---------------------------------------------------------------------------------------------------- [ErrorState] struct @@ -91,3 +97,19 @@ impl ErrorState { SudoState::reset(state) } } + +#[cfg(target_os = "windows")] +pub fn process_running(process_name: ProcessName) -> bool { + let name = match process_name { + ProcessName::P2pool => "p2pool", + ProcessName::Xmrig => "xmrig", + ProcessName::XmrigProxy => "xmrig-proxy", + ProcessName::Node => "monerod", + ProcessName::Xvb => panic!("XvB does not exist as a process outside of Gupaxx"), + }; + let s = System::new_all(); + if s.processes_by_name(name.as_ref()).next().is_some() { + return true; + } + false +}