From 33089ddca301684f84902de8dc8767b36dd9c685 Mon Sep 17 00:00:00 2001 From: hinto-janaiyo Date: Tue, 6 Dec 2022 21:13:37 -0500 Subject: [PATCH] p2pool/app: add STDIN + clear at 56million bytes, 4:3 default ratio --- src/constants.rs | 12 ++++++------ src/gupax.rs | 7 ++++--- src/helper.rs | 22 ++++++++++++++++++++++ src/main.rs | 11 ++++++++++- src/p2pool.rs | 18 ++++++++++++------ 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index dd73109..37439b0 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -20,14 +20,14 @@ pub const P2POOL_VERSION: &str = "v2.4"; pub const XMRIG_VERSION: &str = "v6.18.0"; pub const COMMIT: &str = include_str!("../.git/refs/heads/main"); -// App frame resolution, [16:10] aspect ratio, height = width * 1.6 -pub const APP_MIN_WIDTH: f32 = 768.0; +// App frame resolution, [4:3] aspect ratio, [1.33:1] +pub const APP_MIN_WIDTH: f32 = 640.0; pub const APP_MIN_HEIGHT: f32 = 480.0; -pub const APP_MAX_WIDTH: f32 = 3456.0; -pub const APP_MAX_HEIGHT: f32 = 2160.0; -// Default, 1280x800 +pub const APP_MAX_WIDTH: f32 = 2560.0; +pub const APP_MAX_HEIGHT: f32 = 1920.0; +// Default, 1280x960 pub const APP_DEFAULT_WIDTH: f32 = 1280.0; -pub const APP_DEFAULT_HEIGHT: f32 = 800.0; +pub const APP_DEFAULT_HEIGHT: f32 = 960.0; // Use macOS shaped icon for macOS #[cfg(target_os = "macos")] diff --git a/src/gupax.rs b/src/gupax.rs index 2049fac..e8baba2 100644 --- a/src/gupax.rs +++ b/src/gupax.rs @@ -17,6 +17,7 @@ use crate::State; use egui::{ + TextEdit, TextStyle::Monospace, Checkbox,ProgressBar,Spinner,Button,Label,Slider, SelectableLabel, @@ -130,7 +131,7 @@ impl Gupax { // P2Pool/XMRig binary path selection ui.add_space(SPACE); ui.style_mut().override_text_style = Some(Monospace); - let height = height/20.0; + let height = height/28.0; let text_edit = (ui.available_width()/10.0)-SPACE; ui.horizontal(|ui| { if self.p2pool_path.is_empty() { @@ -152,7 +153,7 @@ impl Gupax { if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() { Self::spawn_file_window_thread(file_window, FileType::P2pool); } - ui.text_edit_singleline(&mut self.p2pool_path).on_hover_text(GUPAX_PATH_P2POOL); + ui.add_sized([ui.available_width()-SPACE, height], TextEdit::hint_text(TextEdit::singleline(&mut self.p2pool_path), GUPAX_PATH_P2POOL)); }); ui.horizontal(|ui| { if self.xmrig_path.is_empty() { @@ -174,7 +175,7 @@ impl Gupax { if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() { Self::spawn_file_window_thread(file_window, FileType::Xmrig); } - ui.text_edit_singleline(&mut self.xmrig_path).on_hover_text(GUPAX_PATH_XMRIG); + ui.add_sized([ui.available_width()-SPACE, height], TextEdit::hint_text(TextEdit::singleline(&mut self.xmrig_path), GUPAX_PATH_XMRIG)); }); let mut guard = file_window.lock().unwrap(); if guard.picked_p2pool { self.p2pool_path = guard.p2pool_path.clone(); guard.picked_p2pool = false; } diff --git a/src/helper.rs b/src/helper.rs index 00e8e2c..8481c64 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -205,6 +205,23 @@ impl Helper { } } + // Reset output if larger than 55_999_000 bytes (around 1 week of logs). + // The actual [String] holds 56_000_000, but this allows for some leeway so it doesn't allocate more memory. + // This will also append a message showing it was reset. + fn check_reset_output(output: &Arc>, name: ProcessName) { + let mut output = output.lock().unwrap(); + if output.len() > 55_999_000 { + let name = match name { + ProcessName::P2pool => "P2Pool", + ProcessName::Xmrig => "XMRig", + }; + info!("{} | Output is nearing 56,000,000 bytes, resetting!", name); + let text = format!("{}\n{} logs are exceeding the maximum: 56,000,000 bytes!\nI've reset the logs for you, your stats may now be inaccurate since they depend on these logs!\nI think you rather have that than have it hogging your memory, though!\n{}", HORI_CONSOLE, name, HORI_CONSOLE); + output.clear(); + output.push_str(&text); + } + } + //---------------------------------------------------------------------------------------------------- P2Pool specific // Read P2Pool's API file. fn read_p2pool_api(path: &std::path::PathBuf) -> Result { @@ -419,6 +436,7 @@ impl Helper { writeln!(pub_api.lock().unwrap().output, "{}\nP2Pool stopped | Uptime: [{}] | Exit status: [{}]\n{}\n\n", HORI_CONSOLE, uptime, exit_status, HORI_CONSOLE); process.lock().unwrap().signal = ProcessSignal::None; break + // Check RESTART } else if process.lock().unwrap().signal == ProcessSignal::Restart { child_pty.lock().unwrap().kill(); // This actually sends a SIGHUP to p2pool (closes the PTY, hangs up on p2pool) // Wait to get the exit status @@ -468,6 +486,9 @@ impl Helper { } } + // Check if logs need resetting + Self::check_reset_output(&output, ProcessName::P2pool); + // Sleep (only if 900ms hasn't passed) let elapsed = now.elapsed().as_millis(); // Since logic goes off if less than 1000, casting should be safe @@ -526,6 +547,7 @@ impl Helper { pub fn spawn_helper(helper: &Arc>) { let mut helper = Arc::clone(helper); thread::spawn(move || { + info!("Helper | Hello from helper thread! Entering loop where I will spend the rest of my days..."); // Begin loop loop { // 1. Loop init timestamp diff --git a/src/main.rs b/src/main.rs index cac8295..1cff40b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,6 +111,8 @@ pub struct App { xmrig_api: Arc>, // Public ready-to-print XMRig API made by the "helper" thread p2pool_img: Arc>, // A one-time snapshot of what data P2Pool started with xmrig_img: Arc>, // A one-time snapshot of what data XMRig started with + // Buffer State + p2pool_console: String, // The buffer between the p2pool console and the [Helper] // State from [--flags] no_startup: bool, // Static stuff @@ -171,6 +173,7 @@ impl App { xmrig_api, p2pool_img, xmrig_img, + p2pool_console: String::with_capacity(10), resizing: false, alpha: 0, no_startup: false, @@ -320,6 +323,12 @@ impl App { app.tab = app.state.gupax.tab; drop(og); // Unlock [og] info!("App ... OK"); + + // Spawn the "Helper" thread. + info!("Helper | Spawning helper thread..."); + Helper::spawn_helper(&app.helper); + info!("Helper ... OK"); + app } } @@ -1126,7 +1135,7 @@ impl eframe::App for App { Gupax::show(&mut self.state.gupax, &self.og, &self.state_path, &self.update, &self.file_window, &mut self.error_state, &self.restart, self.width, self.height, frame, ctx, ui); } Tab::P2pool => { - P2pool::show(&mut self.state.p2pool, &mut self.node_vec, &self.og, &self.ping, &self.regex, &self.helper, &self.p2pool_api, self.width, self.height, ctx, ui); + P2pool::show(&mut self.state.p2pool, &mut self.node_vec, &self.og, &self.ping, &self.regex, &self.p2pool, &self.p2pool_api, &mut self.p2pool_console, self.width, self.height, ctx, ui); } Tab::Xmrig => { Xmrig::show(&mut self.state.xmrig, &mut self.pool_vec, &self.regex, self.width, self.height, ctx, ui); diff --git a/src/p2pool.rs b/src/p2pool.rs index 6787b4d..ce944b5 100644 --- a/src/p2pool.rs +++ b/src/p2pool.rs @@ -32,8 +32,8 @@ use regex::Regex; use log::*; impl P2pool { - pub fn show(&mut self, node_vec: &mut Vec<(String, Node)>, og: &Arc>, ping: &Arc>, regex: &Regexes, helper: &Arc>, api: &Arc>, width: f32, height: f32, ctx: &egui::Context, ui: &mut egui::Ui) { - let text_edit = height / 22.0; + pub fn show(&mut self, node_vec: &mut Vec<(String, Node)>, og: &Arc>, ping: &Arc>, regex: &Regexes, process: &Arc>, api: &Arc>, buffer: &mut String, width: f32, height: f32, ctx: &egui::Context, ui: &mut egui::Ui) { + let text_edit = height / 25.0; //---------------------------------------------------------------------------------------------------- [Simple] Console if self.simple { ui.group(|ui| { @@ -51,7 +51,7 @@ impl P2pool { //---------------------------------------------------------------------------------------------------- [Advanced] Console } else { ui.group(|ui| { - let height = height / 3.0; + let height = height / 2.8; let width = width - SPACE; ui.style_mut().override_text_style = Some(Monospace); egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| { @@ -61,7 +61,14 @@ impl P2pool { }); }); ui.separator(); - ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut "".to_string()), r#"Type a command (e.g "help" or "status") and press Enter"#)); + let response = ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(buffer), r#"Type a command (e.g "help" or "status") and press Enter"#)); + // 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 mut process = process.lock().unwrap(); // Lock + if process.is_alive() { process.input.push(buffer); } // Push only if alive + } }); } @@ -414,7 +421,7 @@ impl P2pool { // [Main/Mini] ui.horizontal(|ui| { - let height = height/3.0; + let height = height/4.0; ui.group(|ui| { ui.horizontal(|ui| { let width = (width/4.0)-SPACE; let height = height + 6.0; @@ -429,7 +436,6 @@ impl P2pool { ui.style_mut().spacing.slider_width = width/1.2; ui.style_mut().spacing.interact_size.y = height; ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into())); -// ui.style_mut().override_text_style = Some(Monospace); ui.horizontal(|ui| { ui.add_sized([text, height], Label::new("Out peers [10-450]:")); ui.add_sized([width, height], Slider::new(&mut self.out_peers, 10..=450)).on_hover_text(P2POOL_OUT);