Tauri v2 更新程序
// Making new app versions available to users automatically.
// 自动将新应用版本提供给用户。
As of writing this post, the beta release of Tauri v2 is available, and I’m helping build a desktop app using it.
截至撰写本文时,Tauri v2 的 beta 版本已可用,我正在帮助构建一个使用它的桌面应用程序。
This post will outline how we implemented a basic version of the Tauri updater. Our app has a Next.js (static site) on the frontend. It’s backed by an independent FastAPI server running on render.com.
这篇文章将概述我们如何实现 Tauri 更新器的基本版本。我们的应用在前端有一个 Next.js(静态网站)。它由一个独立的 FastAPI 服务器支持,该服务器运行在 render.com 上。
TL;DR
简而言之
We release new versions of our app using GitHub Actions and GitHub Releases. We have a ‘publish’ GitHub action workflow which uses the official @tauri-apps/tauri-action GitHub action to build and sign the app. Once this is done, the workflow drafts a new release on GitHub and uploads the built assets to the release.
我们使用 GitHub Actions 和 GitHub Releases 发布我们应用的新版本。我们有一个 'publish' GitHub action 工作流,它使用 官方 @tauri-apps/tauri-action GitHub action 来构建和签名应用。一旦完成,该工作流将在 GitHub 上草拟一个新版本并将构建的资产上传到该版本。
One of the files uploaded to this GitHub release is a latest.json
file which contains the version number and download URLs of the latest release as required by the Tauri updater. I could not figure out how to read the raw version of this file directly from the release using the API (I know you can do it from a repo - so you could also consider committing this file to a branch). As a workaround, we use our FastAPI server to download the latest release file from the GitHub release and then serve up the contents of it via an internal API.
上传到此 GitHub 版本的文件之一是 latest.json
文件,其中包含最新版本的版本号和下载 URL,这是 Tauri 更新程序所需的。我无法通过 API 直接从版本中读取此文件的原始版本(我知道您可以从仓库中做到这一点 - 因此您也可以考虑将此文件提交到一个分支)。作为变通办法,我们使用我们的 FastAPI 服务器从 GitHub 版本下载最新的版本文件,然后通过内部 API 提供其内容。
When the app starts, it makes a request to the FastAPI server to get the latest release information. If the version of the latest release is greater than the current version, the app will prompt the user to update to the new version. If the user decide...