tauri-updater
Use when adding software auto-update to a Tauri 2 desktop app, or when users ask about tauri-plugin-updater integration, app update checking, distinguishing installer vs portable builds for updates, or generating update manifests for GitHub Releases.
luochang212 · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add luochang212/skill-zoo --skill tauri-updater技能说明
name: tauri-updater description: Use when adding software auto-update to a Tauri 2 desktop app, or when users ask about tauri-plugin-updater integration, app update checking, distinguishing installer vs portable builds for updates, or generating update manifests for GitHub Releases.
Tauri Updater
Overview
Add self-update to a Tauri 2 desktop app using tauri-plugin-updater. Covers macOS DMG, Windows NSIS (auto-install), and Windows portable (manual download link). Uses a GitHub Releases-hosted latest.json manifest with signed artifacts.
When to Use
- User asks to add "auto-update", "software update", "check for updates" to a Tauri app
- User asks about
tauri-plugin-updaterintegration - User wants to distinguish installer vs portable builds for update behavior
- User needs to generate update manifests for CI
Don't use for:
- Tauri 1.x apps (different updater API)
- Mobile apps (different update mechanisms)
- Apps distributed only via app stores (use store update mechanisms)
Architecture
Installer vs Portable
Tauri updater only works with installers (NSIS, MSI, DMG). Portable builds need a different path.
| Build | Update method | Implementation |
|---|---|---|
| macOS DMG | Auto-download + install | tauri-plugin-updater full flow |
| Windows NSIS | Auto-download + install | tauri-plugin-updater full flow |
| Windows Portable | Link to GitHub Releases | Button opens releases page |
Detecting portable at runtime: Use a Cargo feature flag:
# Cargo.toml
[features]
portable = []
// Rust command
#[tauri::command]
pub fn is_portable_build() -> bool {
cfg!(feature = "portable")
}
Normal build: cargo build --release
Portable build: cargo build --release --features portable
In lib.rs, conditionally register the updater plugin — skip it when the portable feature is active:
#[cfg(all(desktop, not(feature = "portable")))]
app.handle()
.plugin(tauri_plugin_updater::Builder::new().build())
.expect("Failed to register updater plugin");
When is_portable_build() returns true, the frontend shows a GitHub Releases link instead of the auto-update flow.
Implementation Steps
1. Generate Signing Key (one-time)
bun tauri signer generate -w ~/.tauri/<app-name>.key
Hit enter twice for empty password. Produces:
~/.tauri/<app-name>.key— private key → store as GitHub SecretTAURI_SIGNING_PRIVATE_KEY~/.tauri/<app-name>.key.pub— public key → paste intotauri.conf.json
Empty password is fine — the key lives in encrypted GitHub Secrets. Adding a password means also managing TAURI_SIGNING_PRIVATE_KEY_PASSWORD in CI.
2. Rust Backend
src-tauri/Cargo.toml:
[features]
portable = []
[dependencies]
tauri-plugin-updater = "2"
tauri-plugin-process = "2"
src-tauri/src/lib.rs:
// Always register process plugin (needed for relaunch after update)
.plugin(tauri_plugin_process::init())
.setup(|app| {
// Skip updater for portable builds
#[cfg(all(desktop, not(feature = "portable")))]
app.handle()
.plugin(tauri_plugin_updater::Builder::new().build())
.expect("Failed to register updater plugin");
Ok(())
})
Register is_portable_build as a Tauri command in the invoke handler.
Command file (e.g. commands/settings.rs):
#[tauri::command]
pub fn is_portable_build() -> bool {
cfg!(feature = "portable")
}
3. Tauri Configuration
src-tauri/tauri.conf.json:
{
"bundle": {
"createUpdaterArtifacts": true
},
"plugins": {
"updater": {
"pubkey": "<PUBLIC KEY FROM .pub FILE>",
"endpoints": [
"https://github.com/<owner>/<repo>/releases/latest/download/latest.json"
]
}
}
}
The releases/latest/download/ URL pattern uses GitHub's redirect to always serve the latest release's asset.
Update CSP connect-src to allow GitHub release asset domains:
connect-src 'self' ipc: http://ipc.localhost https://api.github.com https://github.com https://objects.githubusercontent.com https://github-releases.githubusercontent.com
src-tauri/capabilities/default.json — add permissions:
{
"permissions": [
"updater:default",
"process:default",
"process:allow-restart"
]
}
4. Frontend
Install:
bun add @tauri-apps/plugin-updater@^2 @tauri-apps/plugin-process@^2
State machine:
idle → checking → up-to-date
→ downloading → ready-to-restart
→ available (download retry) → downloading → ready-to-restart
→ error → idle (retry)
Portable: always shows "GitHub Releases" link button
| State | UI | Action |
|---|---|---|
idle | "Check for Updates" button | check() |
checking | Spinner, disabled button | Wait |
up-to-date | "Up to date" | None |
downloading | Version number + cumulative byte progress | Wait |
available | Version number + "Download & Install" | Retry downloadAndInstall() after a download failure |
ready-to-restart | "Restart Now" button | relaunch() |
error | Friendly message + Retry | check() |
Key API details:
check()returnsnullwhen up-to-date (not an error)check()throws on network failure or 404 (manifest doesn't exist yet) — show friendly message, not raw errordownloadAndInstall()progress callback: useevent.data.chunkLength(notposition/length). Track cumulative bytes with a state updater.- Store the
Updateobject in auseRefto avoid stale closure in the progress callback.
Error handling pattern — never expose raw errors:
try {
const result = await check();
if (result) { /* downloadAndInstall() immediately */ }
else { /* up-to-date */ }
} catch {
// Network error, 404, rate limit, etc.
setStatus("error"); // shows friendly t("updater.error") message
}
5. CI Pipeline
**Bui
阅读完整来源 ↗