Skip to content

Commit 6d3efb7

Browse files
committed
Add toast when invalid terminal is set
1 parent 4eefd09 commit 6d3efb7

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/container.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ impl Container {
217217
Ok(())
218218
});
219219
}
220-
pub fn spawn_terminal(&self) {
220+
pub fn spawn_terminal(&self) -> DistroboxTask {
221221
let this = self.clone();
222222
self.root_store()
223223
.create_task(&self.name(), "spawn-terminal", move |_task| async move {
224224
let enter_cmd = this.root_store().distrobox().enter_cmd(&this.name());
225225
this.root_store()
226226
.spawn_terminal_cmd(this.name(), &enter_cmd)
227227
.await
228-
});
228+
})
229229
}
230230
}
231231

src/distrobox_task.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use glib::subclass::prelude::*;
66
use glib::Properties;
77
use gtk::glib;
88
use gtk::prelude::*;
9+
use std::cell::Ref;
910
use std::cell::RefCell;
1011
use std::future::Future;
1112
use tracing::{debug, error, info, warn};
@@ -120,6 +121,9 @@ impl DistroboxTask {
120121
pub fn ended(&self) -> bool {
121122
self.is_failed() || self.is_successful()
122123
}
124+
pub fn error(&self) -> Ref<Option<anyhow::Error>> {
125+
self.imp().error.borrow()
126+
}
123127
pub fn take_error(&self) -> Option<anyhow::Error> {
124128
self.imp().error.borrow_mut().take()
125129
}

src/window.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ impl DistroShelfWindow {
218218
.set_child(Some(&tasks_button));
219219
}
220220

221+
fn add_toast(&self, toast: adw::Toast) {
222+
self.imp().toast_overlay.add_toast(toast);
223+
}
224+
221225
pub fn build_container_header(&self, container: &Container) -> gtk::Box {
222226
// Create labels for the title and subtitle
223227
let title_label = gtk::Label::new(Some(&container.name()));
@@ -237,12 +241,12 @@ impl DistroShelfWindow {
237241
copy_btn.add_css_class("xs");
238242
// Capture a clone of the image URL for the closure
239243
let image_url = container.image().to_string();
240-
let toast_overlay = self.imp().toast_overlay.clone();
244+
let this = self.clone();
241245
copy_btn.connect_clicked(move |_| {
242246
if let Some(display) = gdk::Display::default() {
243247
let clipboard = display.primary_clipboard();
244248
clipboard.set_text(&image_url);
245-
toast_overlay.add_toast(adw::Toast::new("Image URL copied"));
249+
this.add_toast(adw::Toast::new("Image URL copied"));
246250
}
247251
});
248252

@@ -318,10 +322,25 @@ impl DistroShelfWindow {
318322
#[weak(rename_to = this)]
319323
self,
320324
move |_| {
321-
this.root_store()
325+
let task = this.root_store()
322326
.selected_container()
323327
.unwrap()
324328
.spawn_terminal();
329+
task.connect_status_notify(move |task| {
330+
if let Some(_) = &*task.error() {
331+
let toast = adw::Toast::new("Check your terminal settings.");
332+
toast.set_button_label(Some("Preferences"));
333+
toast.connect_button_clicked(clone!(
334+
#[weak]
335+
this,
336+
move |_| {
337+
this.root_store()
338+
.set_current_dialog(TaggedObject::new("preferences"));
339+
}
340+
));
341+
this.add_toast(toast);
342+
}
343+
});
325344
}
326345
));
327346
status_child.append(&terminal_btn);
@@ -562,15 +581,11 @@ impl DistroShelfWindow {
562581

563582
let page = adw::PreferencesPage::new();
564583

565-
let preferences_group = adw::PreferencesGroup::new();
566-
preferences_group.set_title("General");
567-
568584
let terminal_group = adw::PreferencesGroup::new();
569585
terminal_group.set_title("Terminal Settings");
570586
terminal_group.add(&TerminalComboRow::new_with_params(self.root_store()));
571587
page.add(&terminal_group);
572588

573-
page.add(&preferences_group);
574589
dialog.add(&page);
575590
dialog.upcast()
576591
}

0 commit comments

Comments
 (0)