From 4e6f1ce832de8b073d7f5a330a0e444cfda033db Mon Sep 17 00:00:00 2001 From: edouard Date: Thu, 16 Dec 2021 17:19:27 +0100 Subject: [PATCH] dummysigner: add low level exit handling - do not rely on iced close_on_exit - listen to window event and ctrl-c signal to exit - drop any connection on exit close #278 --- contrib/tools/dummysigner/src/app.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/tools/dummysigner/src/app.rs b/contrib/tools/dummysigner/src/app.rs index 69173800..87dd55c8 100644 --- a/contrib/tools/dummysigner/src/app.rs +++ b/contrib/tools/dummysigner/src/app.rs @@ -80,6 +80,7 @@ impl Application for App { match message { Message::CtrlC | Message::Event(Event::Window(window::Event::CloseRequested)) => { self.exit = true; + self.status = AppStatus::Waiting {}; Command::none() } Message::Server(server::ServerMessage::NewConnection(addr, writer)) => { @@ -125,7 +126,8 @@ impl Application for App { } Command::none() } - Message::Server(server::ServerMessage::ConnectionDropped) => { + Message::Server(server::ServerMessage::ConnectionDropped) + | Message::Server(server::ServerMessage::Stopped) => { self.status = AppStatus::Waiting {}; Command::none() } @@ -287,10 +289,14 @@ impl Application for App { } fn subscription(&self) -> iced::Subscription { - Subscription::batch(vec![ - iced_native::subscription::events().map(Message::Event), - iced::Subscription::batch(vec![server::listen("0.0.0.0:8080").map(Message::Server)]), - ]) + if !self.exit { + Subscription::batch(vec![ + iced_native::subscription::events().map(Message::Event), + server::listen("0.0.0.0:8080").map(Message::Server), + ]) + } else { + Subscription::none() + } } fn view(&mut self) -> Element {