用途:为 Tauri 2 桌面应用接入自动更新,使用 tauri-plugin-updater,通过 GitHub Releases 托管带签名的 latest.json 清单。适用于用户要求添加自动更新、检查更新,或询问 tauri-plugin-updater 集成、区分安装版与便携版更新行为、为 CI 生成更新清单的场景。不适用于 Tauri 1.x、移动应用或仅通过应用商店分发的应用。
主要能力:安装版(macOS DMG、Windows NSIS)走自动下载安装流程;Windows 便携版改为打开 GitHub Releases 链接。用 Cargo feature 标记 portable,运行时通过 is_portable_build() 判断,便携构建不注册 updater 插件。前端状态机覆盖 idle、checking、up-to-date、downloading、available、ready-to-restart、error。
必要用法:一次性生成签名密钥 bun tauri signer generate -w ~/.tauri/<app-name>.key,私钥存为 GitHub Secret TAURI_SIGNING_PRIVATE_KEY,公钥写入 tauri.conf.json。依赖 tauri-plugin-updater 与 tauri-plugin-process,配置 createUpdaterArtifacts、endpoints 指向 releases/latest/download/latest.json,CSP connect-src 需放行 GitHub 资源域名,capabilities 添加 updater:default、process:default、process:allow-restart。前端安装 @tauri-apps/plugin-updater 与 @tauri-apps/plugin-process。CI 中传入签名密钥、重命名更新产物、用 --features portable 重建便携版、用 jq 生成 latest.json 并上传。
限制与注意:check() 返回 null 表示已是最新而非错误;网络失败或 404 需捕获并显示友好提示;进度回调使用 event.data.chunkLength;Update 对象应存入 useRef 避免闭包过期;首次发布用户需手动下载,之后才自动更新;签名校验失败通常因公钥与 CI 私钥不匹配。具体价格、平台支持范围等资料未提供。