fix: donate amount lost between restarts

This commit is contained in:
mostafaei2002 2024-06-04 15:45:56 +03:30
parent 2259372482
commit d1fe73cc95
2 changed files with 8 additions and 2 deletions

View file

@ -526,10 +526,10 @@ impl App {
// Set saved Hero mode to runtime. // Set saved Hero mode to runtime.
app.xvb_api.lock().unwrap().stats_priv.runtime_mode = app.state.xvb.mode.clone().into(); app.xvb_api.lock().unwrap().stats_priv.runtime_mode = app.state.xvb.mode.clone().into();
app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = match app.state.xvb.amount.parse() { app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = match app.state.xvb.amount.parse::<u64>() {
Ok(n) => n, Ok(n) => n,
Err(_) => { Err(_) => {
warn!("Cannot parse [amount] to u64, defaulting to 0"); error!("Cannot parse [amount] to u64, defaulting to 0");
0 0
} }
}; };

View file

@ -401,9 +401,12 @@ impl PubXvbApi {
output.push_str(&buf); output.push_str(&buf);
} }
let runtime_mode = std::mem::take(&mut gui_api.stats_priv.runtime_mode); let runtime_mode = std::mem::take(&mut gui_api.stats_priv.runtime_mode);
let runtime_manual_amount = std::mem::take(&mut gui_api.stats_priv.runtime_manual_amount);
*gui_api = Self { *gui_api = Self {
output, output,
stats_priv: XvbPrivStats { stats_priv: XvbPrivStats {
runtime_manual_amount,
runtime_mode, runtime_mode,
..pub_api.stats_priv.clone() ..pub_api.stats_priv.clone()
}, },
@ -695,6 +698,8 @@ fn signal_interrupt(
fn reset_data_xvb(pub_api: &Arc<Mutex<PubXvbApi>>, gui_api: &Arc<Mutex<PubXvbApi>>) { fn reset_data_xvb(pub_api: &Arc<Mutex<PubXvbApi>>, gui_api: &Arc<Mutex<PubXvbApi>>) {
let current_node = mem::take(&mut lock!(pub_api).current_node.clone()); let current_node = mem::take(&mut lock!(pub_api).current_node.clone());
let runtime_mode = mem::take(&mut lock!(gui_api).stats_priv.runtime_mode); let runtime_mode = mem::take(&mut lock!(gui_api).stats_priv.runtime_mode);
let runtime_manual_amount = mem::take(&mut lock!(gui_api).stats_priv.runtime_manual_amount);
// let output = mem::take(&mut lock!(gui_api).output); // let output = mem::take(&mut lock!(gui_api).output);
*lock!(pub_api) = PubXvbApi::new(); *lock!(pub_api) = PubXvbApi::new();
*lock!(gui_api) = PubXvbApi::new(); *lock!(gui_api) = PubXvbApi::new();
@ -702,6 +707,7 @@ fn reset_data_xvb(pub_api: &Arc<Mutex<PubXvbApi>>, gui_api: &Arc<Mutex<PubXvbApi
lock!(pub_api).current_node = current_node; lock!(pub_api).current_node = current_node;
// to not loose the information of runtime hero mode between restart // to not loose the information of runtime hero mode between restart
lock!(gui_api).stats_priv.runtime_mode = runtime_mode; lock!(gui_api).stats_priv.runtime_mode = runtime_mode;
lock!(gui_api).stats_priv.runtime_manual_amount = runtime_manual_amount;
// message while starting must be preserved. // message while starting must be preserved.
// lock!(pub_api).output = output; // lock!(pub_api).output = output;
} }