diff --git a/pubsubman_gui/src/app.rs b/pubsubman_gui/src/app.rs index 5e315c9..b9b882f 100644 --- a/pubsubman_gui/src/app.rs +++ b/pubsubman_gui/src/app.rs @@ -246,12 +246,23 @@ impl App { }; } - fn render_close_dialog(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn render_close_dialog(&mut self, ctx: &egui::Context) { let cleanup_subscriptions = || { let sub_names = self.memory.subscriptions.values().cloned().collect(); delete_subscriptions(&self.front_tx, sub_names); }; - self.exit_state.show(ctx, frame, cleanup_subscriptions) + self.exit_state.show(ctx, cleanup_subscriptions) + } + + fn handle_exit(&mut self, frame: &mut eframe::Frame) { + if self.exit_state.can_exit { + for view in self.messages_views.values_mut() { + if let Some(cancel_token) = view.stream_messages_cancel_token.take() { + cancel_token.cancel(); + } + } + frame.close(); + } } } @@ -259,10 +270,11 @@ impl eframe::App for App { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { ctx.request_repaint(); self.handle_backend_message(); - self.render_close_dialog(ctx, frame); + self.render_close_dialog(ctx); self.render_top_panel(ctx, frame); self.render_topics_panel(ctx); self.render_central_panel(ctx); + self.handle_exit(frame); } fn save(&mut self, storage: &mut dyn eframe::Storage) { diff --git a/pubsubman_gui/src/exit_state.rs b/pubsubman_gui/src/exit_state.rs index b2a78c5..8f78226 100644 --- a/pubsubman_gui/src/exit_state.rs +++ b/pubsubman_gui/src/exit_state.rs @@ -3,7 +3,7 @@ use crate::ui::Modal; #[derive(Default)] pub struct ExitState { show_exit_dialogue: bool, - can_exit: bool, + pub can_exit: bool, pub subscription_cleanup_state: SubscriptionCleanupState, } @@ -23,12 +23,7 @@ const MARGIN: egui::Margin = egui::Margin { }; impl ExitState { - pub fn show( - &mut self, - ctx: &egui::Context, - frame: &mut eframe::Frame, - cleanup_subscriptions: impl FnOnce(), - ) { + pub fn show(&mut self, ctx: &egui::Context, cleanup_subscriptions: impl FnOnce()) { if !self.show_exit_dialogue { return; } @@ -46,14 +41,13 @@ impl ExitState { egui::Layout::top_down(egui::Align::Center), |ui| match self.subscription_cleanup_state { SubscriptionCleanupState::Idle => { - self.render_dialog_contents(ui, cleanup_subscriptions, frame); + self.render_dialog_contents(ui, cleanup_subscriptions); } SubscriptionCleanupState::Waiting => { ui.spinner(); } SubscriptionCleanupState::Complete => { self.can_exit = true; - frame.close(); } }, ) @@ -61,12 +55,7 @@ impl ExitState { }); } - fn render_dialog_contents( - &mut self, - ui: &mut egui::Ui, - cleanup_subscriptions: impl FnOnce(), - frame: &mut eframe::Frame, - ) { + fn render_dialog_contents(&mut self, ui: &mut egui::Ui, cleanup_subscriptions: impl FnOnce()) { ui.label( "Pubsubman created Subscriptions in order to receive messages. Do you want to delete these Subscriptions before you quit?", ); @@ -82,7 +71,6 @@ impl ExitState { if ui.button("Skip").clicked() { self.can_exit = true; - frame.close(); } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {