setup: auto-download official installer for existing launchers too

This commit is contained in:
funman300
2026-04-19 00:40:04 -07:00
parent 20509fb488
commit 32c6e1fce0
+40 -4
View File
@@ -22,6 +22,7 @@ pub enum Message {
// Install stage
Back,
SourceChanged(String),
AutoDownload,
PreparePressed,
PrepareDone(Result<PathBuf, String>),
InstallPressed,
@@ -224,6 +225,34 @@ fn update(state: &mut State, message: Message) -> Task<Message> {
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}"))
}