跳至主要内容

更新程序

自定义自动更新流程。

当 `tauri.conf.json` 中的 build.withGlobalTauri 设置为 true 时,也可以通过 `window.__TAURI__.updater` 访问此包。

接口

UpdateManifest

: 1.0.0

属性

body

body: string

定义于: updater.ts:34

date

date: string

定义于: updater.ts:33

version

version: string

定义于: updater.ts:32

UpdateResult

: 1.0.0

属性

manifest

可选 manifest: UpdateManifest

定义于: updater.ts:41

shouldUpdate

shouldUpdate: boolean

定义于: updater.ts:42

UpdateStatusResult

: 1.0.0

属性

error

可选 error: string

定义于: updater.ts:24

status

status: UpdateStatus

定义于: updater.ts:25

类型别名

UpdateStatus

UpdateStatus: "PENDING"| "ERROR" | "DONE" | "UPTODATE"

: 1.0.0

定义于: updater.ts:18

函数

checkUpdate

checkUpdate(): Promise<UpdateResult>

检查是否有可用的更新。

示例

import { checkUpdate } from '@tauri-apps/api/updater';
const update = await checkUpdate();
// now run installUpdate() if needed

: 1.0.0

返回: Promise<UpdateResult>

解析为更新状态的 Promise。

installUpdate

installUpdate(): Promise<void>

如果存在可用更新,则安装更新。

示例

import { checkUpdate, installUpdate } from '@tauri-apps/api/updater';
const update = await checkUpdate();
if (update.shouldUpdate) {
console.log(`Installing update ${update.manifest?.version}, ${update.manifest?.date}, ${update.manifest.body}`);
await installUpdate();
}

: 1.0.0

返回: Promise<void>

指示操作成功或失败的 Promise。

onUpdaterEvent

onUpdaterEvent(handler: fn): Promise<UnlistenFn>

监听更新程序事件。

示例

import { onUpdaterEvent } from "@tauri-apps/api/updater";
const unlisten = await onUpdaterEvent(({ error, status }) => {
console.log('Updater event', error, status);
});

// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

: 1.0.2

参数

名称类型
handler(status: UpdateStatusResult) => void

返回: Promise<UnlistenFn>

一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出作用域(例如组件卸载),则需要移除监听器。