|
|
@ -1,10 +1,12 @@
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import { Update, check } from "tauri-plugin-updater-api";
|
|
|
|
import { check } from "tauri-plugin-updater-api";
|
|
|
|
import { relaunch } from "tauri-plugin-process-api";
|
|
|
|
import { relaunch } from "tauri-plugin-process-api";
|
|
|
|
|
|
|
|
|
|
|
|
export let onMessage;
|
|
|
|
export let onMessage;
|
|
|
|
|
|
|
|
|
|
|
|
let isChecking, isInstalling, newUpdate;
|
|
|
|
let isChecking, isInstalling, newUpdate;
|
|
|
|
|
|
|
|
let totalSize = 0,
|
|
|
|
|
|
|
|
downloadedSize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
async function checkUpdate() {
|
|
|
|
async function checkUpdate() {
|
|
|
|
isChecking = true;
|
|
|
|
isChecking = true;
|
|
|
@ -23,9 +25,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
async function install() {
|
|
|
|
async function install() {
|
|
|
|
isInstalling = true;
|
|
|
|
isInstalling = true;
|
|
|
|
|
|
|
|
downloadedSize = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await newUpdate.downloadAndInstall((res) => {
|
|
|
|
await newUpdate.downloadAndInstall((downloadProgress) => {
|
|
|
|
console.log("event", res);
|
|
|
|
switch (downloadProgress.event) {
|
|
|
|
|
|
|
|
case "Started":
|
|
|
|
|
|
|
|
totalSize = downloadProgress.data.contentLength;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Progress":
|
|
|
|
|
|
|
|
downloadedSize += downloadProgress.data.chunkLength;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finished":
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
onMessage("Installation complete, restarting...");
|
|
|
|
onMessage("Installation complete, restarting...");
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
|
@ -37,6 +49,8 @@
|
|
|
|
isInstalling = false;
|
|
|
|
isInstalling = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$: progress = totalSize ? Math.round((downloadedSize / totalSize) * 100) : 0;
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flex children:grow children:h10">
|
|
|
|
<div class="flex children:grow children:h10">
|
|
|
@ -45,19 +59,28 @@
|
|
|
|
{:else if !isInstalling && newUpdate}
|
|
|
|
{:else if !isInstalling && newUpdate}
|
|
|
|
<button class="btn" on:click={install}>Install update</button>
|
|
|
|
<button class="btn" on:click={install}>Install update</button>
|
|
|
|
{:else}
|
|
|
|
{:else}
|
|
|
|
<button
|
|
|
|
<div class="progress">
|
|
|
|
class="btn text-accentText dark:text-darkAccentText flex items-center justify-center"
|
|
|
|
<span>{progress}%</span>
|
|
|
|
><div class="spinner animate-spin" /></button
|
|
|
|
<div class="progress-bar" style="width: {progress}%" />
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
<style>
|
|
|
|
.spinner {
|
|
|
|
.progress {
|
|
|
|
height: 1.2rem;
|
|
|
|
width: 100%;
|
|
|
|
width: 1.2rem;
|
|
|
|
height: 50px;
|
|
|
|
border-radius: 50rem;
|
|
|
|
position: relative;
|
|
|
|
color: currentColor;
|
|
|
|
margin-top: 5%;
|
|
|
|
border: 2px dashed currentColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.progress > span {
|
|
|
|
|
|
|
|
font-size: 1.2rem;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.progress-bar {
|
|
|
|
|
|
|
|
height: 30px;
|
|
|
|
|
|
|
|
background-color: hsl(32, 94%, 46%);
|
|
|
|
|
|
|
|
border: 1px solid #333;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|