Skip to content

Commit 1f4821a

Browse files
committed
gtk: handle exit of service properly
1 parent 82926d8 commit 1f4821a

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ futures-core = "0.3.28"
2828
futures = "0.3.28"
2929
clap = { version="4.4.11", features = ["derive"] }
3030
gtk = { package = "gtk4", version = "0.7.2", features = ["v4_2"], optional = true }
31-
adw = { package = "libadwaita", version = "0.5.2", features = ["v1_1"], optional = true }
31+
adw = { package = "libadwaita", version = "0.5.2", features = ["v1_2"], optional = true }
3232
async-channel = { version = "2.1.1", optional = true }
3333

3434
[target.'cfg(unix)'.dependencies]

src/frontend/gtk.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ fn build_ui(app: &Application) {
129129
window.imp().stream.borrow_mut().replace(tx);
130130
glib::spawn_future_local(clone!(@weak window => async move {
131131
loop {
132-
let notify = receiver.recv().await.unwrap();
132+
let notify = receiver.recv().await;
133+
let notify = match notify {
134+
Ok(n) => n,
135+
_ => {
136+
window.show_exit_dialog("service exited");
137+
break;
138+
}
139+
};
133140
match notify {
134141
FrontendNotify::NotifyClientActivate(handle, active) => {
135142
window.activate_client(handle, active);

src/frontend/gtk/window.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod imp;
22

3-
use std::io::Write;
3+
use std::{io::Write, process};
44

55
use adw::prelude::*;
66
use adw::subclass::prelude::*;
@@ -218,4 +218,16 @@ impl Window {
218218
let toast_overlay = &self.imp().toast_overlay;
219219
toast_overlay.add_toast(toast);
220220
}
221+
222+
pub fn show_exit_dialog(&self, msg: &str) {
223+
let dialog = adw::MessageDialog::builder()
224+
.transient_for(self)
225+
// .heading(msg)
226+
.body(msg)
227+
.build();
228+
229+
dialog.add_response("close", "Close");
230+
dialog.connect_response(Some("close"), move |_, _| process::exit(1));
231+
dialog.show();
232+
}
221233
}

0 commit comments

Comments
 (0)