diff --git a/src/main.rs b/src/main.rs
index 34de8cd..a86fa6f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -261,6 +261,58 @@ fn init_options() -> NativeOptions {
options
}
+fn init_auto(app: &App) {
+ info!("Starting init_auto()...");
+ // [Auto-Update]
+ if app.state.gupax.auto_update {
+ let path_p2pool = app.og.lock().unwrap().gupax.absolute_p2pool_path.display().to_string();
+ let path_xmrig = app.og.lock().unwrap().gupax.absolute_xmrig_path.display().to_string();
+ let tor = app.og.lock().unwrap().gupax.update_via_tor;
+ app.update.lock().unwrap().path_p2pool = path_p2pool;
+ app.update.lock().unwrap().path_xmrig = path_xmrig;
+ app.update.lock().unwrap().tor = tor;
+ let og = Arc::clone(&app.og);
+ let og_ver = Arc::clone(&app.og.lock().unwrap().version);
+ let state_ver = Arc::clone(&app.state.version);
+ let update = Arc::clone(&app.update);
+ let update_thread = Arc::clone(&app.update);
+ thread::spawn(move|| {
+ info!("Spawning update thread...");
+ match Update::start(update_thread, og_ver.clone(), state_ver.clone()) {
+ Err(e) => {
+ info!("Update ... FAIL ... {}", e);
+ *update.lock().unwrap().msg.lock().unwrap() = format!("{} | {}", MSG_FAILED, e);
+ },
+ _ => {
+ info!("Update | Saving state...");
+ match State::save(&mut og.lock().unwrap()) {
+ Ok(_) => info!("Update ... OK"),
+ Err(e) => {
+ warn!("Update | Saving state ... FAIL ... {}", e);
+ *update.lock().unwrap().msg.lock().unwrap() = format!("Saving new versions into state failed");
+ },
+ };
+ }
+ };
+ *update.lock().unwrap().updating.lock().unwrap() = false;
+ });
+ } else {
+ info!("Skipping auto-update...");
+ }
+
+ // [Auto-Ping]
+ if app.og.lock().unwrap().p2pool.auto_node {
+ let ping = Arc::clone(&app.ping);
+ let og = Arc::clone(&app.og);
+ thread::spawn(move|| {
+ info!("Spawning ping thread...");
+ crate::node::ping(ping, og);
+ });
+ } else {
+ info!("Skipping auto-ping...");
+ }
+}
+
//---------------------------------------------------------------------------------------------------- Misc functions
fn parse_args(mut app: App) -> App {
info!("Parsing CLI arguments...");
@@ -381,6 +433,7 @@ fn main() {
}
let app = App::new();
let name = app.name_version.clone();
+ init_auto(&app);
eframe::run_native(&name, options, Box::new(|cc| Box::new(App::cc(cc, app))),);
}
diff --git a/src/node.rs b/src/node.rs
index c2d5b06..8a2625a 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
+use crate::State;
use serde::{Serialize,Deserialize};
use std::time::{Instant,Duration};
use std::collections::HashMap;
@@ -214,7 +215,7 @@ pub fn format_enum(id: NodeEnum) -> String {
// timeout = BLACK
// default = GRAY
use crate::NodeEnum::*;
-pub fn ping(ping: Arc>) -> PingResult {
+pub fn ping(ping: Arc>, og: Arc>) {
// Start ping
ping.lock().unwrap().pinging = true;
ping.lock().unwrap().prog = 0.0;
@@ -320,10 +321,15 @@ pub fn ping(ping: Arc>) -> PingResult {
let info = format!("Fastest node: {}ms ... {} @ {}", best_ms, fastest, enum_to_ip(fastest));
let percent = (100.0 - ping.lock().unwrap().prog) / 2.0;
info!("Ping | {}", info);
+ ping.lock().unwrap().nodes = nodes;
+ ping.lock().unwrap().fastest = fastest;
ping.lock().unwrap().prog = 100.0;
ping.lock().unwrap().msg = info;
ping.lock().unwrap().pinging = false;
ping.lock().unwrap().pinged = true;
+ if og.lock().unwrap().p2pool.auto_select {
+ og.lock().unwrap().p2pool.node = fastest;
+ og.lock().unwrap().save();
+ }
info!("Ping ... OK");
- PingResult { nodes, fastest }
}
diff --git a/src/p2pool.rs b/src/p2pool.rs
index 9ddf7c5..eb3c966 100644
--- a/src/p2pool.rs
+++ b/src/p2pool.rs
@@ -89,17 +89,10 @@ impl P2pool {
ui.set_enabled(!ping.lock().unwrap().pinging);
if ui.add_sized([width, height], Button::new("Ping community nodes")).on_hover_text(P2POOL_PING).clicked() {
let ping = Arc::clone(&ping);
- let og_clone = Arc::clone(og);
- ping.lock().unwrap().pinging = true;
+ let og = Arc::clone(og);
thread::spawn(move|| {
info!("Spawning ping thread...");
- let ping_result = crate::node::ping(ping.clone());
- ping.lock().unwrap().nodes = ping_result.nodes;
- ping.lock().unwrap().fastest = ping_result.fastest;
- if og_clone.lock().unwrap().p2pool.auto_select {
- og_clone.lock().unwrap().p2pool.node = ping_result.fastest;
- og_clone.lock().unwrap().save();
- }
+ crate::node::ping(ping, og);
});
}});
@@ -125,7 +118,7 @@ impl P2pool {
ui.group(|ui| {
ui.horizontal(|ui| {
- let width = (width/2.0)-(SPACE*1.5);
+ let width = (width/2.0)-(SPACE*1.75);
// [Auto-node] + [Auto-select]
let mut style = (*ctx.style()).clone();
style.spacing.icon_width_inner = height/1.5;
@@ -140,23 +133,18 @@ impl P2pool {
// [Address]
let height = ui.available_height();
ui.horizontal(|ui| {
- let width = width / 100.0;
- ui.add_sized([width*6.0, height], Label::new("Address"));
if self.address.is_empty() {
- ui.add_sized([width, height], Label::new(RichText::new("➖").color(Color32::LIGHT_GRAY)));
+ ui.add_sized([width, text_edit], Label::new(RichText::new("Monero Payout Address ➖").color(Color32::LIGHT_GRAY)));
} else if self.address.len() == 95 && Regex::is_match(addr_regex, &self.address) {
- ui.add_sized([width, height], Label::new(RichText::new("✔").color(Color32::from_rgb(100, 230, 100))));
+ ui.add_sized([width, text_edit], Label::new(RichText::new("Monero Payout Address ✔").color(Color32::from_rgb(100, 230, 100))));
} else {
- ui.add_sized([width, height], Label::new(RichText::new("❌").color(Color32::from_rgb(230, 50, 50))));
+ ui.add_sized([width, text_edit], Label::new(RichText::new("Monero Payout Address ❌").color(Color32::from_rgb(230, 50, 50))));
}
- ui.spacing_mut().text_edit_width = (width*9.0)-(SPACE*2.5);
- ui.style_mut().override_text_style = Some(Monospace);
- ui.add_sized([ui.available_width(), text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4...")).on_hover_text(P2POOL_ADDRESS);
});
-// ui.horizontal(|ui| {
-// ui.add_sized([width, height/2.0], Label::new("Address:"));
-// ui.add_sized([width, height], TextEdit::multiline(&mut self.address));
-// })});
+ ui.spacing_mut().text_edit_width = (width)-(SPACE*3.0);
+ ui.style_mut().override_text_style = Some(Monospace);
+ ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4...")).on_hover_text(P2POOL_ADDRESS);
+
// [Advanced]
} else {
// TODO: