mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2025-01-08 23:19:26 +00:00
fix: custom start options bugfix and better responsiveness
This commit is contained in:
parent
1e4b1347aa
commit
61f67fff4f
9 changed files with 102 additions and 72 deletions
|
@ -17,7 +17,7 @@
|
|||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use egui::{Button, TextEdit, TextStyle, TextWrapMode, Ui};
|
||||
use egui::{Button, ScrollArea, TextEdit, TextStyle, TextWrapMode, Ui};
|
||||
|
||||
use crate::{
|
||||
DARK_GRAY,
|
||||
|
@ -100,38 +100,43 @@ pub fn start_options_field(
|
|||
ui.add(
|
||||
TextEdit::multiline(arguments)
|
||||
.hint_text(hint)
|
||||
.desired_rows(1),
|
||||
.desired_rows(1)
|
||||
.desired_width(ui.available_width()),
|
||||
)
|
||||
.on_hover_text(hover);
|
||||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add_enabled(
|
||||
default_args_simple != arguments,
|
||||
Button::new(" Reset to Simple options "),
|
||||
)
|
||||
.on_hover_text("Reset the start options to arguments used for simple mode")
|
||||
.clicked()
|
||||
{
|
||||
*arguments = default_args_simple.to_string();
|
||||
}
|
||||
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
|
||||
|
||||
if ui
|
||||
.add_enabled(
|
||||
default_args_advanced != arguments,
|
||||
Button::new("Reset to Advanced options"),
|
||||
)
|
||||
.on_hover_text("Reset the start options to arguments used for advanced mode")
|
||||
.clicked()
|
||||
{
|
||||
*arguments = default_args_advanced.to_string();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(!arguments.is_empty(), Button::new("Clear"))
|
||||
.on_hover_text("Clear custom start options to use the advanced settings")
|
||||
.clicked()
|
||||
{
|
||||
*arguments = String::new();
|
||||
}
|
||||
ScrollArea::horizontal().show(ui, |ui| {
|
||||
if ui
|
||||
.add_enabled(
|
||||
default_args_simple != arguments,
|
||||
Button::new(" Reset to Simple options "),
|
||||
)
|
||||
.on_hover_text("Reset the start options to arguments used for simple mode")
|
||||
.clicked()
|
||||
{
|
||||
*arguments = default_args_simple.to_string();
|
||||
}
|
||||
|
||||
if ui
|
||||
.add_enabled(
|
||||
default_args_advanced != arguments,
|
||||
Button::new("Reset to Advanced options"),
|
||||
)
|
||||
.on_hover_text("Reset the start options to arguments used for advanced mode")
|
||||
.clicked()
|
||||
{
|
||||
*arguments = default_args_advanced.to_string();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(!arguments.is_empty(), Button::new("Clear"))
|
||||
.on_hover_text("Clear custom start options to use the advanced settings")
|
||||
.clicked()
|
||||
{
|
||||
*arguments = String::new();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -126,7 +126,6 @@ impl crate::app::App {
|
|||
&mut self.xmrig_stdin,
|
||||
ctx,
|
||||
ui,
|
||||
&self.state.gupax.absolute_xmrig_path,
|
||||
);
|
||||
}
|
||||
Tab::XmrigProxy => {
|
||||
|
|
|
@ -30,7 +30,6 @@ use crate::regex::REGEXES;
|
|||
use egui::{Checkbox, Ui, vec2};
|
||||
use log::*;
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::common::list_poolnode::PoolNode;
|
||||
|
@ -47,7 +46,6 @@ impl Xmrig {
|
|||
buffer: &mut String,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui,
|
||||
path: &Path,
|
||||
) {
|
||||
header_tab(
|
||||
ui,
|
||||
|
@ -74,8 +72,8 @@ impl Xmrig {
|
|||
});
|
||||
if !self.simple {
|
||||
debug!("XMRig Tab | Rendering [Arguments]");
|
||||
let default_args_simple = self.start_options(path, StartOptionsMode::Simple);
|
||||
let default_args_advanced = self.start_options(path, StartOptionsMode::Advanced);
|
||||
let default_args_simple = self.start_options(StartOptionsMode::Simple);
|
||||
let default_args_advanced = self.start_options(StartOptionsMode::Advanced);
|
||||
start_options_field(
|
||||
ui,
|
||||
&mut self.arguments,
|
||||
|
|
|
@ -73,9 +73,6 @@ impl XmrigProxy {
|
|||
}
|
||||
});
|
||||
if !self.simple {
|
||||
if !self.arguments.is_empty() {
|
||||
ui.disable();
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------- Arguments
|
||||
debug!("XMRig-Proxy Tab | Rendering [Arguments]");
|
||||
let default_args_simple = self.start_options(StartOptionsMode::Simple);
|
||||
|
|
|
@ -749,8 +749,8 @@ impl Xmrig {
|
|||
pub const fn process_name() -> ProcessName {
|
||||
ProcessName::Xmrig
|
||||
}
|
||||
pub fn start_options(&self, path: &Path, mode: StartOptionsMode) -> String {
|
||||
Helper::build_xmrig_args(self, path, mode).join(" ")
|
||||
pub fn start_options(&self, mode: StartOptionsMode) -> String {
|
||||
Helper::build_xmrig_args(self, mode).join(" ")
|
||||
}
|
||||
}
|
||||
impl XmrigProxy {
|
||||
|
|
|
@ -490,7 +490,10 @@ impl Helper {
|
|||
}
|
||||
StartOptionsMode::Custom => {
|
||||
// Overriding command arguments
|
||||
args.push(state.arguments.split_whitespace().collect());
|
||||
for arg in state.arguments.split_whitespace() {
|
||||
let arg = if arg == "localhost" { "127.0.0.1" } else { arg };
|
||||
args.push(arg.to_string());
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use crate::disk::state::StartOptionsMode;
|
||||
use crate::helper::xrig::xmrig_proxy::PubXmrigProxyApi;
|
||||
use crate::helper::xvb::algorithm::Algorithm;
|
||||
use crate::helper::{
|
||||
|
@ -556,6 +557,7 @@ Uptime = 0h 2m 4s
|
|||
assert_eq!(data_after_ser, json)
|
||||
}
|
||||
|
||||
use std::path::Path;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
|
@ -823,4 +825,29 @@ Uptime = 0h 2m 4s
|
|||
|
||||
assert_eq!(algo.stats.target_donation_hashrate, 20000.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_args_p2pool() {
|
||||
// check that custom args are parsed correctly.
|
||||
let arguments = "--wallet 4A5Dwt2qKwKEQrZfo4aBkSNtvDDAzSFbAJcyFkdW5RwDh9U4WgeZrgKT4hUoE2gv8h6NmsNMTyjsEL8eSLMbABds5rYFWnw --host node2.monerodevs.org --rpc-port 18089 --zmq-port 18084 --data-api /home/lm/Téléchargements/gupaxx-v1.5.4-rc3-linux-x64-bundle/p2pool --local-api --no-color --mini --light-mode".to_string();
|
||||
let state = P2pool {
|
||||
simple: false,
|
||||
arguments: arguments.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
let args = Helper::build_p2pool_args(
|
||||
&state,
|
||||
Path::new(""),
|
||||
&None,
|
||||
false,
|
||||
StartOptionsMode::Custom,
|
||||
);
|
||||
assert_eq!(
|
||||
arguments
|
||||
.split(" ")
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>(),
|
||||
args
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ impl Helper {
|
|||
} else {
|
||||
StartOptionsMode::Advanced
|
||||
};
|
||||
let args = Self::build_xmrig_args(state, path, mode);
|
||||
let args = Self::build_xmrig_args(state, mode);
|
||||
// Print arguments & user settings to console
|
||||
crate::disk::print_dash(&format!("XMRig | Launch arguments: {:#?}", args));
|
||||
info!("XMRig | Using path: [{}]", path.display());
|
||||
|
@ -286,20 +286,24 @@ impl Helper {
|
|||
// It returns a value... and mutates a deeply nested passed argument... this is some pretty bad code...
|
||||
pub fn build_xmrig_args(
|
||||
state: &crate::disk::state::Xmrig,
|
||||
path: &std::path::Path,
|
||||
// Allows to provide a different mode without mutating the state
|
||||
mode: StartOptionsMode,
|
||||
) -> Vec<String> {
|
||||
let mut args = Vec::with_capacity(500);
|
||||
let path = path.to_path_buf();
|
||||
// The actual binary we're executing is [sudo], technically
|
||||
// the XMRig path is just an argument to sudo, so add it.
|
||||
// Before that though, add the ["--prompt"] flag and set it
|
||||
// to emptiness so that it doesn't show up in the output.
|
||||
if cfg!(unix) {
|
||||
args.push(r#"--prompt="#.to_string());
|
||||
args.push("--".to_string());
|
||||
args.push(path.display().to_string());
|
||||
// some args needs to be added to both simple/advanced
|
||||
match mode {
|
||||
StartOptionsMode::Simple | StartOptionsMode::Advanced => {
|
||||
args.push("--no-color".to_string()); // No color escape codes
|
||||
args.push(format!("--http-access-token={}", state.token)); // HTTP API Port
|
||||
args.push("--http-no-restricted".to_string());
|
||||
args.push("--threads".to_string());
|
||||
args.push(state.current_threads.to_string()); // Threads
|
||||
if state.pause != 0 {
|
||||
args.push("--pause-on-active".to_string());
|
||||
args.push(state.pause.to_string());
|
||||
} // Pause on active
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
match mode {
|
||||
StartOptionsMode::Simple => {
|
||||
|
@ -311,19 +315,12 @@ impl Helper {
|
|||
}; // 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); // 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
|
||||
if state.pause != 0 {
|
||||
args.push("--pause-on-active".to_string());
|
||||
args.push(state.pause.to_string());
|
||||
} // Pause on active
|
||||
}
|
||||
StartOptionsMode::Advanced => {
|
||||
// XMRig doesn't understand [localhost]
|
||||
|
@ -345,8 +342,6 @@ impl Helper {
|
|||
let url = format!("{}:{}", ip, state.port); // Combine IP:Port into one string
|
||||
args.push("--user".to_string());
|
||||
args.push(state.address.clone()); // Wallet
|
||||
args.push("--threads".to_string());
|
||||
args.push(state.current_threads.to_string()); // Threads
|
||||
args.push("--rig-id".to_string());
|
||||
args.push(state.rig.to_string()); // Rig ID
|
||||
args.push("--url".to_string());
|
||||
|
@ -355,17 +350,12 @@ impl Helper {
|
|||
args.push(api_ip.to_string()); // HTTP API IP
|
||||
args.push("--http-port".to_string());
|
||||
args.push(api_port.to_string()); // HTTP API Port
|
||||
args.push("--no-color".to_string()); // No color escape codes
|
||||
if state.tls {
|
||||
args.push("--tls".to_string());
|
||||
} // TLS
|
||||
if state.keepalive {
|
||||
args.push("--keepalive".to_string());
|
||||
} // Keepalive
|
||||
if state.pause != 0 {
|
||||
args.push("--pause-on-active".to_string());
|
||||
args.push(state.pause.to_string());
|
||||
} // Pause on active
|
||||
}
|
||||
StartOptionsMode::Custom => {
|
||||
// This parses the input and attempts to fill out
|
||||
|
@ -378,8 +368,6 @@ impl Helper {
|
|||
}
|
||||
}
|
||||
}
|
||||
args.push(format!("--http-access-token={}", state.token)); // HTTP API Port
|
||||
args.push("--http-no-restricted".to_string());
|
||||
args
|
||||
}
|
||||
|
||||
|
@ -412,7 +400,7 @@ impl Helper {
|
|||
process: Arc<Mutex<Process>>,
|
||||
gui_api: Arc<Mutex<PubXmrigApi>>,
|
||||
pub_api: Arc<Mutex<PubXmrigApi>>,
|
||||
args: Vec<String>,
|
||||
mut args: Vec<String>,
|
||||
path: std::path::PathBuf,
|
||||
sudo: Arc<Mutex<SudoState>>,
|
||||
mut api_ip_port: String,
|
||||
|
@ -422,6 +410,15 @@ impl Helper {
|
|||
process_p2pool: Arc<Mutex<Process>>,
|
||||
pub_api_xvb: &Arc<Mutex<PubXvbApi>>,
|
||||
) {
|
||||
// The actual binary we're executing is [sudo], technically
|
||||
// the XMRig path is just an argument to sudo, so add it.
|
||||
// Before that though, add the ["--prompt"] flag and set it
|
||||
// to emptiness so that it doesn't show up in the output.
|
||||
if cfg!(unix) {
|
||||
args.splice(..0, vec![path.display().to_string()]);
|
||||
args.splice(..0, vec![r#"--"#.to_string()]);
|
||||
args.splice(..0, vec![r#"--prompt="#.to_string()]);
|
||||
}
|
||||
// 1a. Create PTY
|
||||
debug!("XMRig | Creating PTY...");
|
||||
let pty = portable_pty::native_pty_system();
|
||||
|
|
|
@ -135,6 +135,14 @@ impl Helper {
|
|||
let api_port;
|
||||
let ip;
|
||||
let port;
|
||||
match mode {
|
||||
StartOptionsMode::Simple | StartOptionsMode::Advanced => {
|
||||
args.push(format!("--http-access-token={}", state.token)); // HTTP API Port
|
||||
args.push("--http-no-restricted".to_string());
|
||||
args.push("--no-color".to_string()); // No color
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
match mode {
|
||||
StartOptionsMode::Simple => {
|
||||
// Build the xmrig argument
|
||||
|
@ -149,7 +157,6 @@ impl Helper {
|
|||
args.push("0.0.0.0:3355".to_string());
|
||||
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());
|
||||
|
@ -197,7 +204,6 @@ impl Helper {
|
|||
args.push(api_ip.to_string()); // HTTP API IP
|
||||
args.push("--http-port".to_string());
|
||||
args.push(api_port.to_string()); // HTTP API Port
|
||||
args.push("--no-color".to_string()); // No color escape codes
|
||||
if state.tls {
|
||||
args.push("--tls".to_string());
|
||||
} // TLS
|
||||
|
@ -212,8 +218,6 @@ impl Helper {
|
|||
}
|
||||
}
|
||||
}
|
||||
args.push(format!("--http-access-token={}", state.token)); // HTTP API Port
|
||||
args.push("--http-no-restricted".to_string());
|
||||
args
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue