gui(installer): install and start automatically on final step
This commit is contained in:
parent
3a59790530
commit
03c2bd76b8
@ -20,7 +20,10 @@ use liana::miniscript::bitcoin::bip32::Fingerprint;
|
|||||||
|
|
||||||
use liana_ui::widget::*;
|
use liana_ui::widget::*;
|
||||||
|
|
||||||
use crate::installer::{context::Context, message::Message, view};
|
use crate::{
|
||||||
|
bitcoind::Bitcoind,
|
||||||
|
installer::{context::Context, message::Message, view},
|
||||||
|
};
|
||||||
|
|
||||||
pub trait Step {
|
pub trait Step {
|
||||||
fn update(&mut self, _message: Message) -> Command<Message> {
|
fn update(&mut self, _message: Message) -> Command<Message> {
|
||||||
@ -60,7 +63,7 @@ impl From<Welcome> for Box<dyn Step> {
|
|||||||
|
|
||||||
pub struct Final {
|
pub struct Final {
|
||||||
generating: bool,
|
generating: bool,
|
||||||
context: Option<Context>,
|
internal_bitcoind: Option<Bitcoind>,
|
||||||
warning: Option<String>,
|
warning: Option<String>,
|
||||||
config_path: Option<PathBuf>,
|
config_path: Option<PathBuf>,
|
||||||
hot_signer_fingerprint: Fingerprint,
|
hot_signer_fingerprint: Fingerprint,
|
||||||
@ -70,7 +73,7 @@ pub struct Final {
|
|||||||
impl Final {
|
impl Final {
|
||||||
pub fn new(hot_signer_fingerprint: Fingerprint) -> Self {
|
pub fn new(hot_signer_fingerprint: Fingerprint) -> Self {
|
||||||
Self {
|
Self {
|
||||||
context: None,
|
internal_bitcoind: None,
|
||||||
generating: false,
|
generating: false,
|
||||||
warning: None,
|
warning: None,
|
||||||
config_path: None,
|
config_path: None,
|
||||||
@ -82,7 +85,7 @@ impl Final {
|
|||||||
|
|
||||||
impl Step for Final {
|
impl Step for Final {
|
||||||
fn load_context(&mut self, ctx: &Context) {
|
fn load_context(&mut self, ctx: &Context) {
|
||||||
self.context = Some(ctx.clone());
|
self.internal_bitcoind = ctx.internal_bitcoind.clone();
|
||||||
if let Some(signer) = &ctx.recovered_signer {
|
if let Some(signer) = &ctx.recovered_signer {
|
||||||
self.hot_signer_fingerprint = signer.fingerprint();
|
self.hot_signer_fingerprint = signer.fingerprint();
|
||||||
self.hot_signer_is_not_used = false;
|
self.hot_signer_is_not_used = false;
|
||||||
@ -98,6 +101,13 @@ impl Step for Final {
|
|||||||
self.hot_signer_is_not_used = true;
|
self.hot_signer_is_not_used = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn load(&self) -> Command<Message> {
|
||||||
|
if !self.generating && self.config_path.is_none() {
|
||||||
|
Command::perform(async {}, |_| Message::Install)
|
||||||
|
} else {
|
||||||
|
Command::none()
|
||||||
|
}
|
||||||
|
}
|
||||||
fn update(&mut self, message: Message) -> Command<Message> {
|
fn update(&mut self, message: Message) -> Command<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::Installed(res) => {
|
Message::Installed(res) => {
|
||||||
@ -107,7 +117,13 @@ impl Step for Final {
|
|||||||
self.config_path = None;
|
self.config_path = None;
|
||||||
self.warning = Some(e.to_string());
|
self.warning = Some(e.to_string());
|
||||||
}
|
}
|
||||||
Ok(path) => self.config_path = Some(path),
|
Ok(path) => {
|
||||||
|
self.config_path = Some(path.clone());
|
||||||
|
let internal_bitcoind = self.internal_bitcoind.clone();
|
||||||
|
return Command::perform(async {}, move |_| {
|
||||||
|
Message::Exit(path.clone(), internal_bitcoind)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Install => {
|
Message::Install => {
|
||||||
@ -121,20 +137,11 @@ impl Step for Final {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self, progress: (usize, usize)) -> Element<Message> {
|
fn view(&self, progress: (usize, usize)) -> Element<Message> {
|
||||||
let ctx = self.context.as_ref().unwrap();
|
|
||||||
let desc = ctx.descriptor.as_ref().unwrap().to_string();
|
|
||||||
view::install(
|
view::install(
|
||||||
progress,
|
progress,
|
||||||
ctx,
|
|
||||||
desc,
|
|
||||||
self.generating,
|
self.generating,
|
||||||
self.config_path.as_ref(),
|
self.config_path.as_ref(),
|
||||||
self.warning.as_ref(),
|
self.warning.as_ref(),
|
||||||
if self.hot_signer_is_not_used {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(self.hot_signer_fingerprint)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,6 @@ use crate::{
|
|||||||
bitcoind::StartInternalBitcoindError,
|
bitcoind::StartInternalBitcoindError,
|
||||||
hw::HardwareWallet,
|
hw::HardwareWallet,
|
||||||
installer::{
|
installer::{
|
||||||
context::Context,
|
|
||||||
message::{self, Message},
|
message::{self, Message},
|
||||||
prompt,
|
prompt,
|
||||||
step::{DownloadState, InstallState},
|
step::{DownloadState, InstallState},
|
||||||
@ -1090,158 +1089,27 @@ pub fn start_internal_bitcoind<'a>(
|
|||||||
|
|
||||||
pub fn install<'a>(
|
pub fn install<'a>(
|
||||||
progress: (usize, usize),
|
progress: (usize, usize),
|
||||||
context: &Context,
|
|
||||||
descriptor: String,
|
|
||||||
generating: bool,
|
generating: bool,
|
||||||
config_path: Option<&std::path::PathBuf>,
|
config_path: Option<&std::path::PathBuf>,
|
||||||
warning: Option<&'a String>,
|
warning: Option<&'a String>,
|
||||||
signer: Option<Fingerprint>,
|
|
||||||
) -> Element<'a, Message> {
|
) -> Element<'a, Message> {
|
||||||
layout(
|
layout(
|
||||||
progress,
|
progress,
|
||||||
"Final step",
|
"Finalize installation",
|
||||||
Column::new()
|
Column::new()
|
||||||
.push(text(
|
|
||||||
"Check your information before finalizing the install process:",
|
|
||||||
))
|
|
||||||
.push(
|
|
||||||
Container::new(
|
|
||||||
Column::new()
|
|
||||||
.spacing(10)
|
|
||||||
.push(
|
|
||||||
card::simple(
|
|
||||||
Column::new()
|
|
||||||
.spacing(5)
|
|
||||||
.push(text("Descriptor:").small().bold())
|
|
||||||
.push(text(descriptor).small()),
|
|
||||||
)
|
|
||||||
.width(Length::Fill),
|
|
||||||
)
|
|
||||||
.push_maybe(if context.hws.is_empty() && signer.is_none() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(
|
|
||||||
card::simple(
|
|
||||||
Column::new()
|
|
||||||
.spacing(5)
|
|
||||||
.push(text("Registered signing devices:").small().bold())
|
|
||||||
.push_maybe(if context.hws.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(context.hws.iter().fold(
|
|
||||||
Column::new(),
|
|
||||||
|acc, hw| {
|
|
||||||
acc.push(
|
|
||||||
Row::new()
|
|
||||||
.spacing(5)
|
|
||||||
.push_maybe(
|
|
||||||
context.keys.iter().find_map(|k| {
|
|
||||||
if k.master_fingerprint == hw.1
|
|
||||||
{
|
|
||||||
Some(
|
|
||||||
text(k.name.clone())
|
|
||||||
.small()
|
|
||||||
.bold(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.push(
|
|
||||||
text(format!("#{}", hw.1)).small(),
|
|
||||||
)
|
|
||||||
.push(text(hw.0.to_string()).small()),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
))
|
|
||||||
})
|
|
||||||
.push_maybe(signer.as_ref().map(|fingerprint| {
|
|
||||||
Row::new()
|
|
||||||
.spacing(5)
|
|
||||||
.push_maybe(context.keys.iter().find_map(|k| {
|
|
||||||
if k.master_fingerprint == *fingerprint {
|
|
||||||
Some(text(k.name.clone()).small().bold())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.push(text(format!("#{}", fingerprint)).small())
|
|
||||||
.push(text("This computer").small())
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
.width(Length::Fill),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.push(
|
|
||||||
card::simple(
|
|
||||||
Column::new()
|
|
||||||
.push(text("Bitcoind:").small().bold())
|
|
||||||
.push(
|
|
||||||
Row::new()
|
|
||||||
.spacing(5)
|
|
||||||
.align_items(Alignment::Center)
|
|
||||||
.push(text("Cookie path:").small())
|
|
||||||
.push(
|
|
||||||
text(format!(
|
|
||||||
"{}",
|
|
||||||
context
|
|
||||||
.bitcoind_config
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.cookie_path
|
|
||||||
.to_string_lossy()
|
|
||||||
))
|
|
||||||
.small(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.push(
|
|
||||||
Row::new()
|
|
||||||
.spacing(5)
|
|
||||||
.align_items(Alignment::Center)
|
|
||||||
.push(text("Address:").small())
|
|
||||||
.push(
|
|
||||||
text(format!(
|
|
||||||
"{}",
|
|
||||||
context.bitcoind_config.as_ref().unwrap().addr
|
|
||||||
))
|
|
||||||
.small(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.width(Length::Fill),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.max_width(1000),
|
|
||||||
)
|
|
||||||
.push(Space::with_height(Length::Fixed(50.0)))
|
|
||||||
.push_maybe(warning.map(|e| card::invalid(text(e))))
|
.push_maybe(warning.map(|e| card::invalid(text(e))))
|
||||||
.push(if generating {
|
.push(if generating {
|
||||||
Container::new(button::primary(None, "Installing ...").width(Length::Fixed(200.0)))
|
Container::new(text("Installing..."))
|
||||||
} else if let Some(path) = config_path {
|
} else if config_path.is_some() {
|
||||||
Container::new(
|
Container::new(
|
||||||
Column::new()
|
Row::new()
|
||||||
.push(Container::new(text("Installed !")))
|
.spacing(10)
|
||||||
.push(Container::new(
|
|
||||||
button::primary(None, "Start")
|
|
||||||
.on_press(Message::Exit(
|
|
||||||
path.clone(),
|
|
||||||
context.internal_bitcoind.clone(),
|
|
||||||
))
|
|
||||||
.width(Length::Fixed(200.0)),
|
|
||||||
))
|
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.spacing(20),
|
.push(icon::circle_check_icon().style(color::GREEN))
|
||||||
|
.push(text("Installed").style(color::GREEN)),
|
||||||
)
|
)
|
||||||
.padding(50)
|
|
||||||
.width(Length::Fill)
|
|
||||||
.center_x()
|
|
||||||
} else {
|
} else {
|
||||||
Container::new(
|
Container::new(Space::with_height(Length::Fixed(25.0)))
|
||||||
button::primary(None, "Finalize installation")
|
|
||||||
.on_press(Message::Install)
|
|
||||||
.width(Length::Fixed(200.0)),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user