diff --git a/CHANGELOG.md b/CHANGELOG.md index ef4b4ca..9adc808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The release notes for each tag are taken from the section for that version. ## Unreleased ### Fixed +- **Launcher update:** pressing Update no longer makes the update card disappear with nothing happening. The card now stays through the download and shows **Restart now** when the new version is ready; before, the window lost the version's name once the download started, so that button never appeared. A failed download says why and offers Try again and the download page. - **Fix and verify after a rebuild:** when the build finishes but its program is missing, the launcher says where it expected it and suggests checking antivirus, instead of telling you to press Install. - **Linux builds of Windows-only games:** a build that fails because the project uses Windows-only libraries now says so in the log, instead of only showing the compiler's error. diff --git a/src-tauri/src/launcher/view.rs b/src-tauri/src/launcher/view.rs index 3dc5a2d..c92ca64 100644 --- a/src-tauri/src/launcher/view.rs +++ b/src-tauri/src/launcher/view.rs @@ -546,14 +546,17 @@ impl App { } fn updater_view(&self) -> UpdaterView { + // The release being installed, while it downloads, once it is ready and after a failure: + // the window shows the update card only for a release it can name. + let found = || self.updater.release.as_ref().map(|r| r.tag_name.clone()); let (state, tag, error) = match &self.updater.state { UpdaterState::Idle => ("idle", None, None), UpdaterState::Checking => ("checking", None, None), UpdaterState::Current => ("current", None, None), UpdaterState::Available(release) => ("available", Some(release.tag_name.clone()), None), - UpdaterState::Downloading => ("downloading", None, None), - UpdaterState::Downloaded(_) => ("downloaded", None, None), - UpdaterState::Failed(error) => ("failed", None, Some(localize(error))), + UpdaterState::Downloading => ("downloading", found(), None), + UpdaterState::Downloaded(_) => ("downloaded", found(), None), + UpdaterState::Failed(error) => ("failed", found(), Some(localize(error))), }; UpdaterView { state, diff --git a/src-tauri/src/updater.rs b/src-tauri/src/updater.rs index 9728158..96eab30 100644 --- a/src-tauri/src/updater.rs +++ b/src-tauri/src/updater.rs @@ -20,13 +20,13 @@ const MAX_BYTES: u64 = 64 * 1024 * 1024; #[cfg(not(windows))] const MAX_BYTES: u64 = 400 * 1024 * 1024; -#[derive(Deserialize)] +#[derive(Clone, Deserialize)] pub struct Release { pub tag_name: String, assets: Vec, } -#[derive(Deserialize)] +#[derive(Clone, Deserialize)] struct Asset { name: String, size: u64, @@ -58,6 +58,9 @@ pub struct Updater { pub state: State, pub restart_requested: bool, pub restart_error: Option, + /// The newer release the last check found, kept while it downloads, once it is ready and + /// after a failed download: the window names it in each of those, and Update tries it again. + pub release: Option, result: Option>>, } @@ -73,6 +76,16 @@ impl Updater { } }; self.result = None; + self.keep_release(); + } + + /// Keeps the release a check found; forgets it when the check says this version is current. + fn keep_release(&mut self) { + match &self.state { + State::Available(release) => self.release = Some(release.clone()), + State::Current => self.release = None, + _ => {} + } } pub fn check(&mut self, ctx: &Ctx) { @@ -81,9 +94,13 @@ impl Updater { self.start(ctx, State::Checking, check_release); } + /// Downloads the release found: from "available", or again after a failed download. + /// Anything else (a download already running, one ready) is left as it is. pub fn download(&mut self, ctx: &Ctx) { - let State::Available(release) = std::mem::take(&mut self.state) else { - return; + let release = match (&self.state, &self.release) { + (State::Available(release), _) => release.clone(), + (State::Failed(_), Some(release)) => release.clone(), + _ => return, }; self.restart_requested = true; self.restart_error = None; @@ -472,6 +489,35 @@ fn release_links_follow_the_brand() { assert_eq!(RELEASES, format!("{}/releases", crate::brand::SOURCE_URL)); } +#[cfg(test)] +fn release_fixture(tag: &str) -> Release { + Release { + tag_name: tag.into(), + assets: Vec::new(), + } +} + +#[cfg(test)] +#[test] +fn the_release_found_is_kept_through_its_download_and_a_failure() { + let mut updater = Updater { + state: State::Available(release_fixture("v9.0.0")), + ..Updater::default() + }; + updater.keep_release(); + // A download that fails keeps the release, so the window still names it. + updater.state = State::Failed("offline".into()); + updater.keep_release(); + assert_eq!( + updater.release.as_ref().map(|r| r.tag_name.as_str()), + Some("v9.0.0") + ); + // A later check that finds this version current forgets it. + updater.state = State::Current; + updater.keep_release(); + assert!(updater.release.is_none()); +} + #[cfg(test)] #[test] fn compares_stable_versions_numerically() { diff --git a/src/features/shared/launcher-update.tsx b/src/features/shared/launcher-update.tsx index 08ed975..be3da6c 100644 --- a/src/features/shared/launcher-update.tsx +++ b/src/features/shared/launcher-update.tsx @@ -66,12 +66,26 @@ export function LauncherUpdate() { return (

{t("shell.update.ready", { tag })}

+ {u.restart_error &&

{u.restart_error}

}
) } + // A download that failed says why, and can be tried again or fetched from the Releases page. + if (u.state === "failed") { + return ( + +

{t("shell.update.failed", { tag })}

+ {u.error &&

{u.error}

} +
+ + +
+
+ ) + } return null } diff --git a/src/i18n/messages/en/shell.ts b/src/i18n/messages/en/shell.ts index 8075aed..67bb1ed 100644 --- a/src/i18n/messages/en/shell.ts +++ b/src/i18n/messages/en/shell.ts @@ -71,5 +71,7 @@ export default { downloading: "Downloading {tag}", ready: "{tag} is ready", restart: "Restart now", + failed: "Could not update to {tag}", + page: "Download page", }, } as const diff --git a/src/i18n/messages/es/shell.ts b/src/i18n/messages/es/shell.ts index a811f66..d9f6129 100644 --- a/src/i18n/messages/es/shell.ts +++ b/src/i18n/messages/es/shell.ts @@ -69,5 +69,7 @@ export default { downloading: "Descargando {tag}", ready: "{tag} está listo", restart: "Reiniciar ahora", + failed: "No se pudo actualizar a {tag}", + page: "Página de descarga", }, } satisfies Translation diff --git a/src/i18n/messages/fr/shell.ts b/src/i18n/messages/fr/shell.ts index af9df51..1eae27c 100644 --- a/src/i18n/messages/fr/shell.ts +++ b/src/i18n/messages/fr/shell.ts @@ -69,5 +69,7 @@ export default { downloading: "Téléchargement de {tag}", ready: "{tag} est prêt", restart: "Redémarrer maintenant", + failed: "Impossible de passer à {tag}", + page: "Page de téléchargement", }, } satisfies Translation diff --git a/src/i18n/messages/ru/shell.ts b/src/i18n/messages/ru/shell.ts index 4c3e4ec..cc8b24e 100644 --- a/src/i18n/messages/ru/shell.ts +++ b/src/i18n/messages/ru/shell.ts @@ -76,5 +76,7 @@ export default { downloading: "Загрузка {tag}", ready: "{tag} готов к установке", restart: "Перезапустить сейчас", + failed: "Не удалось обновиться до {tag}", + page: "Страница загрузки", }, } as const diff --git a/src/i18n/messages/zh-CN/shell.ts b/src/i18n/messages/zh-CN/shell.ts index 7c8fdcf..33d95c7 100644 --- a/src/i18n/messages/zh-CN/shell.ts +++ b/src/i18n/messages/zh-CN/shell.ts @@ -69,5 +69,7 @@ export default { downloading: "正在下载 {tag}", ready: "{tag} 已就绪", restart: "立即重启", + failed: "无法更新到 {tag}", + page: "下载页面", }, } satisfies Translation diff --git a/src/i18n/messages/zh-TW/shell.ts b/src/i18n/messages/zh-TW/shell.ts index dd2f408..643a047 100644 --- a/src/i18n/messages/zh-TW/shell.ts +++ b/src/i18n/messages/zh-TW/shell.ts @@ -69,5 +69,7 @@ export default { downloading: "正在下載 {tag}", ready: "{tag} 已準備就緒", restart: "立即重新啟動", + failed: "無法更新到 {tag}", + page: "下載頁面", }, } satisfies Translation