mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-11-16 15:27:46 +00:00
cargo check/clippy fixes
This commit is contained in:
parent
0f51ae6873
commit
d3bbe2ece2
12 changed files with 106 additions and 91 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "Gupax"
|
||||
version = "0.9.0"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arti-client",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "Gupax"
|
||||
version = "0.9.0"
|
||||
version = "1.0.0"
|
||||
authors = ["hinto-janaiyo <hinto.janaiyo@protonmail.com>"]
|
||||
description = "GUI for P2Pool+XMRig"
|
||||
documentation = "https://github.com/hinto-janaiyo/gupax"
|
||||
|
|
|
@ -58,7 +58,7 @@ r#"*--------------------------------------*
|
|||
pub const P2POOL_API_PATH: &str = r"local\stats"; // The default relative FS path of P2Pool's local API
|
||||
#[cfg(target_family = "unix")]
|
||||
pub const P2POOL_API_PATH: &str = "local/stats";
|
||||
pub const XMRIG_API_URI: &str = "1/summary"; // The default relative URI of XMRig's API
|
||||
pub const XMRIG_API_URI: &str = "/1/summary"; // The default relative URI of XMRig's API
|
||||
|
||||
// Process state tooltips (online, offline, etc)
|
||||
pub const P2POOL_ALIVE: &str = "P2Pool is online";
|
||||
|
|
|
@ -140,6 +140,12 @@ pub fn into_absolute_path(path: String) -> Result<PathBuf, TomlError> {
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- [State] Impl
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> Self {
|
||||
let max_threads = num_cpus::get();
|
||||
|
|
|
@ -81,7 +81,7 @@ pub enum Ratio {
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- Gupax
|
||||
impl Gupax {
|
||||
pub fn show(&mut self, og: &Arc<Mutex<State>>, state_path: &Path, update: &Arc<Mutex<Update>>, file_window: &Arc<Mutex<FileWindow>>, error_state: &mut ErrorState, restart: &Arc<Mutex<Restart>>, width: f32, height: f32, frame: &mut eframe::Frame, ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
pub fn show(&mut self, og: &Arc<Mutex<State>>, state_path: &Path, update: &Arc<Mutex<Update>>, file_window: &Arc<Mutex<FileWindow>>, error_state: &mut ErrorState, restart: &Arc<Mutex<Restart>>, width: f32, height: f32, frame: &mut eframe::Frame, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
// Update button + Progress bar
|
||||
debug!("Gupax Tab | Rendering [Update] button + progress bar");
|
||||
ui.group(|ui| {
|
||||
|
@ -95,7 +95,7 @@ impl Gupax {
|
|||
ui.vertical(|ui| {
|
||||
ui.set_enabled(!updating);
|
||||
if ui.add_sized([width, height], Button::new("Check for updates")).on_hover_text(GUPAX_UPDATE).clicked() {
|
||||
Update::spawn_thread(og, &self, state_path, update, error_state, restart);
|
||||
Update::spawn_thread(og, self, state_path, update, error_state, restart);
|
||||
}
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
|
@ -254,7 +254,7 @@ impl Gupax {
|
|||
pub fn path_is_exe(path: &str) -> bool {
|
||||
let path = path.to_string();
|
||||
match crate::disk::into_absolute_path(path) {
|
||||
Ok(path) => if path.is_file() { true } else { false },
|
||||
Ok(path) => path.is_file(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
use std::{
|
||||
sync::{Arc,Mutex},
|
||||
path::PathBuf,
|
||||
process::{Command,Stdio},
|
||||
process::Stdio,
|
||||
fmt::Write,
|
||||
time::*,
|
||||
thread,
|
||||
|
@ -48,7 +48,7 @@ use crate::{
|
|||
};
|
||||
use sysinfo::SystemExt;
|
||||
use serde::{Serialize,Deserialize};
|
||||
use num_format::{Buffer,Locale};
|
||||
use sysinfo::{CpuExt,ProcessExt};
|
||||
use log::*;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Constants
|
||||
|
@ -114,6 +114,12 @@ impl Sys {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Sys {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- [Process] Struct
|
||||
// This holds all the state of a (child) process.
|
||||
// The main GUI thread will use this to display console text, online state, etc.
|
||||
|
@ -154,7 +160,7 @@ pub struct Process {
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- [Process] Impl
|
||||
impl Process {
|
||||
pub fn new(name: ProcessName, args: String, path: PathBuf) -> Self {
|
||||
pub fn new(name: ProcessName, _args: String, _path: PathBuf) -> Self {
|
||||
Self {
|
||||
name,
|
||||
state: ProcessState::Dead,
|
||||
|
@ -210,11 +216,16 @@ pub enum ProcessName {
|
|||
|
||||
impl std::fmt::Display for ProcessState { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:#?}", self) } }
|
||||
impl std::fmt::Display for ProcessSignal { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:#?}", self) } }
|
||||
impl std::fmt::Display for ProcessName { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:#?}", self) } }
|
||||
impl std::fmt::Display for ProcessName {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match *self {
|
||||
ProcessName::P2pool => write!(f, "P2Pool"),
|
||||
ProcessName::Xmrig => write!(f, "XMRig"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- [Helper]
|
||||
use tokio::io::{BufReader,AsyncBufReadExt};
|
||||
|
||||
impl Helper {
|
||||
//---------------------------------------------------------------------------------------------------- General Functions
|
||||
pub fn new(instant: std::time::Instant, pub_sys: Arc<Mutex<Sys>>, p2pool: Arc<Mutex<Process>>, xmrig: Arc<Mutex<Process>>, gui_api_p2pool: Arc<Mutex<PubP2poolApi>>, gui_api_xmrig: Arc<Mutex<PubXmrigApi>>, img_p2pool: Arc<Mutex<ImgP2pool>>, img_xmrig: Arc<Mutex<ImgXmrig>>) -> Self {
|
||||
|
@ -242,8 +253,8 @@ impl Helper {
|
|||
let mut stdout = std::io::BufReader::new(reader).lines();
|
||||
while let Some(Ok(line)) = stdout.next() {
|
||||
// println!("{}", line); // For debugging.
|
||||
writeln!(output_full.lock().unwrap(), "{}", line);
|
||||
writeln!(output_buf.lock().unwrap(), "{}", line);
|
||||
if let Err(e) = writeln!(output_full.lock().unwrap(), "{}", line) { error!("PTY | Output error: {}", e); }
|
||||
if let Err(e) = writeln!(output_buf.lock().unwrap(), "{}", line) { error!("PTY | Output error: {}", e); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +291,7 @@ impl Helper {
|
|||
let mut gui_api = gui_api.lock().unwrap();
|
||||
if gui_api.output.len() > GUI_OUTPUT_LEEWAY {
|
||||
info!("XMRig | Output is nearing {} bytes, resetting!", MAX_GUI_OUTPUT_BYTES);
|
||||
let text = format!("{}\nP2Pool GUI log is exceeding the maximum: {} bytes!\nI've reset the logs for you, but your stats will be fine (at least for around a month) since they rely on an internal log!\n{}\n\n\n\n", HORI_CONSOLE, MAX_GUI_OUTPUT_BYTES, HORI_CONSOLE);
|
||||
let text = format!("{}\nXMRig GUI log is exceeding the maximum: {} bytes!\nI've reset the logs for you, but your stats will be fine (at least for around a month) since they rely on an internal log!\n{}\n\n\n\n", HORI_CONSOLE, MAX_GUI_OUTPUT_BYTES, HORI_CONSOLE);
|
||||
gui_api.output.clear();
|
||||
gui_api.output.push_str(&text);
|
||||
}
|
||||
|
@ -302,7 +313,7 @@ impl Helper {
|
|||
helper.lock().unwrap().p2pool.lock().unwrap().signal = ProcessSignal::Restart;
|
||||
helper.lock().unwrap().p2pool.lock().unwrap().state = ProcessState::Middle;
|
||||
|
||||
let helper = Arc::clone(&helper);
|
||||
let helper = Arc::clone(helper);
|
||||
let state = state.clone();
|
||||
let path = path.clone();
|
||||
// This thread lives to wait, start p2pool then die.
|
||||
|
@ -344,7 +355,7 @@ impl Helper {
|
|||
pub fn build_p2pool_args_and_mutate_img(helper: &Arc<Mutex<Self>>, state: &crate::disk::P2pool, path: &std::path::PathBuf) -> (Vec<String>, PathBuf) {
|
||||
let mut args = Vec::with_capacity(500);
|
||||
let path = path.clone();
|
||||
let mut api_path = path.clone();
|
||||
let mut api_path = path;
|
||||
api_path.pop();
|
||||
|
||||
// [Simple]
|
||||
|
@ -426,7 +437,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.
|
||||
fn spawn_p2pool_watchdog(process: Arc<Mutex<Process>>, gui_api: Arc<Mutex<PubP2poolApi>>, pub_api: Arc<Mutex<PubP2poolApi>>, priv_api: Arc<Mutex<PrivP2poolApi>>, args: Vec<String>, path: std::path::PathBuf, api_path: std::path::PathBuf) {
|
||||
fn spawn_p2pool_watchdog(process: Arc<Mutex<Process>>, gui_api: Arc<Mutex<PubP2poolApi>>, pub_api: Arc<Mutex<PubP2poolApi>>, _priv_api: Arc<Mutex<PrivP2poolApi>>, args: Vec<String>, path: std::path::PathBuf, api_path: std::path::PathBuf) {
|
||||
// 1a. Create PTY
|
||||
debug!("P2Pool | Creating PTY...");
|
||||
let pty = portable_pty::native_pty_system();
|
||||
|
@ -474,7 +485,7 @@ impl Helper {
|
|||
}
|
||||
// Attempt to create a default empty one.
|
||||
use std::io::Write;
|
||||
if let Ok(_) = std::fs::File::create(&api_path) {
|
||||
if std::fs::File::create(&api_path).is_ok() {
|
||||
let text = r#"{"hashrate_15m":0,"hashrate_1h":0,"hashrate_24h":0,"shares_found":0,"average_effort":0.0,"current_effort":0.0,"connections":0}"#;
|
||||
match std::fs::write(&path, text) {
|
||||
Ok(_) => info!("P2Pool | Creating default empty API file ... OK"),
|
||||
|
@ -510,7 +521,8 @@ impl Helper {
|
|||
// Check SIGNAL
|
||||
if process.lock().unwrap().signal == ProcessSignal::Stop {
|
||||
debug!("P2Pool Watchdog | Stop SIGNAL caught");
|
||||
child_pty.lock().unwrap().kill(); // This actually sends a SIGHUP to p2pool (closes the PTY, hangs up on p2pool)
|
||||
// This actually sends a SIGHUP to p2pool (closes the PTY, hangs up on p2pool)
|
||||
if let Err(e) = child_pty.lock().unwrap().kill() { error!("P2Pool Watchdog | Kill error: {}", e); }
|
||||
// Wait to get the exit status
|
||||
let exit_status = match child_pty.lock().unwrap().wait() {
|
||||
Ok(e) => {
|
||||
|
@ -532,7 +544,8 @@ impl Helper {
|
|||
// Check RESTART
|
||||
} else if process.lock().unwrap().signal == ProcessSignal::Restart {
|
||||
debug!("P2Pool Watchdog | Restart SIGNAL caught");
|
||||
child_pty.lock().unwrap().kill(); // This actually sends a SIGHUP to p2pool (closes the PTY, hangs up on p2pool)
|
||||
// This actually sends a SIGHUP to p2pool (closes the PTY, hangs up on p2pool)
|
||||
if let Err(e) = child_pty.lock().unwrap().kill() { error!("P2Pool Watchdog | Kill error: {}", e); }
|
||||
// Wait to get the exit status
|
||||
let exit_status = match child_pty.lock().unwrap().wait() {
|
||||
Ok(e) => if e.success() { "Successful" } else { "Failed" },
|
||||
|
@ -553,7 +566,7 @@ impl Helper {
|
|||
let input = std::mem::take(&mut lock.input);
|
||||
for line in input {
|
||||
debug!("P2Pool Watchdog | User input not empty, writing to STDIN: [{}]", line);
|
||||
writeln!(lock.stdin.as_mut().unwrap(), "{}", line);
|
||||
if let Err(e) = writeln!(lock.stdin.as_mut().unwrap(), "{}", line) { error!("P2Pool Watchdog | STDIN error: {}", e); }
|
||||
}
|
||||
}
|
||||
drop(lock);
|
||||
|
@ -624,7 +637,7 @@ impl Helper {
|
|||
// Write the [sudo] password to STDIN.
|
||||
let mut stdin = child.stdin.take().unwrap();
|
||||
use std::io::Write;
|
||||
writeln!(stdin, "{}\n", sudo.lock().unwrap().pass);
|
||||
if let Err(e) = writeln!(stdin, "{}\n", sudo.lock().unwrap().pass) { error!("Sudo Kill | STDIN error: {}", e); }
|
||||
|
||||
// Return exit code of [sudo/kill].
|
||||
child.wait().unwrap().success()
|
||||
|
@ -644,7 +657,7 @@ impl Helper {
|
|||
helper.lock().unwrap().xmrig.lock().unwrap().signal = ProcessSignal::Restart;
|
||||
helper.lock().unwrap().xmrig.lock().unwrap().state = ProcessState::Middle;
|
||||
|
||||
let helper = Arc::clone(&helper);
|
||||
let helper = Arc::clone(helper);
|
||||
let state = state.clone();
|
||||
let path = path.clone();
|
||||
// This thread lives to wait, start xmrig then die.
|
||||
|
@ -704,7 +717,7 @@ impl Helper {
|
|||
let rig = if state.simple_rig.is_empty() { GUPAX_VERSION_UNDERSCORE.to_string() } else { state.simple_rig.clone() }; // Rig name
|
||||
args.push("--url".to_string()); args.push("127.0.0.1:3333".to_string()); // Local P2Pool (the default)
|
||||
args.push("--threads".to_string()); args.push(state.current_threads.to_string()); // Threads
|
||||
args.push("--user".to_string()); args.push(rig.clone()); // Rig name
|
||||
args.push("--user".to_string()); args.push(rig); // Rig name
|
||||
args.push("--no-color".to_string()); // No color
|
||||
args.push("--http-host".to_string()); args.push("127.0.0.1".to_string()); // HTTP API IP
|
||||
args.push("--http-port".to_string()); args.push("18088".to_string()); // HTTP API Port
|
||||
|
@ -782,7 +795,7 @@ impl Helper {
|
|||
// The XMRig watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works.
|
||||
// This isn't actually async, a tokio runtime is unfortunately needed because [Hyper] is an async library (HTTP API calls)
|
||||
#[tokio::main]
|
||||
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>>, api_ip_port: String) {
|
||||
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>, path: std::path::PathBuf, sudo: Arc<Mutex<SudoState>>, api_ip_port: String) {
|
||||
// 1a. Create PTY
|
||||
debug!("XMRig | Creating PTY...");
|
||||
let pty = portable_pty::native_pty_system();
|
||||
|
@ -808,7 +821,7 @@ impl Helper {
|
|||
// 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);
|
||||
if let Err(e) = writeln!(pair.master, "{}", sudo.lock().unwrap().pass) { error!("XMRig | Sudo STDIN error: {}", e); };
|
||||
SudoState::wipe(&sudo);
|
||||
}
|
||||
|
||||
|
@ -872,7 +885,7 @@ impl Helper {
|
|||
// If we're restarting, the next start will wipe it for us.
|
||||
if signal != ProcessSignal::Restart { SudoState::wipe(&sudo); }
|
||||
} else {
|
||||
child_pty.lock().unwrap().kill();
|
||||
if let Err(e) = child_pty.lock().unwrap().kill() { error!("XMRig Watchdog | Kill error: {}", e); }
|
||||
}
|
||||
let exit_status = match child_pty.lock().unwrap().wait() {
|
||||
Ok(e) => {
|
||||
|
@ -910,7 +923,7 @@ impl Helper {
|
|||
let input = std::mem::take(&mut lock.input);
|
||||
for line in input {
|
||||
debug!("XMRig Watchdog | User input not empty, writing to STDIN: [{}]", line);
|
||||
writeln!(lock.stdin.as_mut().unwrap(), "{}", line);
|
||||
if let Err(e) = writeln!(lock.stdin.as_mut().unwrap(), "{}", line) { error!("XMRig Watchdog | STDIN error: {}", e); };
|
||||
}
|
||||
}
|
||||
drop(lock);
|
||||
|
@ -951,7 +964,6 @@ impl Helper {
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- The "helper"
|
||||
fn update_pub_sys_from_sysinfo(sysinfo: &sysinfo::System, pub_sys: &mut Sys, pid: &sysinfo::Pid, helper: &Helper, max_threads: usize) {
|
||||
use sysinfo::{CpuExt,ProcessExt,NetworkExt,NetworksExt};
|
||||
let gupax_uptime = helper.uptime.to_string();
|
||||
let cpu = &sysinfo.cpus()[0];
|
||||
let gupax_cpu_usage = format!("{:.2}%", sysinfo.process(*pid).unwrap().cpu_usage()/(max_threads as f32));
|
||||
|
@ -977,7 +989,6 @@ impl Helper {
|
|||
system_cpu_usage,
|
||||
system_memory,
|
||||
system_cpu_model,
|
||||
..*pub_sys
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1083,11 +1094,6 @@ impl Helper {
|
|||
|
||||
// 5. End loop
|
||||
}
|
||||
|
||||
// 6. Something has gone terribly wrong if the helper exited this loop.
|
||||
let text = "HELPER THREAD HAS ESCAPED THE LOOP...!";
|
||||
error!("{}", text);error!("{}", text);error!("{}", text);panic!("{}", text);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1101,6 +1107,12 @@ use std::time::Duration;
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct HumanTime(Duration);
|
||||
|
||||
impl Default for HumanTime {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl HumanTime {
|
||||
pub fn new() -> HumanTime {
|
||||
HumanTime(ZERO_SECONDS)
|
||||
|
@ -1143,7 +1155,7 @@ impl std::fmt::Display for HumanTime {
|
|||
let minutes = day_secs % 3600 / 60;
|
||||
let seconds = day_secs % 60;
|
||||
|
||||
let ref mut started = false;
|
||||
let started = &mut false;
|
||||
Self::plural(f, started, "year", years)?;
|
||||
Self::plural(f, started, "month", months)?;
|
||||
Self::plural(f, started, "day", days)?;
|
||||
|
@ -1409,7 +1421,7 @@ impl PubP2poolApi {
|
|||
|
||||
// 2. Parse the full STDOUT
|
||||
let output = output.lock().unwrap();
|
||||
let (payouts, xmr) = Self::calc_payouts_and_xmr(&output, ®ex);
|
||||
let (payouts, xmr) = Self::calc_payouts_and_xmr(&output, regex);
|
||||
|
||||
// 3. Calculate hour/day/month given elapsed time
|
||||
let elapsed_as_secs_f64 = elapsed.as_secs_f64();
|
||||
|
@ -1632,9 +1644,9 @@ impl PrivXmrigApi {
|
|||
async fn request_xmrig_api(client: hyper::Client<hyper::client::HttpConnector>, api_ip_port: &str) -> Result<Self, anyhow::Error> {
|
||||
let request = hyper::Request::builder()
|
||||
.method("GET")
|
||||
.uri("http://".to_string() + api_ip_port + "/1/summary")
|
||||
.uri("http://".to_string() + api_ip_port + XMRIG_API_URI)
|
||||
.body(hyper::Body::empty())?;
|
||||
let mut response = tokio::time::timeout(std::time::Duration::from_millis(500), client.request(request)).await?;
|
||||
let response = tokio::time::timeout(std::time::Duration::from_millis(500), client.request(request)).await?;
|
||||
let body = hyper::body::to_bytes(response?.body_mut()).await?;
|
||||
Ok(serde_json::from_slice::<Self>(&body)?)
|
||||
}
|
||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -49,15 +49,8 @@ use std::{
|
|||
time::Instant,
|
||||
path::PathBuf,
|
||||
};
|
||||
// Sysinfo (this controls which info we get)
|
||||
use sysinfo::{
|
||||
NetworkExt,
|
||||
CpuExt,
|
||||
ProcessExt,
|
||||
System,
|
||||
SystemExt,
|
||||
PidExt,
|
||||
};
|
||||
// Sysinfo
|
||||
use sysinfo::SystemExt;
|
||||
// Modules
|
||||
mod ferris;
|
||||
mod constants;
|
||||
|
@ -468,6 +461,12 @@ pub struct ErrorState {
|
|||
buttons: ErrorButtons, // Which buttons to display?
|
||||
}
|
||||
|
||||
impl Default for ErrorState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ErrorState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -514,7 +513,7 @@ impl ErrorState {
|
|||
ferris: ErrorFerris::Sudo,
|
||||
buttons: ErrorButtons::Sudo,
|
||||
};
|
||||
SudoState::reset(&state)
|
||||
SudoState::reset(state)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -564,7 +563,7 @@ impl Regexes {
|
|||
|
||||
// Check if a Monero address is correct.
|
||||
pub fn addr_ok(&self, address: &str) -> bool {
|
||||
address.len() == 95 && Regex::is_match(&self.address, &address) && !address.contains('0') && !address.contains('O') && !address.contains('l')
|
||||
address.len() == 95 && Regex::is_match(&self.address, address) && !address.contains('0') && !address.contains('O') && !address.contains('l')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -728,13 +727,11 @@ fn init_auto(app: &mut App) {
|
|||
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 {
|
||||
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);
|
||||
}
|
||||
app.sudo.lock().unwrap().signal = ProcessSignal::Start;
|
||||
app.error_state.ask_sudo(&app.sudo);
|
||||
}
|
||||
} else {
|
||||
info!("Skipping auto-xmrig...");
|
||||
|
@ -917,7 +914,7 @@ impl eframe::App for App {
|
|||
|
||||
// If [F11] was pressed, reverse [fullscreen] bool
|
||||
let mut input = ctx.input_mut();
|
||||
let mut key: KeyPressed = {
|
||||
let key: KeyPressed = {
|
||||
if input.consume_key(Modifiers::NONE, Key::F11) {
|
||||
KeyPressed::F11
|
||||
} else if input.consume_key(Modifiers::NONE, Key::ArrowLeft) {
|
||||
|
@ -975,13 +972,13 @@ impl eframe::App for App {
|
|||
let p2pool = self.p2pool.lock().unwrap();
|
||||
let p2pool_is_alive = p2pool.is_alive();
|
||||
let p2pool_is_waiting = p2pool.is_waiting();
|
||||
let p2pool_state = p2pool.state;
|
||||
let p2pool_state = ProcessState::Alive;
|
||||
drop(p2pool);
|
||||
debug!("App | Locking and collecting XMRig state...");
|
||||
let xmrig = self.xmrig.lock().unwrap();
|
||||
let xmrig_is_alive = xmrig.is_alive();
|
||||
let xmrig_is_waiting = xmrig.is_waiting();
|
||||
let xmrig_state = xmrig.state;
|
||||
let xmrig_state = ProcessState::Alive;
|
||||
drop(xmrig);
|
||||
|
||||
// This sets the top level Ui dimensions.
|
||||
|
@ -1157,7 +1154,7 @@ impl eframe::App for App {
|
|||
let sudo_width = width/10.0;
|
||||
let height = ui.available_height()/4.0;
|
||||
let mut sudo = self.sudo.lock().unwrap();
|
||||
let hide = sudo.hide.clone();
|
||||
let hide = sudo.hide;
|
||||
ui.style_mut().override_text_style = Some(Monospace);
|
||||
if sudo.testing {
|
||||
ui.add_sized([width, height], Spinner::new().size(height));
|
||||
|
@ -1409,9 +1406,6 @@ impl eframe::App for App {
|
|||
if key.is_up() || ui.add_sized([width, height], Button::new("⟲")).on_hover_text("Restart XMRig").clicked() {
|
||||
if cfg!(windows) {
|
||||
Helper::restart_xmrig(&self.helper, &self.state.xmrig, &self.state.gupax.absolute_xmrig_path, Arc::clone(&self.sudo));
|
||||
} else if cfg!(target_os = "macos") {
|
||||
self.sudo.lock().unwrap().signal = ProcessSignal::Restart;
|
||||
self.error_state.ask_sudo(&self.sudo);
|
||||
} else {
|
||||
self.sudo.lock().unwrap().signal = ProcessSignal::Restart;
|
||||
self.error_state.ask_sudo(&self.sudo);
|
||||
|
@ -1493,7 +1487,6 @@ impl eframe::App for App {
|
|||
ui.add_sized([width, height], Hyperlink::from_label_and_url("Made by hinto-janaiyo".to_string(), "https://gupax.io"));
|
||||
ui.add_sized([width, height], Label::new("egui is licensed under MIT & Apache-2.0"));
|
||||
ui.add_sized([width, height], Label::new("Gupax, P2Pool, and XMRig are licensed under GPLv3"));
|
||||
if cfg!(debug_assertions) { ui.label(format!("Gupax is running in debug mode - {}", self.now.elapsed().as_secs_f64())); }
|
||||
});
|
||||
}
|
||||
Tab::Status => {
|
||||
|
|
16
src/node.rs
16
src/node.rs
|
@ -16,7 +16,6 @@
|
|||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
State,
|
||||
constants::*,
|
||||
};
|
||||
use serde::{Serialize,Deserialize};
|
||||
|
@ -197,6 +196,12 @@ pub struct Ping {
|
|||
pub auto_selected: bool,
|
||||
}
|
||||
|
||||
impl Default for Ping {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Ping {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -254,11 +259,8 @@ impl Ping {
|
|||
// default = GRAY
|
||||
#[tokio::main]
|
||||
pub async fn ping(ping: &Arc<Mutex<Self>>) -> Result<String, anyhow::Error> {
|
||||
// Timer
|
||||
let now = Instant::now();
|
||||
let ping = Arc::clone(ping);
|
||||
|
||||
// Start ping
|
||||
let ping = Arc::clone(ping);
|
||||
ping.lock().unwrap().pinging = true;
|
||||
ping.lock().unwrap().prog = 0.0;
|
||||
let percent = (100.0 / ((NODE_IPS.len()) as f32)).floor();
|
||||
|
@ -296,7 +298,7 @@ impl Ping {
|
|||
let node_vec = std::mem::take(&mut *node_vec.lock().unwrap());
|
||||
let fastest_info = format!("Fastest node: {}ms ... {} @ {}", node_vec[0].ms, node_vec[0].id, node_vec[0].ip);
|
||||
|
||||
let info = format!("Cleaning up connections");
|
||||
let info = "Cleaning up connections".to_string();
|
||||
info!("Ping | {}...", info);
|
||||
let mut ping = ping.lock().unwrap();
|
||||
ping.fastest = node_vec[0].id;
|
||||
|
@ -309,9 +311,9 @@ impl Ping {
|
|||
|
||||
async fn response(client: Client<HttpConnector>, request: Request<Body>, ip: &'static str, ping: Arc<Mutex<Self>>, percent: f32, node_vec: Arc<Mutex<Vec<NodeData>>>) {
|
||||
let id = ip_to_enum(ip);
|
||||
let now = Instant::now();
|
||||
let ms;
|
||||
let info;
|
||||
let now = Instant::now();
|
||||
match tokio::time::timeout(Duration::from_secs(5), client.request(request)).await {
|
||||
Ok(_) => {
|
||||
ms = now.elapsed().as_millis();
|
||||
|
|
|
@ -32,7 +32,7 @@ use regex::Regex;
|
|||
use log::*;
|
||||
|
||||
impl P2pool {
|
||||
pub fn show(&mut self, node_vec: &mut Vec<(String, Node)>, og: &Arc<Mutex<State>>, ping: &Arc<Mutex<Ping>>, regex: &Regexes, process: &Arc<Mutex<Process>>, api: &Arc<Mutex<PubP2poolApi>>, buffer: &mut String, width: f32, height: f32, ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
pub fn show(&mut self, node_vec: &mut Vec<(String, Node)>, _og: &Arc<Mutex<State>>, ping: &Arc<Mutex<Ping>>, regex: &Regexes, process: &Arc<Mutex<Process>>, api: &Arc<Mutex<PubP2poolApi>>, buffer: &mut String, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
let text_edit = height / 25.0;
|
||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
debug!("P2Pool Tab | Rendering [Console]");
|
||||
|
@ -63,7 +63,7 @@ impl P2pool {
|
|||
// If the user pressed enter, dump buffer contents into the process STDIN
|
||||
if response.lost_focus() && ui.input().key_pressed(egui::Key::Enter) {
|
||||
response.request_focus(); // Get focus back
|
||||
let mut buffer = std::mem::take(buffer); // Take buffer
|
||||
let buffer = std::mem::take(buffer); // Take buffer
|
||||
let mut process = process.lock().unwrap(); // Lock
|
||||
if process.is_alive() { process.input.push(buffer); } // Push only if alive
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl P2pool {
|
|||
if self.address.is_empty() {
|
||||
text = format!("Monero Address [{}/95] ➖", len);
|
||||
color = Color32::LIGHT_GRAY;
|
||||
} else if Regexes::addr_ok(®ex, &self.address) {
|
||||
} else if Regexes::addr_ok(regex, &self.address) {
|
||||
text = format!("Monero Address [{}/95] ✔", len);
|
||||
color = Color32::from_rgb(100, 230, 100);
|
||||
} else {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
Helper,
|
||||
PubP2poolApi,
|
||||
PubXmrigApi,
|
||||
ImgP2pool,
|
||||
|
@ -27,7 +26,6 @@ use crate::{
|
|||
use std::sync::{Arc,Mutex};
|
||||
use log::*;
|
||||
use egui::{
|
||||
containers::*,
|
||||
Label,RichText,TextStyle
|
||||
};
|
||||
|
||||
|
@ -36,7 +34,7 @@ use egui::{
|
|||
pub struct Status {}
|
||||
|
||||
impl Status {
|
||||
pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_api: &Arc<Mutex<PubXmrigApi>>, p2pool_img: &Arc<Mutex<ImgP2pool>>, xmrig_img: &Arc<Mutex<ImgXmrig>>, p2pool_alive: bool, xmrig_alive: bool, width: f32, height: f32, ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_api: &Arc<Mutex<PubXmrigApi>>, _p2pool_img: &Arc<Mutex<ImgP2pool>>, _xmrig_img: &Arc<Mutex<ImgXmrig>>, p2pool_alive: bool, xmrig_alive: bool, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
let width = (width/3.0)-(SPACE*1.666);
|
||||
let min_height = height/1.14;
|
||||
let height = height/25.0;
|
||||
|
@ -48,17 +46,17 @@ pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_
|
|||
ui.add_sized([width, height*2.0], Label::new(RichText::new("[Gupax]").color(LIGHT_GRAY).text_style(TextStyle::Name("MonospaceLarge".into())))).on_hover_text("Gupax is online");
|
||||
let sys = sys.lock().unwrap();
|
||||
ui.add_sized([width, height], Label::new(RichText::new("Uptime").underline().color(BONE))).on_hover_text(STATUS_GUPAX_UPTIME);
|
||||
ui.add_sized([width, height], Label::new(format!("{}", sys.gupax_uptime)));
|
||||
ui.add_sized([width, height], Label::new(sys.gupax_uptime.to_string()));
|
||||
ui.add_sized([width, height], Label::new(RichText::new("Gupax CPU").underline().color(BONE))).on_hover_text(STATUS_GUPAX_CPU_USAGE);
|
||||
ui.add_sized([width, height], Label::new(format!("{}", sys.gupax_cpu_usage)));
|
||||
ui.add_sized([width, height], Label::new(sys.gupax_cpu_usage.to_string()));
|
||||
ui.add_sized([width, height], Label::new(RichText::new("Gupax Memory").underline().color(BONE))).on_hover_text(STATUS_GUPAX_MEMORY_USAGE);
|
||||
ui.add_sized([width, height], Label::new(format!("{}", sys.gupax_memory_used_mb)));
|
||||
ui.add_sized([width, height], Label::new(sys.gupax_memory_used_mb.to_string()));
|
||||
ui.add_sized([width, height], Label::new(RichText::new("System CPU").underline().color(BONE))).on_hover_text(STATUS_GUPAX_SYSTEM_CPU_USAGE);
|
||||
ui.add_sized([width, height], Label::new(format!("{}", sys.system_cpu_usage)));
|
||||
ui.add_sized([width, height], Label::new(sys.system_cpu_usage.to_string()));
|
||||
ui.add_sized([width, height], Label::new(RichText::new("System Memory").underline().color(BONE))).on_hover_text(STATUS_GUPAX_SYSTEM_MEMORY);
|
||||
ui.add_sized([width, height], Label::new(format!("{}", sys.system_memory)));
|
||||
ui.add_sized([width, height], Label::new(sys.system_memory.to_string()));
|
||||
ui.add_sized([width, height], Label::new(RichText::new("System CPU Model").underline().color(BONE))).on_hover_text(STATUS_GUPAX_SYSTEM_CPU_MODEL);
|
||||
ui.add_sized([width, height], Label::new(format!("{}", sys.system_cpu_model)));
|
||||
ui.add_sized([width, height], Label::new(sys.system_cpu_model.to_string()));
|
||||
drop(sys);
|
||||
})});
|
||||
// [P2Pool]
|
||||
|
@ -104,7 +102,7 @@ pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_
|
|||
ui.add_sized([width, height], Label::new(RichText::new("Shares").underline().color(BONE))).on_hover_text(STATUS_XMRIG_SHARES);
|
||||
ui.add_sized([width, height], Label::new(format!("[Accepted: {}] [Rejected: {}]", api.accepted, api.rejected)));
|
||||
ui.add_sized([width, height], Label::new(RichText::new("Pool").underline().color(BONE))).on_hover_text(STATUS_XMRIG_POOL);
|
||||
ui.add_sized([width, height], Label::new(format!("{}", api.pool)));
|
||||
ui.add_sized([width, height], Label::new(api.pool.to_string()));
|
||||
drop(api);
|
||||
})});
|
||||
});
|
||||
|
|
10
src/sudo.rs
10
src/sudo.rs
|
@ -46,6 +46,12 @@ pub struct SudoState {
|
|||
pub signal: ProcessSignal, // Main GUI will set this depending on if we want [Start] or [Restart]
|
||||
}
|
||||
|
||||
impl Default for SudoState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl SudoState {
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn new() -> Self {
|
||||
|
@ -74,7 +80,7 @@ impl SudoState {
|
|||
|
||||
// Resets the state.
|
||||
pub fn reset(state: &Arc<Mutex<Self>>) {
|
||||
Self::wipe(&state);
|
||||
Self::wipe(state);
|
||||
let mut state = state.lock().unwrap();
|
||||
state.testing = false;
|
||||
state.success = false;
|
||||
|
@ -159,7 +165,7 @@ impl SudoState {
|
|||
},
|
||||
}
|
||||
}
|
||||
sudo.kill();
|
||||
if let Err(e) = sudo.kill() { error!("Sudo | Kill error: {}", e); }
|
||||
if state.lock().unwrap().success {
|
||||
match state.lock().unwrap().signal {
|
||||
ProcessSignal::Restart => crate::helper::Helper::restart_xmrig(&helper, &xmrig, &path, Arc::clone(&state)),
|
||||
|
|
|
@ -33,7 +33,7 @@ use regex::Regex;
|
|||
use log::*;
|
||||
|
||||
impl Xmrig {
|
||||
pub fn show(&mut self, pool_vec: &mut Vec<(String, Pool)>, regex: &Regexes, process: &Arc<Mutex<Process>>, api: &Arc<Mutex<PubXmrigApi>>, buffer: &mut String, width: f32, height: f32, ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
pub fn show(&mut self, pool_vec: &mut Vec<(String, Pool)>, regex: &Regexes, process: &Arc<Mutex<Process>>, api: &Arc<Mutex<PubXmrigApi>>, buffer: &mut String, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||
let text_edit = height / 25.0;
|
||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
debug!("XMRig Tab | Rendering [Console]");
|
||||
|
@ -64,7 +64,7 @@ impl Xmrig {
|
|||
// If the user pressed enter, dump buffer contents into the process STDIN
|
||||
if response.lost_focus() && ui.input().key_pressed(egui::Key::Enter) {
|
||||
response.request_focus(); // Get focus back
|
||||
let mut buffer = std::mem::take(buffer); // Take buffer
|
||||
let buffer = std::mem::take(buffer); // Take buffer
|
||||
let mut process = process.lock().unwrap(); // Lock
|
||||
if process.is_alive() { process.input.push(buffer); } // Push only if alive
|
||||
}
|
||||
|
@ -127,14 +127,12 @@ impl Xmrig {
|
|||
});
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Simple
|
||||
let height = ui.available_height();
|
||||
if self.simple {
|
||||
// ui.group(|ui|
|
||||
|
||||
// });
|
||||
} else {
|
||||
debug!("XMRig Tab | Rendering [Pool List] elements");
|
||||
// let _height = height / 10.0;
|
||||
let width = ui.available_width() - 10.0;
|
||||
let mut incorrect_input = false; // This will disable [Add/Delete] on bad input
|
||||
// [Pool IP/Port]
|
||||
|
|
Loading…
Reference in a new issue