mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 14:49:21 +00:00
add [init_auto()] for auto-* options
This commit is contained in:
parent
9638f9dc5b
commit
3f4124622c
3 changed files with 71 additions and 24 deletions
53
src/main.rs
53
src/main.rs
|
@ -261,6 +261,58 @@ fn init_options() -> NativeOptions {
|
||||||
options
|
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
|
//---------------------------------------------------------------------------------------------------- Misc functions
|
||||||
fn parse_args(mut app: App) -> App {
|
fn parse_args(mut app: App) -> App {
|
||||||
info!("Parsing CLI arguments...");
|
info!("Parsing CLI arguments...");
|
||||||
|
@ -381,6 +433,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
let app = App::new();
|
let app = App::new();
|
||||||
let name = app.name_version.clone();
|
let name = app.name_version.clone();
|
||||||
|
init_auto(&app);
|
||||||
eframe::run_native(&name, options, Box::new(|cc| Box::new(App::cc(cc, app))),);
|
eframe::run_native(&name, options, Box::new(|cc| Box::new(App::cc(cc, app))),);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/node.rs
10
src/node.rs
|
@ -15,6 +15,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use crate::State;
|
||||||
use serde::{Serialize,Deserialize};
|
use serde::{Serialize,Deserialize};
|
||||||
use std::time::{Instant,Duration};
|
use std::time::{Instant,Duration};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -214,7 +215,7 @@ pub fn format_enum(id: NodeEnum) -> String {
|
||||||
// timeout = BLACK
|
// timeout = BLACK
|
||||||
// default = GRAY
|
// default = GRAY
|
||||||
use crate::NodeEnum::*;
|
use crate::NodeEnum::*;
|
||||||
pub fn ping(ping: Arc<Mutex<Ping>>) -> PingResult {
|
pub fn ping(ping: Arc<Mutex<Ping>>, og: Arc<Mutex<State>>) {
|
||||||
// Start ping
|
// Start ping
|
||||||
ping.lock().unwrap().pinging = true;
|
ping.lock().unwrap().pinging = true;
|
||||||
ping.lock().unwrap().prog = 0.0;
|
ping.lock().unwrap().prog = 0.0;
|
||||||
|
@ -320,10 +321,15 @@ pub fn ping(ping: Arc<Mutex<Ping>>) -> PingResult {
|
||||||
let info = format!("Fastest node: {}ms ... {} @ {}", best_ms, fastest, enum_to_ip(fastest));
|
let info = format!("Fastest node: {}ms ... {} @ {}", best_ms, fastest, enum_to_ip(fastest));
|
||||||
let percent = (100.0 - ping.lock().unwrap().prog) / 2.0;
|
let percent = (100.0 - ping.lock().unwrap().prog) / 2.0;
|
||||||
info!("Ping | {}", info);
|
info!("Ping | {}", info);
|
||||||
|
ping.lock().unwrap().nodes = nodes;
|
||||||
|
ping.lock().unwrap().fastest = fastest;
|
||||||
ping.lock().unwrap().prog = 100.0;
|
ping.lock().unwrap().prog = 100.0;
|
||||||
ping.lock().unwrap().msg = info;
|
ping.lock().unwrap().msg = info;
|
||||||
ping.lock().unwrap().pinging = false;
|
ping.lock().unwrap().pinging = false;
|
||||||
ping.lock().unwrap().pinged = true;
|
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");
|
info!("Ping ... OK");
|
||||||
PingResult { nodes, fastest }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,17 +89,10 @@ impl P2pool {
|
||||||
ui.set_enabled(!ping.lock().unwrap().pinging);
|
ui.set_enabled(!ping.lock().unwrap().pinging);
|
||||||
if ui.add_sized([width, height], Button::new("Ping community nodes")).on_hover_text(P2POOL_PING).clicked() {
|
if ui.add_sized([width, height], Button::new("Ping community nodes")).on_hover_text(P2POOL_PING).clicked() {
|
||||||
let ping = Arc::clone(&ping);
|
let ping = Arc::clone(&ping);
|
||||||
let og_clone = Arc::clone(og);
|
let og = Arc::clone(og);
|
||||||
ping.lock().unwrap().pinging = true;
|
|
||||||
thread::spawn(move|| {
|
thread::spawn(move|| {
|
||||||
info!("Spawning ping thread...");
|
info!("Spawning ping thread...");
|
||||||
let ping_result = crate::node::ping(ping.clone());
|
crate::node::ping(ping, og);
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
@ -125,7 +118,7 @@ impl P2pool {
|
||||||
|
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let width = (width/2.0)-(SPACE*1.5);
|
let width = (width/2.0)-(SPACE*1.75);
|
||||||
// [Auto-node] + [Auto-select]
|
// [Auto-node] + [Auto-select]
|
||||||
let mut style = (*ctx.style()).clone();
|
let mut style = (*ctx.style()).clone();
|
||||||
style.spacing.icon_width_inner = height/1.5;
|
style.spacing.icon_width_inner = height/1.5;
|
||||||
|
@ -140,23 +133,18 @@ impl P2pool {
|
||||||
// [Address]
|
// [Address]
|
||||||
let height = ui.available_height();
|
let height = ui.available_height();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let width = width / 100.0;
|
|
||||||
ui.add_sized([width*6.0, height], Label::new("Address"));
|
|
||||||
if self.address.is_empty() {
|
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) {
|
} 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 {
|
} 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.spacing_mut().text_edit_width = (width)-(SPACE*3.0);
|
||||||
// ui.add_sized([width, height/2.0], Label::new("Address:"));
|
ui.style_mut().override_text_style = Some(Monospace);
|
||||||
// ui.add_sized([width, height], TextEdit::multiline(&mut self.address));
|
ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4...")).on_hover_text(P2POOL_ADDRESS);
|
||||||
// })});
|
|
||||||
// [Advanced]
|
// [Advanced]
|
||||||
} else {
|
} else {
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
Loading…
Reference in a new issue