Skip to content

Commit

Permalink
fix dummysigner exit signal
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Dec 16, 2021
1 parent 02e480c commit 44eb4f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
11 changes: 11 additions & 0 deletions contrib/tools/dummysigner/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contrib/tools/dummysigner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ iced_futures = "0.3.0"
iced_native = "0.4.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
tokio = {version = "1.9.0", features = ["net", "io-util"]}
tokio = {version = "1.9.0", features = ["net", "io-util", "signal"]}
tokio-util = { version = "0.6", features = ["codec"] }
tokio-serde = {version = "0.8", features = ["json"]}
toml = "0.5"
Expand Down
30 changes: 26 additions & 4 deletions contrib/tools/dummysigner/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::net::SocketAddr;

use iced::{executor, Application, Clipboard, Command, Element, Settings};
use iced::{executor, Application, Clipboard, Command, Element, Settings, Subscription};
use iced_native::{window, Event};
use revault_tx::bitcoin::util::bip32::ExtendedPrivKey;
use serde_json::json;

Expand All @@ -14,11 +15,13 @@ use crate::{
};

pub fn run(cfg: Config) -> iced::Result {
let settings = Settings::with_flags(cfg);
let mut settings = Settings::with_flags(cfg);
settings.exit_on_close_request = false;
App::run(settings)
}

pub struct App {
exit: bool,
keys: Vec<config::Key>,
signer: sign::Signer,
status: AppStatus,
Expand All @@ -35,6 +38,8 @@ pub enum AppStatus {

#[derive(Debug)]
pub enum Message {
CtrlC,
Event(Event),
Server(server::ServerMessage),
View(view::ViewMessage),
}
Expand All @@ -47,6 +52,7 @@ impl Application for App {
fn new(cfg: Config) -> (App, Command<Message>) {
(
App {
exit: false,
signer: sign::Signer::new(
cfg.descriptors.map(|d| sign::Descriptors {
deposit_descriptor: d.deposit_descriptor,
Expand All @@ -58,16 +64,24 @@ impl Application for App {
keys: cfg.keys,
status: AppStatus::Waiting,
},
Command::none(),
Command::perform(ctrl_c(), |_| Message::CtrlC),
)
}

fn title(&self) -> String {
String::from("Dummy signer - Revault")
}

fn should_exit(&self) -> bool {
self.exit
}

fn update(&mut self, message: Message, _clipboard: &mut Clipboard) -> Command<Message> {
match message {
Message::CtrlC | Message::Event(Event::Window(window::Event::CloseRequested)) => {
self.exit = true;
Command::none()
}
Message::Server(server::ServerMessage::NewConnection(addr, writer)) => {
self.status = AppStatus::Connected {
addr,
Expand Down Expand Up @@ -273,7 +287,10 @@ impl Application for App {
}

fn subscription(&self) -> iced::Subscription<Message> {
iced::Subscription::batch(vec![server::listen("0.0.0.0:8080").map(Message::Server)])
Subscription::batch(vec![
iced_native::subscription::events().map(Message::Event),
iced::Subscription::batch(vec![server::listen("0.0.0.0:8080").map(Message::Server)]),
])
}

fn view(&mut self) -> Element<Message> {
Expand All @@ -287,6 +304,11 @@ impl Application for App {
}
}

async fn ctrl_c() -> Result<(), ()> {
tokio::signal::ctrl_c().await.unwrap();
Ok(())
}

pub struct Key {
name: String,
xpriv: ExtendedPrivKey,
Expand Down

0 comments on commit 44eb4f8

Please sign in to comment.