Skip to content

Commit

Permalink
Extracted actual frame close to app. Cancelling remaining streaming t…
Browse files Browse the repository at this point in the history
…okens before exit.
  • Loading branch information
dmackdev committed Aug 7, 2023
1 parent 500a481 commit 60a6d6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 15 additions & 3 deletions pubsubman_gui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,35 @@ 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();
}
}
}

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) {
Expand Down
20 changes: 4 additions & 16 deletions pubsubman_gui/src/exit_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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;
}
Expand All @@ -46,27 +41,21 @@ 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();
}
},
)
});
});
}

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?",
);
Expand All @@ -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| {
Expand Down

0 comments on commit 60a6d6a

Please sign in to comment.