Skip to content

Commit

Permalink
dummysigner: add low level exit handling
Browse files Browse the repository at this point in the history
- do not rely on iced close_on_exit
- listen to window event and ctrl-c signal to exit
- drop any connection on exit

close revault#278
  • Loading branch information
edouardparis committed Dec 16, 2021
1 parent 44eb4f8 commit 4e6f1ce
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions contrib/tools/dummysigner/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -287,10 +289,14 @@ impl Application for App {
}

fn subscription(&self) -> iced::Subscription<Message> {
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<Message> {
Expand Down

0 comments on commit 4e6f1ce

Please sign in to comment.