|
| 1 | +# Updater module |
| 2 | + |
| 3 | +Custom macOS updater that syncs files *into* the existing `.app` bundle, preserving its inode and |
| 4 | +`com.apple.macl` xattr so macOS TCC (Full Disk Access) permissions survive across updates. |
| 5 | + |
| 6 | +Compiled only on macOS (`#[cfg(target_os = "macos")]`). On other platforms, the Tauri updater plugin handles updates |
| 7 | +and the frontend calls the plugin API directly. |
| 8 | + |
| 9 | +## File map |
| 10 | + |
| 11 | +| File | Purpose | |
| 12 | +|------|---------| |
| 13 | +| `mod.rs` | Three Tauri commands (`check_for_update`, `download_update`, `install_update`) and shared `UpdateState` | |
| 14 | +| `manifest.rs` | Parses `latest.json`, compares versions, resolves platform key | |
| 15 | +| `signature.rs` | Minisign signature verification (base64-wrapped, matching Tauri's format) | |
| 16 | +| `installer.rs` | Extracts tarball, syncs into running bundle, handles privilege escalation | |
| 17 | + |
| 18 | +## Key decisions |
| 19 | + |
| 20 | +**Decision**: Sync files into the bundle instead of replacing the `.app` directory. |
| 21 | +**Why**: Replacing the bundle changes its inode, which causes macOS TCC to lose FDA grants. Users would have to |
| 22 | +re-grant Full Disk Access after every update. |
| 23 | + |
| 24 | +**Decision**: Sync order is Resources, Info.plist, _CodeSignature, then MacOS binary last. |
| 25 | +**Why**: Updating the binary last minimizes the window where the code signature is inconsistent with the binary on |
| 26 | +disk. If the app crashes mid-update, the old binary is still intact. |
| 27 | + |
| 28 | +**Decision**: Unconditional deletion of stale files after sync. |
| 29 | +**Why**: Old files left behind could cause version mismatches or bloat. The deletion pass removes anything in the |
| 30 | +destination that isn't in the source, then cleans up empty directories bottom-up. |
| 31 | + |
| 32 | +**Decision**: Minisign verification before writing tarball to disk. |
| 33 | +**Why**: Ensures integrity and authenticity of the update. The public key is compiled into the binary. Both key and |
| 34 | +signatures use base64(minisign-text-format) encoding, matching Tauri's internal convention. |
| 35 | + |
| 36 | +**Decision**: Privilege escalation via `osascript` with `rsync -a --delete`. |
| 37 | +**Why**: When the app is installed in `/Applications` (owned by root), direct writes fail. `osascript`'s |
| 38 | +`do shell script ... with administrator privileges` shows the native macOS auth dialog. `rsync` is used because it |
| 39 | +expresses the full sync (copy + delete stale) in a single shell command. |
| 40 | + |
| 41 | +## Key patterns and gotchas |
| 42 | + |
| 43 | +- **macOS-only.** The module, command registrations, and `UpdateState` are all gated with `#[cfg(target_os = "macos")]`. |
| 44 | + On non-macOS, the frontend uses `@tauri-apps/plugin-updater` directly. |
| 45 | +- **Staging dir is `/tmp/cmdr-update-staging`.** Cleaned before and after install. If the app crashes mid-install, |
| 46 | + leftover staging doesn't block the next attempt (it gets cleaned on retry). |
| 47 | +- **Privilege escalation via `osascript`.** Only triggers when direct writes to `/Applications/Cmdr.app` are denied. |
| 48 | + Users who run from `~/Applications` or a dev build won't see the auth dialog. |
| 49 | +- **CI guard.** `check_for_update` returns `None` when the `CI` env var is set, avoiding network calls in tests. |
| 50 | +- **Manifest URL is hardcoded** (`https://getcmdr.com/latest.json`), not configurable from the frontend. |
| 51 | + |
| 52 | +## Dependencies |
| 53 | + |
| 54 | +- `reqwest` -- HTTP client for manifest and tarball download |
| 55 | +- `minisign-verify` -- signature verification |
| 56 | +- `flate2`, `tar` -- tarball extraction |
| 57 | +- `filetime` -- touching the bundle after install to trigger LaunchServices refresh |
| 58 | +- `base64` -- decoding the double-encoded minisign key and signatures |
0 commit comments