更新(updater)
定制自动更新流程。
当 tauri.conf.json
中的 build.withGlobalTauri
设置为 true
时,该包也可以通过 window.__TAURI__.updater
访问。
Interfaces
UpdateManifest
Since: 1.0.0
-
body:
string
定义在: updater.ts:34
-
date:
string
定义在: updater.ts:33
-
version:
string
定义在: updater.ts:32
UpdateResult
Since: 1.0.0
属性
-
Optional
manifest:UpdateManifest
定义在: updater.ts:41
-
shouldUpdate:
boolean
定义在: updater.ts:42
UpdateStatusResult
Since: 1.0.0
属性
-
Optional
error:string
定义在: updater.ts:24
-
status:
UpdateStatus
定义在: updater.ts:25
Type Aliases
UpdateStatus
-
UpdateStatus:
"PENDING"
|"ERROR"
|"DONE"
|"UPTODATE"
Since: 1.0.0
定义在: updater.ts:18
Functions
checkUpdate
-
checkUpdate():
Promise
<UpdateResult
>
检查是否有更新可用。
示例
import { checkUpdate } from '@tauri-apps/api/updater';
const update = await checkUpdate();
// now run installUpdate() if needed
Since: 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();
}
Since: 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();
Since: 1.0.2
参数
名称 |
类型 |
|
( |
返回: Promise
<UnlistenFn
>
一个 Promise,解析为用于停止监听事件的函数。请注意,如果监听器超出范围(例如组件被卸载),则需要移除监听器。