updates: show check results with craft-update's CheckResultDialog

This commit is contained in:
aiongg
2026-10-31 04:42:07 +00:00
parent 660e15c9f4
commit 11ce7eb52c
3 changed files with 42 additions and 13 deletions
Generated
+9 -9
View File
@@ -268,7 +268,7 @@ dependencies = [
"objc2-foundation 0.3.2",
"parking_lot",
"percent-encoding",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
"wl-clipboard-rs",
"x11rb",
]
@@ -1191,7 +1191,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",
@@ -1643,7 +1643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -3435,7 +3435,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
dependencies = [
"libc",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -4030,7 +4030,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.12.1",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -4087,7 +4087,7 @@ dependencies = [
"security-framework",
"security-framework-sys",
"webpki-root-certs",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -4562,10 +4562,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [
"fastrand",
"getrandom 0.3.4",
"getrandom 0.4.3",
"once_cell",
"rustix 1.1.5",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -5471,7 +5471,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
+1 -1
View File
@@ -66,7 +66,7 @@ egui-wgpu = "0.37"
# Monotonic time on native and web (performance.now on wasm).
web-time = "1.1"
# 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"] }
rfd = "0.17"
arboard = { version = "3.6", default-features = false }
+32 -3
View File
@@ -3,6 +3,7 @@
//! `craft_update::updater::Updater`.
use craft_update::updater::{Action, Status, Updater};
use craft_update::{CheckResultDialog, CheckResultResponse};
use crate::CadApp;
@@ -16,11 +17,15 @@ pub struct Runtime {
enabled: bool,
/// Help ▸ Check for Updates… was chosen; the next frame's `tick` starts it with the context.
check_requested: bool,
/// The check-result dialog is open (from a requested check until it is closed).
result_open: bool,
/// The current result was already written to the command history.
result_echoed: bool,
}
impl Default for Runtime {
fn default() -> Self {
Self { updater: Updater::new(&crate::UPDATE_APP, VERSION), enabled: false, check_requested: false }
Self { updater: Updater::new(&crate::UPDATE_APP, VERSION), enabled: false, check_requested: false, result_open: false, result_echoed: false }
}
}
@@ -31,9 +36,11 @@ impl CadApp {
}
}
/// Help ▸ Check for Updates…: check now, and say so when there is nothing newer.
/// Help ▸ Check for Updates…: check now, and show the result when there is nothing newer.
pub fn check_now(app: &mut CadApp) {
app.updates_rt.check_requested = true;
app.updates_rt.result_open = true;
app.updates_rt.result_echoed = false;
}
/// Start the checks and collect the answers.
@@ -50,8 +57,16 @@ pub fn tick(app: &mut CadApp, ctx: &egui::Context) {
Status::Failed(_) => Some(crate::tl!("Could not check for updates.")),
Status::Idle | Status::Checking => None,
};
if let Some(message) = outcome {
let Some(message) = outcome else {
// A check that found an update leaves `Idle`; the prompt takes over from the dialog.
if rt.result_open && matches!(rt.updater.status(), Status::Idle) {
rt.result_open = false;
}
return;
};
if !rt.result_open {
rt.updater.dismiss_status();
} else if !std::mem::replace(&mut rt.result_echoed, true) {
app.session.echo(message);
}
}
@@ -60,6 +75,20 @@ pub fn tick(app: &mut CadApp, ctx: &egui::Context) {
pub fn show(app: &mut CadApp, ctx: &egui::Context) {
// The restart helper is scheduled before the app closes, so no update starts over unsaved work.
let clean = !app.session.docs.iter().any(|d| d.is_dirty());
let rt = &mut app.updates_rt;
if rt.result_open {
match CheckResultDialog::new(&crate::UPDATE_APP, VERSION).show(ctx, rt.updater.status()) {
CheckResultResponse::Close => {
rt.result_open = false;
rt.updater.dismiss_status();
}
CheckResultResponse::CheckAgain => {
rt.result_echoed = false;
rt.check_requested = true;
}
CheckResultResponse::None => {}
}
}
match app.updates_rt.updater.show_if(ctx, clean) {
Action::OpenUrl(url) => ctx.open_url(egui::OpenUrl::new_tab(url)),
// The guarded close path asks about unsaved changes; the restart helper relaunches once the