7 个版本
| 0.2.0 | 2024 年 6 月 5 日 | 
|---|---|
| 0.1.4 | 2024 年 1 月 30 日 | 
| 0.1.1 | 2023 年 12 月 27 日 | 
| 0.0.0 | 2023 年 9 月 4 日 | 
#359 在 加密学
73KB
 1K  SLoC
cargo-packager-updater
由 cargo-packager 打包的应用程序更新器。
检查更新
您可以使用 check_update 函数或使用 Updater 构建 UpdaterBuilder 来检查更新,这两种方法都需要当前应用程序的版本和一个 Config,该配置指定了请求更新的端点和更新签名的公钥。
use cargo_packager_updater::{check_update, Config};
let config = Config {
  endpoints: vec!["http://myserver.com/updates".parse().unwrap()],
  pubkey: "<pubkey here>".into(),
  ..Default::default()
};
if let Some(update) = check_update("0.1.0".parse().unwrap(), config).expect("failed while checking for update") {
  update.download_and_install().expect("failed to download and install update");
} else {
  // there is no updates
}
端点
每个端点可以可选地包含 {{arch}}、{{target}} 或 {{current_version}},这些值将在向端点发出请求之前检测并替换为相应的值。
- {{current_version}}:请求更新的应用程序的版本。
- {{target}}:操作系统名称(其中一个是- linux、- windows或- macos)。
- {{arch}}:机器的架构(以下是其中的一个:- x86_64、- i686、- aarch64或- armv7)。
例如
 "https://releases.myapp.com/{{target}}/{{arch}}/{{current_version}}"
将转换为
 "https://releases.myapp.com/windows/x86_64/0.1.0"
如果您需要更多信息,可以设置额外的请求头 UpdaterBuilder::header 以满足您的需求。
端点响应
更新器期望端点以两种可能的响应进行响应
- 204 No Content在没有可用的更新时。
- 200 OK和一个可能的 JSON 响应,该响应可以是代表所有可用平台更新的 JSON,或者如果使用端点变量(见上方)或附加当前更新器目标头,则可以仅返回请求目标的信息。
预期的 JSON 响应应设置以下字段
- version:必须是有效的 semver,可以带或不带前缀- v``, 这意味着1.0.0- 和v1.0.0` 都是有效的。
- url或- platforms.[target].url:必须是更新包的有效 URL。
- signature或- platforms.[target].signature:必须是生成的- .sig文件的内容。签名可能每次运行构建您的应用程序时都会更改,因此请确保始终更新它。
- format或- platforms.[target].format:必须是- app、- appimage、- nsis或- wix之一。
[!NOTE] 如果使用
platforms对象,则每个键都采用OS-ARCH格式,其中OS是linux、macos或windows之一,而ARCH是x86_64、aarch64、i686或armv7之一,请参阅下面的示例。
它还可以包含这些可选字段
- notes:在此处可以添加有关更新的说明,如发布说明。
- pub_date:如果存在,则必须根据 RFC 3339 进行格式化。
以下为两个预期的 JSON 格式的示例
- 
所有平台的 JSON { "version": "v1.0.0", "notes": "Test version", "pub_date": "2020-06-22T19:25:57Z", "platforms": { "darwin-x86_64": { "signature": "Content of app.tar.gz.sig", "url": "https://github.com/username/reponame/releases/download/v1.0.0/app-x86_64.app.tar.gz", "format": "app" }, "darwin-aarch64": { "signature": "Content of app.tar.gz.sig", "url": "https://github.com/username/reponame/releases/download/v1.0.0/app-aarch64.app.tar.gz", "format": "app" }, "linux-x86_64": { "signature": "Content of app.AppImage.sig", "url": "https://github.com/username/reponame/releases/download/v1.0.0/app-amd64.AppImage.tar.gz", "format": "appimage" }, "windows-x86_64": { "signature": "Content of app-setup.exe.sig or app.msi.sig, depending on the chosen format", "url": "https://github.com/username/reponame/releases/download/v1.0.0/app-x64-setup.nsis.zip", "format": "nsis or wix depending on the chosen format" } } }
- 
单个平台的 JSON { "version": "0.2.0", "pub_date": "2020-09-18T12:29:53+01:00", "url": "https://mycompany.example.com/myapp/releases/myrelease.tar.gz", "signature": "Content of the relevant .sig file", "format": "app or nsis or wix or appimage depending on the release target and the chosen format", "notes": "These are some release notes" }
Windows 上的更新安装模式
您可以使用 WindowsConfig::install_mode 指定 Windows 上的安装模式,可以是以下之一
- "Passive":将有一个带有进度条的窗口。更新将安装而无需任何用户交互。通常推荐,也是默认模式。
- "BasicUi":将显示一个基本用户界面,需要用户交互来完成安装。
- "Quiet":不会向用户反馈进度。在此模式下,安装程序无法自行请求管理员权限,因此它只能在用户级安装或您的应用程序本身已运行具有管理员权限的情况下工作。一般不推荐使用。
许可证
适用于适用的 MIT 或 MIT/Apache 2.0。
依赖关系
~6–24MB
~359K SLoC