mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-12 12:41:30 +03:00
gtk: handle exit of service properly
This commit is contained in:
@@ -28,7 +28,7 @@ futures-core = "0.3.28"
|
|||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
clap = { version="4.4.11", features = ["derive"] }
|
clap = { version="4.4.11", features = ["derive"] }
|
||||||
gtk = { package = "gtk4", version = "0.7.2", features = ["v4_2"], optional = true }
|
gtk = { package = "gtk4", version = "0.7.2", features = ["v4_2"], optional = true }
|
||||||
adw = { package = "libadwaita", version = "0.5.2", features = ["v1_1"], optional = true }
|
adw = { package = "libadwaita", version = "0.5.2", features = ["v1_2"], optional = true }
|
||||||
async-channel = { version = "2.1.1", optional = true }
|
async-channel = { version = "2.1.1", optional = true }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
|||||||
@@ -129,7 +129,14 @@ fn build_ui(app: &Application) {
|
|||||||
window.imp().stream.borrow_mut().replace(tx);
|
window.imp().stream.borrow_mut().replace(tx);
|
||||||
glib::spawn_future_local(clone!(@weak window => async move {
|
glib::spawn_future_local(clone!(@weak window => async move {
|
||||||
loop {
|
loop {
|
||||||
let notify = receiver.recv().await.unwrap();
|
let notify = receiver.recv().await;
|
||||||
|
let notify = match notify {
|
||||||
|
Ok(n) => n,
|
||||||
|
_ => {
|
||||||
|
window.show_exit_dialog("service exited");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
match notify {
|
match notify {
|
||||||
FrontendNotify::NotifyClientActivate(handle, active) => {
|
FrontendNotify::NotifyClientActivate(handle, active) => {
|
||||||
window.activate_client(handle, active);
|
window.activate_client(handle, active);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::{io::Write, process};
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
@@ -218,4 +218,16 @@ impl Window {
|
|||||||
let toast_overlay = &self.imp().toast_overlay;
|
let toast_overlay = &self.imp().toast_overlay;
|
||||||
toast_overlay.add_toast(toast);
|
toast_overlay.add_toast(toast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_exit_dialog(&self, msg: &str) {
|
||||||
|
let dialog = adw::MessageDialog::builder()
|
||||||
|
.transient_for(self)
|
||||||
|
// .heading(msg)
|
||||||
|
.body(msg)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
dialog.add_response("close", "Close");
|
||||||
|
dialog.connect_response(Some("close"), move |_, _| process::exit(1));
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user