Skip to content

Commit a3bbf6d

Browse files
committed
chore: reuse toast
1 parent df6d8dd commit a3bbf6d

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

nxshell/src/app.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub struct NxShell {
6666
pub clipboard: ClipboardContext,
6767
pub db: DbConn,
6868
pub opts: NxShellOptions,
69+
pub toasts: Toasts,
6970
}
7071

7172
impl NxShell {
@@ -89,6 +90,9 @@ impl NxShell {
8990
..Default::default()
9091
},
9192
state_manager,
93+
toasts: Toasts::new()
94+
.anchor(Align2::CENTER_CENTER, (10.0, 10.0))
95+
.direction(egui::Direction::TopDown),
9296
})
9397
}
9498

@@ -112,10 +116,6 @@ impl eframe::App for NxShell {
112116
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
113117
self.recv_event();
114118

115-
let mut toasts = Toasts::new()
116-
.anchor(Align2::CENTER_CENTER, (10.0, 10.0))
117-
.direction(egui::Direction::TopDown);
118-
119119
egui::TopBottomPanel::top("main_top_panel").show(ctx, |ui| {
120120
self.menubar(ui);
121121
});
@@ -131,7 +131,7 @@ impl eframe::App for NxShell {
131131

132132
self.search_sessions(ui);
133133
ui.separator();
134-
self.list_sessions(ctx, ui, &mut toasts);
134+
self.list_sessions(ctx, ui);
135135
});
136136
egui::TopBottomPanel::bottom("main_bottom_panel").show(ctx, |ui| {
137137
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
@@ -141,14 +141,14 @@ impl eframe::App for NxShell {
141141

142142
if *self.opts.show_add_session_modal.borrow() {
143143
self.opts.surrender_focus();
144-
self.show_add_session_window(ctx, &mut toasts);
144+
self.show_add_session_window(ctx);
145145
}
146146

147147
egui::CentralPanel::default().show(ctx, |_ui| {
148148
self.tab_view(ctx);
149149
});
150150

151-
toasts.show(ctx);
151+
self.toasts.show(ctx);
152152
}
153153
}
154154

@@ -165,7 +165,7 @@ impl NxShell {
165165
}
166166
}
167167

168-
fn list_sessions(&mut self, ctx: &egui::Context, ui: &mut egui::Ui, toasts: &mut Toasts) {
168+
fn list_sessions(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
169169
if let Some(sessions) = self.state_manager.sessions.take() {
170170
for (group, sessions) in sessions.iter() {
171171
CollapsingHeader::new(group)
@@ -183,12 +183,12 @@ impl NxShell {
183183
if let Err(err) =
184184
self.add_shell_tab_with_secret(ctx, session)
185185
{
186-
toasts.add(error_toast(err.to_string()));
186+
self.toasts.add(error_toast(err.to_string()));
187187
}
188188
}
189189
Ok(None) => {}
190190
Err(err) => {
191-
toasts.add(error_toast(err.to_string()));
191+
self.toasts.add(error_toast(err.to_string()));
192192
}
193193
}
194194
} else if response.secondary_clicked() {

nxshell/src/ui/form/session.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use egui::{
88
use egui_form::garde::GardeReport;
99
use egui_form::{Form, FormField};
1010
use egui_term::{Authentication, SshOptions, TermType};
11-
use egui_toast::Toasts;
1211
use garde::Validate;
1312
use orion::aead::{seal, SecretKey};
1413
use std::fmt::Display;
@@ -91,7 +90,7 @@ impl SessionState {
9190
}
9291

9392
impl NxShell {
94-
pub fn show_add_session_window(&mut self, ctx: &Context, toasts: &mut Toasts) {
93+
pub fn show_add_session_window(&mut self, ctx: &Context) {
9594
let session_id = Id::new(SessionState::id());
9695
let mut session_state = SessionState::load(ctx, session_id);
9796

@@ -114,7 +113,7 @@ impl NxShell {
114113
Ok(_) => should_close = true,
115114
Err(err) => {
116115
error!("failed to add session: {err}");
117-
toasts.add(error_toast(err.to_string()));
116+
self.toasts.add(error_toast(err.to_string()));
118117
}
119118
}
120119
}

0 commit comments

Comments
 (0)