diff --git a/src/app/panels/middle/p2pool/simple.rs b/src/app/panels/middle/p2pool/simple.rs index 82404e8..5167970 100644 --- a/src/app/panels/middle/p2pool/simple.rs +++ b/src/app/panels/middle/p2pool/simple.rs @@ -33,10 +33,20 @@ impl P2pool { // Two atomic bools = enough to represent this data // local or remote + // button bool + ui.vertical_centered(|ui|{ + ui.add_space(space_h); + ui.checkbox(&mut self.local_node, "Use a local node").on_hover_text("If checked (recommended), p2pool will automatically use the local node.\nCheck the Node tab to start a local node.\nIf unchecked, p2pool will attempt to use a remote node."); + }); + ui.add_space(space_h * 2.0); + + // if checked, use only local node + // if unchecked, show remote nodes. // disable remote if local is checked. + let visible = !self.local_node; debug!("P2Pool Tab | Running [auto-select] check"); - if self.auto_select { + if self.auto_select && visible { let mut ping = lock!(ping); // If we haven't auto_selected yet, auto-select and turn it off if ping.pinged && !ping.auto_selected { @@ -46,142 +56,147 @@ impl P2pool { drop(ping); } - ui.vertical(|ui| { - ui.horizontal(|ui| { - debug!("P2Pool Tab | Rendering [Ping List]"); - // [Ping List] - let mut ms = 0; - let mut color = Color32::LIGHT_GRAY; - if lock!(ping).pinged { - for data in lock!(ping).nodes.iter() { - if data.ip == self.node { - ms = data.ms; - color = data.color; - break; + ui.add_enabled_ui(visible, |ui| { + ui.vertical(|ui| { + ui.horizontal(|ui| { + debug!("P2Pool Tab | Rendering [Ping List]"); + // [Ping List] + let mut ms = 0; + let mut color = Color32::LIGHT_GRAY; + if lock!(ping).pinged { + for data in lock!(ping).nodes.iter() { + if data.ip == self.node { + ms = data.ms; + color = data.color; + break; + } } } - } - debug!("P2Pool Tab | Rendering [ComboBox] of Remote Nodes"); - let ip_location = format_ip_location(&self.node, false); - let text = RichText::new(format!(" ⏺ {}ms | {}", ms, ip_location)).color(color); - ComboBox::from_id_salt("remote_nodes") - .selected_text(text) - .width(size.x) - .show_ui(ui, |ui| { - for data in lock!(ping).nodes.iter() { - let ms = format_ms(data.ms); - let ip_location = format_ip_location(data.ip, true); - let text = RichText::new(format!(" ⏺ {} | {}", ms, ip_location)) - .color(data.color); - ui.selectable_value(&mut self.node, data.ip.to_string(), text); - } - }); - }); + debug!("P2Pool Tab | Rendering [ComboBox] of Remote Nodes"); + let ip_location = format_ip_location(&self.node, false); + let text = RichText::new(format!(" ⏺ {}ms | {}", ms, ip_location)).color(color); + ComboBox::from_id_salt("remote_nodes") + .selected_text(text) + .width(size.x) + .show_ui(ui, |ui| { + for data in lock!(ping).nodes.iter() { + let ms = format_ms(data.ms); + let ip_location = format_ip_location(data.ip, true); + let text = RichText::new(format!(" ⏺ {} | {}", ms, ip_location)) + .color(data.color); + ui.selectable_value(&mut self.node, data.ip.to_string(), text); + } + }); + }); - ui.add_space(space_h); + ui.add_space(space_h); - debug!("P2Pool Tab | Rendering [Select fastest ... Ping] buttons"); - ui.horizontal(|ui| { - let width = ((size.x / 5.0) - 6.0).max(0.0); - let size = vec2(width, height); - // [Select random node] - if ui - .add_sized(size, Button::new("Select random node")) - .on_hover_text(P2POOL_SELECT_RANDOM) - .clicked() - { - self.node = RemoteNode::get_random(&self.node); - } - // [Select fastest node] - if ui - .add_sized(size, Button::new("Select fastest node")) - .on_hover_text(P2POOL_SELECT_FASTEST) - .clicked() - && lock!(ping).pinged - { - self.node = lock!(ping).fastest.to_string(); - } - // [Ping Button] - ui.add_enabled_ui(!lock!(ping).pinging, |ui| { + debug!("P2Pool Tab | Rendering [Select fastest ... Ping] buttons"); + ui.horizontal(|ui| { + let width = ((size.x / 5.0) - 6.0).max(0.0); + let size = vec2(width, height); + // [Select random node] if ui - .add_sized(size, Button::new("Ping remote nodes")) - .on_hover_text(P2POOL_PING) + .add_sized(size, Button::new("Select random node")) + .on_hover_text(P2POOL_SELECT_RANDOM) .clicked() { - Ping::spawn_thread(ping); + self.node = RemoteNode::get_random(&self.node); + } + // [Select fastest node] + if ui + .add_sized(size, Button::new("Select fastest node")) + .on_hover_text(P2POOL_SELECT_FASTEST) + .clicked() + && lock!(ping).pinged + { + self.node = lock!(ping).fastest.to_string(); + } + // [Ping Button] + ui.add_enabled_ui(!lock!(ping).pinging, |ui| { + if ui + .add_sized(size, Button::new("Ping remote nodes")) + .on_hover_text(P2POOL_PING) + .clicked() + { + Ping::spawn_thread(ping); + } + }); + // [Last <-] + if ui + .add_sized(size, Button::new("⬅ Last")) + .on_hover_text(P2POOL_SELECT_LAST) + .clicked() + { + let ping = lock!(ping); + match ping.pinged { + true => { + self.node = RemoteNode::get_last_from_ping(&self.node, &ping.nodes) + } + false => self.node = RemoteNode::get_last(&self.node), + } + drop(ping); + } + // [Next ->] + if ui + .add_sized(size, Button::new("Next ➡")) + .on_hover_text(P2POOL_SELECT_NEXT) + .clicked() + { + let ping = lock!(ping); + match ping.pinged { + true => { + self.node = RemoteNode::get_next_from_ping(&self.node, &ping.nodes) + } + false => self.node = RemoteNode::get_next(&self.node), + } + drop(ping); } }); - // [Last <-] - if ui - .add_sized(size, Button::new("⬅ Last")) - .on_hover_text(P2POOL_SELECT_LAST) - .clicked() - { - let ping = lock!(ping); - match ping.pinged { - true => self.node = RemoteNode::get_last_from_ping(&self.node, &ping.nodes), - false => self.node = RemoteNode::get_last(&self.node), - } - drop(ping); - } - // [Next ->] - if ui - .add_sized(size, Button::new("Next ➡")) - .on_hover_text(P2POOL_SELECT_NEXT) - .clicked() - { - let ping = lock!(ping); - match ping.pinged { - true => self.node = RemoteNode::get_next_from_ping(&self.node, &ping.nodes), - false => self.node = RemoteNode::get_next(&self.node), - } - drop(ping); - } - }); - ui.vertical(|ui| { - let height = height / 2.0; - let pinging = lock!(ping).pinging; - ui.add_enabled_ui(pinging, |ui| { - let prog = lock!(ping).prog.round(); - let msg = RichText::new(format!("{} ... {}%", lock!(ping).msg, prog)); - let height = height / 1.25; - let size = vec2(size.x, height); - ui.add_space(space_h); - ui.add_sized(size, Label::new(msg)); - ui.add_space(space_h); - if pinging { - ui.add_sized(size, Spinner::new().size(height)); - } else { - ui.add_sized(size, Label::new("...")); - } - ui.add_sized(size, ProgressBar::new(prog.round() / 100.0)); - ui.add_space(space_h); + ui.vertical(|ui| { + let height = height / 2.0; + let pinging = lock!(ping).pinging; + ui.add_enabled_ui(pinging, |ui| { + let prog = lock!(ping).prog.round(); + let msg = RichText::new(format!("{} ... {}%", lock!(ping).msg, prog)); + let height = height / 1.25; + let size = vec2(size.x, height); + ui.add_space(space_h); + ui.add_sized(size, Label::new(msg)); + ui.add_space(space_h); + if pinging { + ui.add_sized(size, Spinner::new().size(height)); + } else { + ui.add_sized(size, Label::new("...")); + } + ui.add_sized(size, ProgressBar::new(prog.round() / 100.0)); + ui.add_space(space_h); + }); }); }); - }); - debug!("P2Pool Tab | Rendering [Auto-*] buttons"); - ui.group(|ui| { - ui.horizontal(|ui| { - let width = ((size.x / 3.0) - (SPACE * 1.75)).max(0.0); - let size = vec2(width, height); - // [Auto-node] - ui.add_sized(size, Checkbox::new(&mut self.auto_select, "Auto-select")) - .on_hover_text(P2POOL_AUTO_SELECT); - ui.separator(); - // [Auto-node] - ui.add_sized(size, Checkbox::new(&mut self.auto_ping, "Auto-ping")) - .on_hover_text(P2POOL_AUTO_NODE); - ui.separator(); - // [Backup host] - ui.add_sized(size, Checkbox::new(&mut self.backup_host, "Backup host")) - .on_hover_text(P2POOL_BACKUP_HOST_SIMPLE); - }) - }); + debug!("P2Pool Tab | Rendering [Auto-*] buttons"); + ui.group(|ui| { + ui.horizontal(|ui| { + let width = ((size.x / 3.0) - (SPACE * 1.75)).max(0.0); + let size = vec2(width, height); + // [Auto-node] + ui.add_sized(size, Checkbox::new(&mut self.auto_select, "Auto-select")) + .on_hover_text(P2POOL_AUTO_SELECT); + ui.separator(); + // [Auto-node] + ui.add_sized(size, Checkbox::new(&mut self.auto_ping, "Auto-ping")) + .on_hover_text(P2POOL_AUTO_NODE); + ui.separator(); + // [Backup host] + ui.add_sized(size, Checkbox::new(&mut self.backup_host, "Backup host")) + .on_hover_text(P2POOL_BACKUP_HOST_SIMPLE); + }) + }); - debug!("P2Pool Tab | Rendering warning text"); - ui.add_sized( + debug!("P2Pool Tab | Rendering warning text"); + ui.add_sized( [size.x, height / 2.0], Hyperlink::from_label_and_url( "WARNING: It is recommended to run/use your own Monero Node (hover for details)", @@ -189,5 +204,6 @@ impl P2pool { ), ) .on_hover_text(P2POOL_COMMUNITY_NODE_WARNING); + }); } } diff --git a/src/disk/state.rs b/src/disk/state.rs index c2771fa..258fd9e 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -209,6 +209,7 @@ pub struct Gupax { #[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)] pub struct P2pool { pub simple: bool, + pub local_node: bool, pub mini: bool, pub auto_ping: bool, pub auto_select: bool, @@ -487,6 +488,7 @@ impl Default for P2pool { fn default() -> Self { Self { simple: true, + local_node: true, mini: true, auto_ping: true, auto_select: true,