show progress

pull/351/head
Lucas Nogueira 2 years ago
parent bf92af354b
commit 16abdbfcf8
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

@ -3603,6 +3603,7 @@ checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5"
[[package]] [[package]]
name = "tauri" name = "tauri"
version = "2.0.0-alpha.8" version = "2.0.0-alpha.8"
source = "git+https://github.com/tauri-apps/tauri?branch=feat/channel#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -3658,6 +3659,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-build" name = "tauri-build"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=feat/channel#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cargo_toml", "cargo_toml",
@ -3678,6 +3680,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-codegen" name = "tauri-codegen"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=feat/channel#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
dependencies = [ dependencies = [
"base64 0.21.0", "base64 0.21.0",
"brotli", "brotli",
@ -3702,6 +3705,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-macros" name = "tauri-macros"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=feat/channel#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
dependencies = [ dependencies = [
"heck 0.4.1", "heck 0.4.1",
"proc-macro2", "proc-macro2",
@ -3893,6 +3897,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime" name = "tauri-runtime"
version = "0.13.0-alpha.4" version = "0.13.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=feat/channel#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
dependencies = [ dependencies = [
"gtk", "gtk",
"http", "http",
@ -3913,6 +3918,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime-wry" name = "tauri-runtime-wry"
version = "0.13.0-alpha.4" version = "0.13.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=feat/channel#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"gtk", "gtk",
@ -3932,6 +3938,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-utils" name = "tauri-utils"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=feat/channel#9122e27ed863a5cb2bf13dc0dd0433c7387e141b"
dependencies = [ dependencies = [
"aes-gcm", "aes-gcm",
"brotli", "brotli",

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

Loading…
Cancel
Save