main/update: add [Restart] state, set name to yellow if updated

This commit is contained in:
hinto-janaiyo 2022-11-27 15:11:00 -05:00
parent b85dcd908d
commit 9576a94498
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
3 changed files with 39 additions and 14 deletions

View file

@ -28,6 +28,7 @@ use crate::{
disk::Gupax, disk::Gupax,
update::*, update::*,
ErrorState, ErrorState,
Restart,
}; };
use std::{ use std::{
thread, thread,
@ -78,7 +79,7 @@ pub enum Ratio {
//---------------------------------------------------------------------------------------------------- Gupax //---------------------------------------------------------------------------------------------------- Gupax
impl Gupax { impl Gupax {
pub fn show(&mut self, og: &Arc<Mutex<State>>, state_path: &Path, update: &Arc<Mutex<Update>>, file_window: &Arc<Mutex<FileWindow>>, error_state: &mut ErrorState, width: f32, height: f32, frame: &mut eframe::Frame, ctx: &egui::Context, ui: &mut egui::Ui) { pub fn show(&mut self, og: &Arc<Mutex<State>>, state_path: &Path, update: &Arc<Mutex<Update>>, file_window: &Arc<Mutex<FileWindow>>, error_state: &mut ErrorState, restart: &Arc<Mutex<Restart>>, width: f32, height: f32, frame: &mut eframe::Frame, ctx: &egui::Context, ui: &mut egui::Ui) {
// Update button + Progress bar // Update button + Progress bar
ui.group(|ui| { ui.group(|ui| {
// These are in unnecessary [ui.vertical()]'s // These are in unnecessary [ui.vertical()]'s
@ -91,7 +92,7 @@ impl Gupax {
ui.vertical(|ui| { ui.vertical(|ui| {
ui.set_enabled(!updating); ui.set_enabled(!updating);
if ui.add_sized([width, height], Button::new("Check for updates")).on_hover_text(GUPAX_UPDATE).clicked() { if ui.add_sized([width, height], Button::new("Check for updates")).on_hover_text(GUPAX_UPDATE).clicked() {
Update::spawn_thread(og, &self, state_path, update, error_state); Update::spawn_thread(og, &self, state_path, update, error_state, restart);
} }
}); });
ui.vertical(|ui| { ui.vertical(|ui| {

View file

@ -88,6 +88,10 @@ pub struct App {
og_pool_vec: Vec<(String, Pool)>, // Manual Pool database og_pool_vec: Vec<(String, Pool)>, // Manual Pool database
pool_vec: Vec<(String, Pool)>, // Manual Pool database pool_vec: Vec<(String, Pool)>, // Manual Pool database
diff: bool, // This bool indicates state changes diff: bool, // This bool indicates state changes
// Restart state:
// If Gupax updated itself, this represents that the
// user should (but isn't required to) restart Gupax.
restart: Arc<Mutex<Restart>>,
// Error State // Error State
// These values are essentially global variables that // These values are essentially global variables that
// indicate if an error message needs to be displayed // indicate if an error message needs to be displayed
@ -143,6 +147,7 @@ impl App {
node_vec: Node::new_vec(), node_vec: Node::new_vec(),
og_pool_vec: Pool::new_vec(), og_pool_vec: Pool::new_vec(),
pool_vec: Pool::new_vec(), pool_vec: Pool::new_vec(),
restart: Arc::new(Mutex::new(Restart::No)),
diff: false, diff: false,
error_state: ErrorState::new(), error_state: ErrorState::new(),
p2pool: false, p2pool: false,
@ -313,6 +318,13 @@ impl Default for Tab {
} }
} }
//---------------------------------------------------------------------------------------------------- [Restart] Enum
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Restart {
No, // We don't need to restart
Yes, // We updated, user should probably (but isn't required to) restart
}
//---------------------------------------------------------------------------------------------------- [ErrorState] struct //---------------------------------------------------------------------------------------------------- [ErrorState] struct
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ErrorButtons { pub enum ErrorButtons {
@ -492,7 +504,7 @@ fn init_auto(app: &mut App) {
// [Auto-Update] // [Auto-Update]
if app.state.gupax.auto_update { if app.state.gupax.auto_update {
Update::spawn_thread(&app.og, &app.state.gupax, &app.state_path, &app.update, &mut app.error_state); Update::spawn_thread(&app.og, &app.state.gupax, &app.state_path, &app.update, &mut app.error_state, &app.restart);
} else { } else {
info!("Skipping auto-update..."); info!("Skipping auto-update...");
} }
@ -860,22 +872,28 @@ impl eframe::App for App {
ui.style_mut().override_text_style = Some(Name("Bottom".into())); ui.style_mut().override_text_style = Some(Name("Bottom".into()));
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.group(|ui| { ui.group(|ui| {
// [Gupax Version] + [OS] + [P2Pool on/off] + [XMRig on/off]
let width = ((self.width/2.0)/4.0)-(SPACE*2.0); let width = ((self.width/2.0)/4.0)-(SPACE*2.0);
ui.add_sized([width, height], Label::new(&*self.name_version)); // [Gupax Version]
// Is yellow if the user updated and should (but isn't required to) restart.
match *self.restart.lock().unwrap() {
Restart::Yes => ui.add_sized([width, height], Label::new(RichText::new(&self.name_version).color(YELLOW))).on_hover_text("Gupax was updated. A restart is recommended but not required."),
_ => ui.add_sized([width, height], Label::new(&self.name_version)).on_hover_text("Gupax is up-to-date"),
};
ui.separator(); ui.separator();
// [OS]
ui.add_sized([width, height], Label::new(self.os)); ui.add_sized([width, height], Label::new(self.os));
ui.separator(); ui.separator();
// [P2Pool/XMRig] Status
if self.p2pool { if self.p2pool {
ui.add_sized([width, height], Label::new(RichText::new("P2Pool ⏺").color(GREEN))); ui.add_sized([width, height], Label::new(RichText::new("P2Pool ⏺").color(GREEN))).on_hover_text("P2Pool is online");
} else { } else {
ui.add_sized([width, height], Label::new(RichText::new("P2Pool ⏺").color(RED))); ui.add_sized([width, height], Label::new(RichText::new("P2Pool ⏺").color(RED))).on_hover_text("P2Pool is offline");
} }
ui.separator(); ui.separator();
if self.xmrig { if self.xmrig {
ui.add_sized([width, height], Label::new(RichText::new("XMRig ⏺").color(GREEN))); ui.add_sized([width, height], Label::new(RichText::new("XMRig ⏺").color(GREEN))).on_hover_text("XMRig is online");
} else { } else {
ui.add_sized([width, height], Label::new(RichText::new("XMRig ⏺").color(RED))); ui.add_sized([width, height], Label::new(RichText::new("XMRig ⏺").color(RED))).on_hover_text("XMRig is offline");
} }
}); });
@ -1026,7 +1044,7 @@ impl eframe::App for App {
Status::show(self, self.width, self.height, ctx, ui); Status::show(self, self.width, self.height, ctx, ui);
} }
Tab::Gupax => { Tab::Gupax => {
Gupax::show(&mut self.state.gupax, &self.og, &self.state_path, &self.update, &self.file_window, &mut self.error_state, self.width, self.height, frame, ctx, ui); 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 => { Tab::P2pool => {
P2pool::show(&mut self.state.p2pool, &mut self.node_vec, &self.og, self.p2pool, &self.ping, &self.regex, self.width, self.height, ctx, ui); P2pool::show(&mut self.state.p2pool, &mut self.node_vec, &self.og, self.p2pool, &self.ping, &self.regex, self.width, self.height, ctx, ui);

View file

@ -32,6 +32,7 @@ use crate::{
disk::*, disk::*,
update::Name::*, update::Name::*,
ErrorState,ErrorFerris,ErrorButtons, ErrorState,ErrorFerris,ErrorButtons,
Restart,
}; };
use hyper::{ use hyper::{
Client,Body,Request, Client,Body,Request,
@ -265,7 +266,7 @@ impl Update {
// actually contains the code. This is so that everytime // actually contains the code. This is so that everytime
// an update needs to happen (Gupax tab, auto-update), the // an update needs to happen (Gupax tab, auto-update), the
// code only needs to be edited once, here. // code only needs to be edited once, here.
pub fn spawn_thread(og: &Arc<Mutex<State>>, gupax: &crate::disk::Gupax, state_path: &Path, update: &Arc<Mutex<Update>>, error_state: &mut ErrorState) { pub fn spawn_thread(og: &Arc<Mutex<State>>, gupax: &crate::disk::Gupax, state_path: &Path, update: &Arc<Mutex<Update>>, error_state: &mut ErrorState, restart: &Arc<Mutex<Restart>>) {
// Check P2Pool path for safety // Check P2Pool path for safety
// Attempt relative to absolute path // Attempt relative to absolute path
let p2pool_path = match into_absolute_path(gupax.p2pool_path.clone()) { let p2pool_path = match into_absolute_path(gupax.p2pool_path.clone()) {
@ -329,9 +330,10 @@ impl Update {
let state_ver = Arc::clone(&og.lock().unwrap().version); let state_ver = Arc::clone(&og.lock().unwrap().version);
let state_path = state_path.to_path_buf(); let state_path = state_path.to_path_buf();
let update = Arc::clone(update); let update = Arc::clone(update);
let restart = Arc::clone(restart);
std::thread::spawn(move|| { std::thread::spawn(move|| {
info!("Spawning update thread..."); info!("Spawning update thread...");
match Update::start(update.clone(), og.clone(), state_ver.clone()) { match Update::start(update.clone(), og.clone(), state_ver.clone(), restart) {
Ok(_) => { Ok(_) => {
info!("Update | Saving state..."); info!("Update | Saving state...");
let original_version = og.lock().unwrap().version.clone(); let original_version = og.lock().unwrap().version.clone();
@ -362,7 +364,7 @@ impl Update {
// 4. loop over vec, download links // 4. loop over vec, download links
// 5. extract, upgrade // 5. extract, upgrade
#[tokio::main] #[tokio::main]
pub async fn start(update: Arc<Mutex<Self>>, _og: Arc<Mutex<State>>, state_ver: Arc<Mutex<Version>>) -> Result<(), anyhow::Error> { pub async fn start(update: Arc<Mutex<Self>>, _og: Arc<Mutex<State>>, state_ver: Arc<Mutex<Version>>, restart: Arc<Mutex<Restart>>) -> Result<(), anyhow::Error> {
//---------------------------------------------------------------------------------------------------- Init //---------------------------------------------------------------------------------------------------- Init
*update.lock().unwrap().updating.lock().unwrap() = true; *update.lock().unwrap().updating.lock().unwrap() = true;
// Set timer // Set timer
@ -658,7 +660,11 @@ impl Update {
} }
std::fs::rename(entry.path(), path)?; std::fs::rename(entry.path(), path)?;
match name { match name {
Gupax => state_ver.lock().unwrap().gupax = Pkg::get_new_pkg_version(Gupax, &vec4)?, Gupax => {
state_ver.lock().unwrap().gupax = Pkg::get_new_pkg_version(Gupax, &vec4)?;
// If we're updating Gupax, set the [Restart] state so that the user knows to restart
*restart.lock().unwrap() = Restart::Yes;
},
P2pool => state_ver.lock().unwrap().p2pool = Pkg::get_new_pkg_version(P2pool, &vec4)?, P2pool => state_ver.lock().unwrap().p2pool = Pkg::get_new_pkg_version(P2pool, &vec4)?,
Xmrig => state_ver.lock().unwrap().xmrig = Pkg::get_new_pkg_version(Xmrig, &vec4)?, Xmrig => state_ver.lock().unwrap().xmrig = Pkg::get_new_pkg_version(Xmrig, &vec4)?,
}; };