跳至主要內容

更新器

自訂自動更新流程。

tauri.conf.json 中的 build.withGlobalTauri 設為 true 時,也可以透過 window.__TAURI__.updater 存取此套件。

介面

UpdateManifest

: 1.0.0

屬性

body

body: 字串

定義於: updater.ts:34

date

date: 字串

定義於: updater.ts:33

version

version: 字串

定義於: updater.ts:32

UpdateResult

: 1.0.0

屬性

manifest

可選 manifest: UpdateManifest

定義於: updater.ts:41

shouldUpdate

shouldUpdate: 布林值

定義於: updater.ts:42

UpdateStatusResult

: 1.0.0

屬性

error

Optional 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>

表示操作成功或失敗的承諾。

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>

解析為取消偵聽事件的函式的承諾。請注意,如果偵聽器超出範圍(例如卸載元件),則需要移除偵聽器。