From 9baacc310ad282ec451f0bc056a69bb1fa56ff4f Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 31 Oct 2026 04:42:38 +0000 Subject: [PATCH] updates: show check results with craft-update's CheckResultDialog --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/ui-egui/src/updates_ui.rs | 49 ++++++++++++++++---------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8403d2e09..050008643 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1084,7 +1084,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=04aa1703b32d299e54f78fcde4182f2b393a9116#04aa1703b32d299e54f78fcde4182f2b393a9116" +source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7" dependencies = [ "chrono", "dunce", diff --git a/Cargo.toml b/Cargo.toml index 7c8f655c4..ecf431a0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ vello_cpu = "0.2" image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "gif", "bmp", "tiff"] } craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0", default-features = false, features = ["write"] } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "04aa1703b32d299e54f78fcde4182f2b393a9116", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["egui"] } quick-xml = "0.41" zip = { version = "3", default-features = false, features = ["deflate"] } # zlib streams (compressed metafile pictures in `.doc` drawings); already in the lock as a dependency of other crates. diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index 020f73c48..c7cd6348a 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -2,12 +2,16 @@ use crate::WordApp; +#[cfg(not(target_arch = "wasm32"))] +use craft_update::dialog::{CheckResultDialog, CheckResultResponse}; #[cfg(not(target_arch = "wasm32"))] use craft_update::updater::{Action, Status, Updater}; pub(crate) struct Runtime { #[cfg(not(target_arch = "wasm32"))] updater: Updater, + #[cfg(not(target_arch = "wasm32"))] + result_dialog: CheckResultDialog, /// The desktop app turns the check at start on; tests and the web build leave it off. #[cfg(not(target_arch = "wasm32"))] startup_check: bool, @@ -17,6 +21,7 @@ pub(crate) struct Runtime { #[cfg(not(target_arch = "wasm32"))] repaint: Option, pub(crate) manual_window_open: bool, + #[cfg(target_arch = "wasm32")] pub(crate) status_message: Option, } @@ -26,12 +31,15 @@ impl Default for Runtime { #[cfg(not(target_arch = "wasm32"))] updater: Updater::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")), #[cfg(not(target_arch = "wasm32"))] + result_dialog: CheckResultDialog::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")), + #[cfg(not(target_arch = "wasm32"))] startup_check: false, #[cfg(not(target_arch = "wasm32"))] check_requested: false, #[cfg(not(target_arch = "wasm32"))] repaint: None, manual_window_open: false, + #[cfg(target_arch = "wasm32")] status_message: None, } } @@ -49,6 +57,7 @@ pub(crate) fn check(app: &mut WordApp) { #[cfg(not(target_arch = "wasm32"))] { app.updates_rt.check_requested = true; + app.updates_rt.manual_window_open = true; if let Some(ctx) = &app.updates_rt.repaint { ctx.request_repaint(); } @@ -86,21 +95,27 @@ pub(crate) fn show(app: &mut WordApp, ctx: &egui::Context) { Action::Close => ctx.send_viewport_cmd(egui::ViewportCommand::Close), Action::None => {} } - // The window answers Help ▸ Check for Updates, so it follows the updater's status. + // The dialog answers Help ▸ Check for Updates; a found update leaves the status idle and the prompt above takes over. let rt = &mut app.updates_rt; - (rt.manual_window_open, rt.status_message) = match rt.updater.status() { - Status::Idle => (false, None), - Status::Checking => (true, None), - Status::UpToDate => { - (true, Some(tl!("WordCraft {version} is currently the newest version available.").replace("{version}", env!("CARGO_PKG_VERSION")))) + if rt.manual_window_open { + match rt.result_dialog.show(ctx, rt.updater.status()) { + CheckResultResponse::None => {} + CheckResultResponse::Close => { + rt.manual_window_open = false; + rt.updater.dismiss_status(); + } + CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), } - Status::Failed(e) => (true, Some(tl!("Could not check for updates:\n{error}").replace("{error}", e))), - }; + // An update was found: the prompt replaces the dialog. + if matches!(rt.updater.status(), Status::Idle) { + rt.manual_window_open = false; + } + } } + #[cfg(target_arch = "wasm32")] if app.updates_rt.manual_window_open { let mut open = true; - let mut close = false; egui::Window::new(tl!("Check for Updates")) .open(&mut open) .resizable(false) @@ -109,25 +124,11 @@ pub(crate) fn show(app: &mut WordApp, ctx: &egui::Context) { .show(ctx, |ui| { if let Some(msg) = &app.updates_rt.status_message { ui.label(msg); - } else { - ui.label(tl!("Checking for updates…")); } - ui.add_space(8.0); - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if ui.button(tl!("Close")).clicked() { - close = true; - } - }); }); - if !open || close { + if !open { app.updates_rt.manual_window_open = false; app.updates_rt.status_message = None; } } - - // Closing the window dismisses the outcome it showed. - #[cfg(not(target_arch = "wasm32"))] - if !app.updates_rt.manual_window_open { - app.updates_rt.updater.dismiss_status(); - } }