mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 03:33:53 +00:00
Method for overlord to tell ui to shut down
This commit is contained in:
parent
9f5f9b1a46
commit
af3f2f8258
@ -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<Settings>,
|
||||
}
|
||||
@ -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()),
|
||||
}
|
||||
};
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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| {
|
||||
|
Loading…
Reference in New Issue
Block a user