macOS updater: let the app show update progress and choose when to restart

Open
#936 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
macos, typescript, zig
Domain
api, desktop-dev

Research direction

Start in the macOS updater’s download timer, stock-sheet progress UI, and installDownloadedUpdate path, then trace the existing app.check-for-updates command and PlatformServices.checkForUpdates API. Define the update-state machine and app-facing configuration before wiring Zig, TypeScript, and built-in command/event surfaces. Done means progress is determinate, app-driven check/download/cancel/install flows work, staged bundles are validated and cleaned up, and the documented state and error behavior are covered by tests.

Written by the indexing model from the issue text.

Description

#169 asked for update effects the app controls: check, download, download progress, and install and relaunch. The updater from #398 does the checks and the swap, but it gives the app none of those effects. This issue is about that missing part.

The problem

After the user clicks Install Update, the macOS updater shows a sheet on the app's window until the whole ZIP has downloaded. The sheet's progress bar is indeterminate. The sheet is also window-modal, so the app can't be used while the download runs. A large update takes minutes, and the app looks frozen. When the download finishes, the updater checks it, starts the install script, and quits the app right away. This is true in 0.11.1 and on current main.

The app can't change any of this. Its only hook is the reserved app.check-for-updates command, or PlatformServices.checkForUpdates. It gets no event when an update is found, while it downloads, or when it is ready. It also can't start the download or the restart itself.

Sage, a Native SDK 0.11.1 app, has a 230 MB update ZIP. We'd like its updates to work like they do in many Mac apps. A sidebar item reads Install update. Clicking it downloads the ZIP in the background while the item shows progress. Then the item reads Restart to update, and the user restarts when they're ready.

The updater already has most of what this needs:

  • The signed feed gives archive_bytes.
  • updateDownloadLimitTimerFired already reads countOfBytesReceived every 0.1 seconds, to cap the download size.
  • installDownloadedUpdate already checks and stages the new bundle before it starts the install script.

The proposal

1. A real progress bar in the stock sheet

This is the smallest change. Make the sheet's NSProgressIndicator determinate, with maxValue set to archive_bytes, and update it from the timer that already runs. Apps that keep the stock sheets get real progress with no work.

2. An update API for apps

Let an app turn off the stock sheets and drive the updater itself, for example with "updates": { "ui": "app" } in app.json. With it on, the updater shows no sheets, and the app gets:

  • A state it can read and subscribe to: idle, checking, available (version and release notes), downloading (bytes received and total bytes), ready (version), and failed (an error code and message).
  • Four calls: check (quiet or user-initiated), download (starts the download in the background), cancel, and install (swaps in the staged bundle and relaunches).

A WebView page could reach these as built-in commands, such as native-sdk.updates.check, native-sdk.updates.download, native-sdk.updates.cancel, native-sdk.updates.install, and native-sdk.updates.state, plus an event when the state changes. A TypeScript core could get a Cmd for each call and a Sub for the state. A Zig core could get matching PlatformServices functions and an app event.

ready would mean every check in installDownloadedUpdate has passed: size, SHA-256, extraction, one top-level .app, bundle ID and version, and the codesign requirement when the app has a team ID. The staged bundle waits in the folder the updater already uses, .<App>.app.native-update-<uuid> next to the app, until the app calls install.

Notes

  • No feed changes. All of this happens in the installed app, so the signed feed and native update sign stay as they are. That matters because verifyEnvelope rejects unknown fields, and installed copies must keep reading the feed.
  • Quitting with an update ready. If the user quits without restarting, the updater could swap in the new bundle as the app quits, without reopening it. Or it could keep the staged bundle for the next launch. Either works, as long as the app knows which one happens.
  • Leftover staging folders. If the app quits or crashes while an update is staged, the next launch should delete the staging folder, or reuse it if it still matches the newest feed.
  • The app's quit path. install should quit through the normal terminate path, as installDownloadedUpdate does today. Apps can then stop their child processes and save their state first.
  • Why not in the app. An app can already check the feed with updater.verifyEnvelope and the ZIP with native_sdk_update_verify_archive. But it would still need its own downloader, staging folder, cleanup, and copy of the install script. The updater already does this safely, and two copies of the swap logic would drift apart.
Dominant language
Zig
Stars
7.9k
Forks
335
Avg merge
10h 33m
Merged PRs (30d)
147

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel-labs/native

All issues in vercel-labs/native

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.