feat(app): the window tells when a newer version exists and where to get it (P15 C1)

Update is an ordinary app update: the newer package installed over the
old one. The program's part is to say one exists. Once a day, on a
thread of its own, it reads one small file a release publishes
(latest.json: only a version number is taken from it; where to get the
update is a fixed address in the program) and notes the answer in the
data root's updates folder. A higher x.y.z shows a standing notice with
a button that opens the download page and the words that books, keys
and connections stay. Check for updates does the same look at once on
every platform; where a program may replace itself with a signed release
it also stages one as before. A macOS app is never replaced one file at
a time (that breaks its signature): it is treated as managed, and says
to drag the new app over the old. Window prose names the product
Wanderbooks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 15:35:17 -07:00
1 parent 2bc442f795
commit 90f663ed54
8 files changed
+510 -49

No files matched your search

+76 -6
View File
@@ -474,6 +474,11 @@ pub trait Owner: Send + Sync {
fn check_for_updates(&self) -> Result<Vec<String>, String> {
Err("not here".into())
}
/// A newer version exists, and where to get it (WB-pkg-3): what the
/// program's daily look found. Cheap: called every few seconds.
fn newer_version(&self) -> Option<NewerVersion> {
None
}
/// Accept the waiting update: the books' host installs it and restarts
/// onto it when no call is running, the books staying open.
fn apply_update(&self) -> Result<Vec<String>, String> {
@@ -486,6 +491,16 @@ pub trait Owner: Send + Sync {
}
}
/// A newer version of the program that the person may get and install over
/// this one (WB-pkg-3).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NewerVersion {
/// Its version.
pub version: String,
/// The page to get it from: the program's own, never a feed's.
pub page: String,
}
/// The Claude desktop extension the Connect page made (WB-pkg-5).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ExtensionMade {
@@ -642,6 +657,8 @@ pub struct OwnerMenu {
/// The update waiting, as last read, and when (re-read every few
/// seconds and after any job).
update: Option<(std::time::Instant, Option<UpdateWaiting>)>,
/// A newer version the person may get, as last read, and when.
newer: Option<(std::time::Instant, Option<NewerVersion>)>,
/// The tab's threads: every job is one of them (INVARIANT 6).
jobs: crate::jobs::Spawner,
}
@@ -687,6 +704,23 @@ impl OwnerMenu {
self.update.as_ref().and_then(|(_, u)| u.clone())
}
/// A newer version to get, if any (read now and then, not every frame).
fn newer_version(
&mut self,
ctx: &egui::Context,
owner: &Arc<dyn Owner>,
) -> Option<NewerVersion> {
if self
.newer
.as_ref()
.is_none_or(|(at, _)| at.elapsed() > UPDATE_LOOK)
{
self.newer = Some((std::time::Instant::now(), owner.newer_version()));
}
ctx.request_repaint_after(UPDATE_LOOK);
self.newer.as_ref().and_then(|(_, n)| n.clone())
}
/// The standing notices above the page: an update waiting for the
/// owner's accept, and a format upgrade the books wait for, whose
/// go-ahead is asked for once each open (INVARIANT 5).
@@ -708,7 +742,7 @@ impl OwnerMenu {
ui.horizontal_wrapped(|ui| {
ui.label(
RichText::new(format!(
"{} Version {} of wanderbooks is ready.",
"{} Version {} of Wanderbooks is ready.",
icon::ARROW_FAT_UP,
update.version
))
@@ -738,12 +772,48 @@ impl OwnerMenu {
ui.ctx(),
(
"Update".into(),
Effect::Changes("Updating wanderbooks"),
Effect::Changes("Updating Wanderbooks"),
work,
),
);
}
}
// No update of the program's own is waiting: is a newer version
// out for the person to get and install over this one?
else if let Some(newer) = self.newer_version(ui.ctx(), &owner) {
let p = crate::theme::pal(ui.ctx());
egui::Frame::new()
.fill(p.warning_soft)
.inner_margin(egui::Margin::symmetric(20, 10))
.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal_wrapped(|ui| {
ui.label(
RichText::new(format!(
"{} Version {} of Wanderbooks is available.",
icon::ARROW_FAT_UP,
newer.version
))
.font(crate::theme::semibold(13.0))
.color(p.warning),
);
ui.label(
RichText::new(
"Download it and install it over this one. Your books, keys and connections stay as they are.",
)
.font(crate::theme::regular(13.0))
.color(p.text),
);
if ui
.button("Open the download page")
.on_hover_text(newer.page.clone())
.clicked()
{
ui.ctx().open_url(egui::OpenUrl::new_tab(newer.page.clone()));
}
});
});
}
let Some(upgrade) = books.format_upgrade.clone() else {
return;
};
@@ -771,7 +841,7 @@ impl OwnerMenu {
);
ui.label(
RichText::new(
"An older version of wanderbooks wrote them. They work on their old format until you agree; what needs the new one is refused.",
"An older version of Wanderbooks wrote them. They work on their old format until you agree; what needs the new one is refused.",
)
.font(crate::theme::regular(13.0))
.color(p.text),
@@ -886,7 +956,7 @@ impl OwnerMenu {
ui.separator();
if ui
.button(format!("{} Check for updates", icon::ARROWS_CLOCKWISE))
.on_hover_text("Look for a newer version of wanderbooks now")
.on_hover_text("Look for a newer version of Wanderbooks now")
.clicked()
{
let o = owner.clone();
@@ -905,7 +975,7 @@ impl OwnerMenu {
let o = owner.clone();
start = Some((
"Update".into(),
Effect::Changes("Updating wanderbooks"),
Effect::Changes("Updating Wanderbooks"),
Box::new(move || o.apply_update()),
));
}
@@ -1167,7 +1237,7 @@ fn upgrade_dialog(
ui.heading("Upgrade these books' format?");
ui.add_space(4.0);
ui.label(format!(
"An older version of wanderbooks wrote these books, in journal format {}. The upgrade adds {}.",
"An older version of Wanderbooks wrote these books, in journal format {}. The upgrade adds {}.",
form.upgrade.from.format,
form.upgrade.adds().join(", ")
));
+1 -1
View File
@@ -158,7 +158,7 @@ impl Welcome {
ui.vertical_centered(|ui| {
ui.set_max_width(640.0);
ui.add_space(36.0);
ui.label(RichText::new("Welcome to wanderbooks").font(crate::theme::bold(28.0)));
ui.label(RichText::new("Welcome to Wanderbooks").font(crate::theme::bold(28.0)));
ui.label(
RichText::new(
"Your company's books, kept by an assistant and checked by you. A few short steps; nothing here needs a terminal.",
+57 -2
View File
@@ -21,6 +21,7 @@ use std::sync::{Arc, Mutex, OnceLock};
struct Fake {
asked: Mutex<Vec<String>>,
staged: Mutex<bool>,
newer: Mutex<bool>,
}
impl Fake {
@@ -57,6 +58,12 @@ impl Owner for Fake {
staged_at: "2026-10-30T08:00:00Z".into(),
})
}
fn newer_version(&self) -> Option<ledger_gui::owner::NewerVersion> {
(*self.newer.lock().unwrap()).then(|| ledger_gui::owner::NewerVersion {
version: "9.2.0".into(),
page: "https://example.test/releases/latest".into(),
})
}
fn check_for_updates(&self) -> Result<Vec<String>, String> {
self.said("check");
*self.staged.lock().unwrap() = true;
@@ -159,7 +166,7 @@ fn the_menu_checks_for_updates_and_a_waiting_update_shows_a_notice_that_accepts(
// owner, and the notice goes once it is installed.
for _ in 0..60 {
h.run_steps(2);
if h.query_by_label_contains("Version 9.1.0 of wanderbooks is ready")
if h.query_by_label_contains("Version 9.1.0 of Wanderbooks is ready")
.is_some()
{
break;
@@ -167,7 +174,7 @@ fn the_menu_checks_for_updates_and_a_waiting_update_shows_a_notice_that_accepts(
std::thread::sleep(std::time::Duration::from_millis(100));
}
assert!(
h.query_by_label_contains("Version 9.1.0 of wanderbooks is ready")
h.query_by_label_contains("Version 9.1.0 of Wanderbooks is ready")
.is_some(),
"no notice"
);
@@ -194,3 +201,51 @@ fn books_outside_a_data_root_have_no_update_notice() {
assert!(h.query_by_label_contains("is ready.").is_none());
*f.staged.lock().unwrap() = false;
}
/// WB-pkg-3: with no update of the program's own waiting, a newer version
/// the daily look found is told in a standing notice that says where to
/// get it and that books, keys and connections stay; an update that is
/// waiting is the only notice shown (one at a time).
#[test]
fn a_newer_version_is_told_with_where_to_get_it() {
let _alone = alone();
let f = fake();
*f.newer.lock().unwrap() = true;
let (_dir, _book, b) = books(true);
let mut h = harness(b);
for _ in 0..60 {
h.run_steps(2);
if h.query_by_label_contains("Version 9.2.0 of Wanderbooks is available")
.is_some()
{
break;
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
assert!(
h.query_by_label_contains("Version 9.2.0 of Wanderbooks is available")
.is_some(),
"no notice"
);
assert!(
h.query_by_label_contains("Your books, keys and connections stay as they are")
.is_some()
);
assert!(h.query_by_label("Open the download page").is_some());
// One notice at a time: a staged update wins.
*f.staged.lock().unwrap() = true;
for _ in 0..60 {
h.run_steps(2);
if h.query_by_label_contains("is ready.").is_some() {
break;
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
assert!(h.query_by_label_contains("is ready.").is_some());
assert!(
h.query_by_label_contains("Version 9.2.0 of Wanderbooks is available")
.is_none()
);
*f.staged.lock().unwrap() = false;
*f.newer.lock().unwrap() = false;
}