Merge #268: fix launcher: exit on close event

09789b8161c04c9e1872d62232a8e95e97d42ab6 fix launcher: exit on close event (edouard)

Pull request description:

  close #264

ACKs for top commit:
  edouardparis:
    Self-ACK 09789b8161c04c9e1872d62232a8e95e97d42ab6

Tree-SHA512: e8c46719349320ef4fafd9cdf32a5967329e72999694ccf296ee27fa9307282c3645101e70de233bc1c7f1530b1b5afc9f366fb819e8f70a320843f6571204d4
This commit is contained in:
edouard 2022-12-20 18:09:39 +01:00
commit 57e8545b22
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F
2 changed files with 14 additions and 2 deletions

View File

@ -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<Message> {
iced_native::subscription::events().map(Message::Event)
}
pub fn view(&self) -> Element<Message> {
Container::new(
Column::new()
@ -111,6 +115,7 @@ impl Launcher {
#[derive(Debug, Clone)]
pub enum Message {
Event(iced_native::Event),
Install,
Run(Network),
}

View File

@ -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))),
}
}