Skip to content

Commit

Permalink
feat: Update download progress messaging to display sizes in MB
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuzat committed Dec 30, 2024
1 parent 57076fe commit d6ccaae
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/lib/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { check, Update } from '@tauri-apps/plugin-updater';
import { relaunch } from '@tauri-apps/plugin-process';
import { toast } from 'svelte-sonner';
import { message } from '@tauri-apps/plugin-dialog';
import { VERSION } from 'svelte/compiler';
import { getVersion } from '@tauri-apps/api/app';

export async function checkUpdate() {
Expand Down Expand Up @@ -31,23 +30,22 @@ export async function downloadAndInstall(update: Update) {
});
let downloaded = 0;
let contentLength = 0;
// alternatively we could also call update.download() and update.install() separately
await update.downloadAndInstall((event) => {
switch (event.event) {
case 'Started':
contentLength = event.data.contentLength ?? 0;
contentLength = (event.data.contentLength ?? 0) / 1e6;
console.log(`started downloading ${event.data.contentLength} bytes`);
toast.info(`Downloading update ${update.version}...`, {
id,
description: `Started downloading ${event.data.contentLength} bytes`
description: `Started downloading ${contentLength} MB`
});
break;
case 'Progress':
downloaded += event.data.chunkLength;
console.log(`downloaded ${downloaded} from ${contentLength}`);
toast.info(`Downloading update ${update.version}...`, {
id,
description: `Downloaded ${downloaded} / ${contentLength} bytes`
description: `Downloaded ${downloaded / 1e6} / ${contentLength} MB`
});
break;
case 'Finished':
Expand All @@ -59,8 +57,6 @@ export async function downloadAndInstall(update: Update) {
break;
}
});

console.log('update installed');
toast.success(`Update ${update.version} installed. Relaunching...`, {
id,
description: 'Update installed'
Expand Down

0 comments on commit d6ccaae

Please sign in to comment.