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

+44 -13
View File
@@ -136,6 +136,17 @@ pub fn install_kind(exe: &Path, appimage: Option<&Path>) -> Install {
if let Some(image) = appimage.filter(|p| p.is_file()) {
return Install::SelfUpdating(image.to_path_buf());
}
// A macOS app is signed whole: one file replaced inside it breaks the
// signature, so it is only ever replaced whole, by the person (the
// newer .dmg), never by this program (WB-pkg-3).
if exe
.ancestors()
.skip(1)
.take(3)
.any(|dir| dir.extension().is_some_and(|e| e == "app") && dir.join("Contents").is_dir())
{
return Install::PackageManaged("app".to_string());
}
if let Some(prefix) = exe.parent().and_then(Path::parent)
&& let Ok(text) = std::fs::read_to_string(prefix.join("share/wanderbooks/install-method"))
{
@@ -153,25 +164,20 @@ pub fn this_install() -> Result<Install, String> {
}
fn refuse_package_managed(manager: &str, what: &str) -> Failure {
if manager == "app" {
return format!(
"this is the macOS app, which is replaced whole and never one file at a time: get the newer Wanderbooks at {} and drag it over this one",
crate::newer::DOWNLOAD_PAGE
)
.into();
}
format!(
"this install is managed by {manager}, which also {what} it: use the package manager (our apt and dnf repositories keep every release, and the AUR keeps old PKGBUILDs)"
)
.into()
}
/// `1.2.3` as numbers; anything else (a pre-release, a `v`) is no version
/// of ours.
pub fn parse_version(text: &str) -> Option<(u64, u64, u64)> {
let mut parts = text.split('.');
let mut next = || -> Option<u64> {
let p = parts.next()?;
(!p.is_empty() && p.bytes().all(|b| b.is_ascii_digit()))
.then(|| p.parse().ok())
.flatten()
};
let v = (next()?, next()?, next()?);
parts.next().is_none().then_some(v)
}
pub use crate::newer::parse_version;
fn hex(bytes: &[u8]) -> String {
bytes.iter().map(|b| format!("{b:02x}")).collect()
@@ -966,6 +972,31 @@ mod tests {
);
}
/// WB-pkg-3: a macOS app is signed whole, so this program never
/// replaces a file inside one; the person replaces the whole app.
#[test]
fn a_macos_app_is_never_updated_in_place() {
let dir = tempfile::tempdir().unwrap();
let macos = dir.path().join("Wanderbooks.app/Contents/MacOS");
std::fs::create_dir_all(&macos).unwrap();
let exe = macos.join("wanderbooks");
std::fs::write(&exe, b"x").unwrap();
assert_eq!(
install_kind(&exe, None),
Install::PackageManaged("app".into())
);
let said = refuse_package_managed("app", "updates").to_string();
assert!(said.contains("replaced whole"), "{said}");
assert!(said.contains(crate::newer::DOWNLOAD_PAGE), "{said}");
// A folder that only happens to be called .app, with no bundle in
// it, is not one.
let plain = dir.path().join("tools.app/bin");
std::fs::create_dir_all(&plain).unwrap();
let exe = plain.join("wanderbooks");
std::fs::write(&exe, b"x").unwrap();
assert_eq!(install_kind(&exe, None), Install::SelfUpdating(exe));
}
#[test]
fn a_public_key_is_read_in_every_form_minisign_and_the_packager_write_it() {
let bare = "RWQdrs7W5/jf6drdD0G/ymxFmRWYAIOyggYlubz4NQzdQm5e/Fj0nrb0";