-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,53 @@ | ||
import { check } from "@tauri-apps/plugin-updater"; | ||
import { openDialog } from "./message"; | ||
// import { relaunch } from "@tauri-apps/plugin-process"; | ||
import { openDialog, sendMessage } from "./message"; | ||
import { h, ref } from "vue"; | ||
import { toPercentage } from "./format"; | ||
|
||
export const checkUpdate = async () => { | ||
const update = await check(); | ||
if (update) { | ||
openDialog( | ||
`found update ${update.version} from ${update.date} with notes ${update.body}`, | ||
{ | ||
title: "更新提示" | ||
let date = "未知"; | ||
if (update.date) { | ||
date = update.date | ||
.replace(/\s+([+-]\d{2}:\d{2}):\d{2}$/, "$1") | ||
.replace(/(?<!\d)(\d)(?!\d)/, "0$1") | ||
.replace(" ", "T"); | ||
date = new Date(date).toLocaleString("zh-CN", { | ||
dateStyle: "long", | ||
timeStyle: "short" | ||
}); | ||
} | ||
openDialog(`更新至 <b>${update.version}</b> (${date})`, { | ||
lock: true, | ||
title: "发现新版本!", | ||
sureText: "更新并重启 Rockoon", | ||
onSure: async () => { | ||
const message = ref(""); | ||
const { close } = openDialog(() => h("p", message.value), { | ||
title: "更新中...", | ||
lock: true, | ||
footer: false | ||
}); | ||
let downloaded = 0; | ||
let contentLength = 0; | ||
await update.downloadAndInstall(event => { | ||
switch (event.event) { | ||
case "Started": | ||
contentLength = event.data.contentLength ?? 0; | ||
message.value = "开始下载..."; | ||
break; | ||
case "Progress": | ||
downloaded += event.data.chunkLength; | ||
message.value = `下载中... ${toPercentage(downloaded / contentLength)}`; | ||
break; | ||
case "Finished": | ||
message.value = `下载完成!`; | ||
break; | ||
} | ||
}); | ||
close(); | ||
sendMessage("更新完成!请重启 Rockoon"); | ||
} | ||
); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters