From 32c6e1fce0cd2e15a8280634dcc6925d1c2eb923 Mon Sep 17 00:00:00 2001 From: funman300 Date: Sun, 19 Apr 2026 00:40:04 -0700 Subject: [PATCH] setup: auto-download official installer for existing launchers too --- src/setup.rs | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/setup.rs b/src/setup.rs index 3cd2575..0a3704a 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -22,6 +22,7 @@ pub enum Message { // Install stage Back, SourceChanged(String), + AutoDownload, PreparePressed, PrepareDone(Result), InstallPressed, @@ -224,6 +225,34 @@ fn update(state: &mut State, message: Message) -> Task { state.source = s; 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 => { let src = state.source.trim().to_string(); if src.is_empty() { @@ -821,10 +850,17 @@ pub fn run(config: &Config, launcher: &Launcher) -> Result<()> { ..Default::default() }) .run_with(move || { - ( - State::new_install(config.clone(), launcher.clone()), - Task::none(), - ) + let has_url = launcher.installer_url.is_some(); + let mut state = State::new_install(config.clone(), launcher.clone()); + 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}")) }