From 09789b8161c04c9e1872d62232a8e95e97d42ab6 Mon Sep 17 00:00:00 2001 From: edouard Date: Tue, 20 Dec 2022 16:56:02 +0100 Subject: [PATCH] fix launcher: exit on close event close #264 --- gui/src/launcher.rs | 7 ++++++- gui/src/main.rs | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gui/src/launcher.rs b/gui/src/launcher.rs index 625fcdd0..ff8ef768 100644 --- a/gui/src/launcher.rs +++ b/gui/src/launcher.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use iced::{ widget::{Button, Column, Container, Row}, - Alignment, Element, Length, + Alignment, Element, Length, Subscription, }; use liana::miniscript::bitcoin::Network; @@ -46,6 +46,10 @@ impl Launcher { self.should_exit } + pub fn subscription(&self) -> Subscription { + iced_native::subscription::events().map(Message::Event) + } + pub fn view(&self) -> Element { Container::new( Column::new() @@ -111,6 +115,7 @@ impl Launcher { #[derive(Debug, Clone)] pub enum Message { + Event(iced_native::Event), Install, Run(Network), } diff --git a/gui/src/main.rs b/gui/src/main.rs index 528c7cd8..a4d5cf69 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -165,6 +165,12 @@ impl Application for GUI { self.state = State::Installer(Box::new(install)); command.map(|msg| Message::Install(Box::new(msg))) } + launcher::Message::Event(iced_native::Event::Window( + iced_native::window::Event::CloseRequested, + )) => { + l.stop(); + Command::none() + } launcher::Message::Run(network) => { let mut path = l.datadir_path.clone(); path.push(network.to_string()); @@ -177,6 +183,7 @@ impl Application for GUI { self.state = State::Loader(Box::new(loader)); command.map(|msg| Message::Load(Box::new(msg))) } + _ => Command::none(), }, (State::Installer(i), Message::Install(msg)) => { if let installer::Message::Exit(path) = *msg { @@ -233,7 +240,7 @@ impl Application for GUI { State::Installer(v) => v.subscription().map(|msg| Message::Install(Box::new(msg))), State::Loader(v) => v.subscription().map(|msg| Message::Load(Box::new(msg))), State::App(v) => v.subscription().map(|msg| Message::Run(Box::new(msg))), - _ => Subscription::none(), + State::Launcher(v) => v.subscription().map(|msg| Message::Launch(Box::new(msg))), } }