-
Notifications
You must be signed in to change notification settings - Fork 1
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
8 changed files
with
93 additions
and
21 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { checkUpdate, installUpdate, onUpdaterEvent } from '@tauri-apps/api/updater' | ||
import { invoke } from '@tauri-apps/api/tauri'; | ||
import { emit } from '@tauri-apps/api/event'; | ||
import { dialog, app } from '@tauri-apps/api'; | ||
import { relaunch } from '@tauri-apps/api/process' | ||
|
||
import Swal from "sweetalert2"; | ||
import * as data from "./data.ts"; | ||
|
||
const unlisten = await onUpdaterEvent(({ error, status }) => { | ||
// This will log all updater events, including status updates and errors. | ||
console.log('Updater event', error, status) | ||
if (status == "DONE") { Swal.close() } // To close Swal. | ||
}) | ||
|
||
try { | ||
const { shouldUpdate, manifest } = await checkUpdate() | ||
if (shouldUpdate) { | ||
// You could show a dialog asking the user if they want to install the update here. | ||
console.log("We received a update."); | ||
console.log(manifest); | ||
const choice = await dialog.ask(`新版本:BiliTools v${manifest?.version} 可用!当前版本:v${await app.getVersion()}。 | ||
\n您想要现在更新吗? | ||
\n更新发布时间:${manifest?.date} | ||
\n更新说明:\n${manifest?.body} | ||
\n注意:更新期间将无法使用APP。 | ||
更新下载完成后,将会自动重启应用以完成更新。`, "更新"); | ||
if (choice) { | ||
Swal.fire({ | ||
title: "正在下载更新...", | ||
allowOutsideClick: false, | ||
didOpen: () => { | ||
Swal.showLoading(); | ||
}, | ||
}); | ||
// Kill aria2c. | ||
invoke("handle_aria2c", { action: "kill", secret: data.secret }) | ||
// Install the update. This will also restart the app on Windows! | ||
await installUpdate() | ||
// On macOS and Linux you will need to restart the app manually. | ||
// You could use this step to display another confirmation dialog. | ||
await relaunch() | ||
} | ||
} | ||
} catch (e) { emit("error", e) } | ||
|
||
// you need to call unlisten if your handler goes out of scope, for example if the component is unmounted. | ||
unlisten() |
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