From 754f076f18fe89c3d3d4b4fa15340be9b9b8e7b2 Mon Sep 17 00:00:00 2001 From: Shreyas Date: Fri, 13 Jun 2025 11:11:37 +0530 Subject: [PATCH] fix(desktop): in-memory update progress polling (#5126) Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> --- .../hoppscotch-desktop/src/types/index.ts | 4 -- .../hoppscotch-desktop/src/utils/updater.ts | 57 ++++++++++--------- .../hoppscotch-desktop/src/views/Home.vue | 43 ++++++++++++-- 3 files changed, 67 insertions(+), 37 deletions(-) diff --git a/packages/hoppscotch-desktop/src/types/index.ts b/packages/hoppscotch-desktop/src/types/index.ts index 12703429..c6fac4e1 100644 --- a/packages/hoppscotch-desktop/src/types/index.ts +++ b/packages/hoppscotch-desktop/src/types/index.ts @@ -31,8 +31,4 @@ export interface UpdateState { status: UpdateStatus; version?: string; message?: string; - progress?: { - downloaded: number; - total?: number; - }; } diff --git a/packages/hoppscotch-desktop/src/utils/updater.ts b/packages/hoppscotch-desktop/src/utils/updater.ts index f7243e36..fc48bd92 100644 --- a/packages/hoppscotch-desktop/src/utils/updater.ts +++ b/packages/hoppscotch-desktop/src/utils/updater.ts @@ -4,6 +4,8 @@ import { type LazyStore } from "@tauri-apps/plugin-store"; import { UpdateStatus, CheckResult, UpdateState } from "~/types"; export class UpdaterService { + private currentProgress: { downloaded: number; total?: number } = { downloaded: 0 }; + constructor(private store: LazyStore) {} async initialize(): Promise { @@ -12,6 +14,10 @@ export class UpdaterService { }); } + getCurrentProgress(): { downloaded: number; total?: number } { + return this.currentProgress; + } + async checkForUpdates(timeout = 5000): Promise { try { await this.saveUpdateState({ @@ -86,41 +92,36 @@ export class UpdaterService { throw new Error("No update available to install"); } - await this.saveUpdateState({ - status: UpdateStatus.DOWNLOADING, - progress: { - downloaded: 0, - total: undefined - } - }); - let totalBytes: number | undefined; let downloadedBytes = 0; + await this.saveUpdateState({ + status: UpdateStatus.DOWNLOADING, + }); + await updateResult.downloadAndInstall( (event: DownloadEvent) => { - if (event.event === 'Started') { - totalBytes = event.data.contentLength; - this.saveUpdateState({ - status: UpdateStatus.DOWNLOADING, - progress: { - downloaded: 0, - total: totalBytes - } - }); - } else if (event.event === 'Progress') { - downloadedBytes += event.data.chunkLength; - this.saveUpdateState({ - status: UpdateStatus.DOWNLOADING, - progress: { + try { + if (event.event === 'Started') { + totalBytes = event.data.contentLength; + downloadedBytes = 0; + console.log(`Download started, total size: ${totalBytes} bytes`); + } else if (event.event === 'Progress') { + downloadedBytes += event.data.chunkLength; + console.log(`Download progress: ${downloadedBytes}/${totalBytes} bytes`); + + this.currentProgress = { downloaded: downloadedBytes, total: totalBytes - } - }); - } else if (event.event === 'Finished') { - this.saveUpdateState({ - status: UpdateStatus.INSTALLING - }); + }; + } else if (event.event === 'Finished') { + console.log("Download finished, starting installation"); + this.saveUpdateState({ + status: UpdateStatus.INSTALLING + }); + } + } catch (error) { + console.warn('Progress tracking error:', error); } } ); diff --git a/packages/hoppscotch-desktop/src/views/Home.vue b/packages/hoppscotch-desktop/src/views/Home.vue index fcbf1958..0e6f3b60 100644 --- a/packages/hoppscotch-desktop/src/views/Home.vue +++ b/packages/hoppscotch-desktop/src/views/Home.vue @@ -129,7 +129,7 @@