diff --git a/src/globals.rs b/src/globals.rs index 451e85a4..2155a46a 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -47,6 +47,10 @@ pub struct Globals { /// Whether or not we have a saved private key and need the password to unlock it pub need_password: AtomicBool, + /// Whether or not we are shutting down. For the UI (minions will be signaled and + /// waited for by the overlord) + pub shutting_down: AtomicBool, + /// Settings pub settings: Mutex, } @@ -71,6 +75,7 @@ lazy_static! { desired_events: Mutex::new(HashMap::new()), people: Mutex::new(HashMap::new()), need_password: AtomicBool::new(false), + shutting_down: AtomicBool::new(false), settings: Mutex::new(Settings::default()), } }; diff --git a/src/main.rs b/src/main.rs index d64c01dd..88f138b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,10 +70,10 @@ async fn tokio_main() { // Any task can call this to shutdown pub fn initiate_shutdown() -> Result<(), Error> { let to_overlord = GLOBALS.to_overlord.clone(); - to_overlord.send(BusMessage { + let _ = to_overlord.send(BusMessage { target: "all".to_string(), kind: "shutdown".to_string(), json_payload: serde_json::to_string("").unwrap(), - })?; + }); // ignore errors Ok(()) } diff --git a/src/overlord/mod.rs b/src/overlord/mod.rs index aa71527b..00194d6f 100644 --- a/src/overlord/mod.rs +++ b/src/overlord/mod.rs @@ -43,6 +43,10 @@ impl Overlord { error!("{}", e); } + GLOBALS + .shutting_down + .store(true, std::sync::atomic::Ordering::Relaxed); + // Send shutdown message to all minions (and ui) // If this fails, it's probably because there are no more listeners // so just ignore it and keep shutting down. diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 8206e53e..d5e577cf 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -118,6 +118,13 @@ impl GossipUi { impl eframe::App for GossipUi { fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) { + if GLOBALS + .shutting_down + .load(std::sync::atomic::Ordering::Relaxed) + { + frame.close(); + } + let darkmode: bool = ctx.style().visuals.dark_mode; egui::TopBottomPanel::top("menu").show(ctx, |ui| {