JFLib

18. Updates#

lib/update (UPDATES.md) brings signed updates with a rollback to any app. The app builds an update::Config (its id, version -- rt::app_version!(), the version= of its PACKAGE -- the address of update.json and the Ed25519 public keys of its publisher, as hex constants in the code), calls update::startup(&cfg) first in ui::main! and update::healthy(&cfg) once it works:

ui::main!({
    if let update::Startup::RolledBack(v) = update::startup(&update_config()) {
        // version v did not start and was rolled back: tell the user
    }
    ui::launch(&DESC, App::default(), &style::STYLE)
});
  • update::Updater::new(cfg) -- start_check() / start_download() run on a thread and wake the UI (UIC_WAKE); status() has the phase (Available, Downloading with done / total, Ready, Failed with the error) for a dialog or a status line; cancel(); apply() puts the update in place now and restarts the program.
  • A downloaded update is put in place by the next startup(), which restarts into it. The new version runs on trial until healthy(); a start that finds the trial still open restores the old files and restarts the old version, which learns of it through Startup::RolledBack.
  • Everything is checked against the signature (tools/update_manifest.py writes and signs the channel, tools/package.py --update DIR does it per style); the downloads go through the app's net.connect rules. Putting files in place needs a writable program folder (fs.write $EXE/** in PERMISSIONS); programs in system folders use package updates.
  • The same calls follow the way the program is installed (update::install(&cfg), a plat::pkg::Packaged): an AppImage replaces its .AppImage file with the channel's appimage entry (trial and rollback as above; a signed AppImage only takes one signed with the same key; a folder the user cannot write is Error::ReadOnly; fs.write $APPIMAGE/**), a Flatpak checks and installs through the Flatpak portal (Kind::Flatpak; apply() starts the new version), and an MSIX package or a Snap answers Check::Managed(..): App Installer, the Store or snapd update it (UPDATES.md, "Packages"). On macOS a program in an app bundle takes the channel's app entry: the whole NAME.app is replaced in one step after its signature checked against the installed one (UPDATES.md, "macOS app bundles").
  • Windows and Linux on ARM64 (ARM64.md) are targets of their own in the channel, windows-aarch64 and linux-aarch64 (update::target()): tools/package.py APP --arch aarch64 --update DIR adds their files to the channel the x86-64 run wrote for the same version, so one update.json serves both processors and each program takes its own entry.

Source: docs/GUIDE.md in the JFLib repository.