setup: auto-download official installer for existing launchers too
This commit is contained in:
+40
-4
@@ -22,6 +22,7 @@ pub enum Message {
|
|||||||
// Install stage
|
// Install stage
|
||||||
Back,
|
Back,
|
||||||
SourceChanged(String),
|
SourceChanged(String),
|
||||||
|
AutoDownload,
|
||||||
PreparePressed,
|
PreparePressed,
|
||||||
PrepareDone(Result<PathBuf, String>),
|
PrepareDone(Result<PathBuf, String>),
|
||||||
InstallPressed,
|
InstallPressed,
|
||||||
@@ -224,6 +225,34 @@ fn update(state: &mut State, message: Message) -> Task<Message> {
|
|||||||
state.source = s;
|
state.source = s;
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::AutoDownload => {
|
||||||
|
// Auto-start download for launchers with an official installer URL
|
||||||
|
let url = state.source.clone();
|
||||||
|
if url.is_empty() {
|
||||||
|
return Task::none();
|
||||||
|
}
|
||||||
|
state.stage = Stage::Busy;
|
||||||
|
let display_name = state
|
||||||
|
.launcher
|
||||||
|
.as_ref()
|
||||||
|
.map(|l| l.display.clone())
|
||||||
|
.unwrap_or_else(|| "installer".to_string());
|
||||||
|
state.status = format!("Downloading {} installer…", display_name);
|
||||||
|
if let Ok(mut p) = state.download.lock() {
|
||||||
|
*p = DownloadProgress::default();
|
||||||
|
}
|
||||||
|
let name = state
|
||||||
|
.launcher
|
||||||
|
.as_ref()
|
||||||
|
.expect("launcher set")
|
||||||
|
.name
|
||||||
|
.clone();
|
||||||
|
let progress = state.download.clone();
|
||||||
|
Task::perform(
|
||||||
|
async_blocking(move || download_blocking(&url, &name, progress)),
|
||||||
|
Message::PrepareDone,
|
||||||
|
)
|
||||||
|
}
|
||||||
Message::PreparePressed => {
|
Message::PreparePressed => {
|
||||||
let src = state.source.trim().to_string();
|
let src = state.source.trim().to_string();
|
||||||
if src.is_empty() {
|
if src.is_empty() {
|
||||||
@@ -821,10 +850,17 @@ pub fn run(config: &Config, launcher: &Launcher) -> Result<()> {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.run_with(move || {
|
.run_with(move || {
|
||||||
(
|
let has_url = launcher.installer_url.is_some();
|
||||||
State::new_install(config.clone(), launcher.clone()),
|
let mut state = State::new_install(config.clone(), launcher.clone());
|
||||||
Task::none(),
|
if has_url {
|
||||||
)
|
state.source = launcher.installer_url.unwrap_or_default();
|
||||||
|
}
|
||||||
|
let init_task = if has_url {
|
||||||
|
Task::done(Message::AutoDownload)
|
||||||
|
} else {
|
||||||
|
Task::none()
|
||||||
|
};
|
||||||
|
(state, init_task)
|
||||||
})
|
})
|
||||||
.map_err(|e| anyhow::anyhow!("iced: {e}"))
|
.map_err(|e| anyhow::anyhow!("iced: {e}"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user