From 014ab10ef805d05b1bb022bf22d079e36bd633d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 22 Jan 2024 11:47:28 +0200 Subject: [PATCH] Improve Splash screen download indicators - Calculate package list download progress percentage if possible. This requires that the response headers contain the total length of the content, which is not guaranteed. - Set exclusion list download progress to 100 when done. Previously this would be left to 0 if the response headers didn't contain the content length. - Set package list download progress to 100 when done, even if the download fails. Strictly speaking this wouldn't be necessary since the progress bar is hidden after this step, but it might prevent issues in the future if the UI is changed. - Reset all progress to 0 if user attempts to reconnect after some part of the process has failed. --- src/components/mixins/SplashMixin.vue | 3 +++ src/pages/Splash.vue | 3 +++ src/utils/HttpUtils.ts | 13 ++++--------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/mixins/SplashMixin.vue b/src/components/mixins/SplashMixin.vue index 352b2e124..66bef26b1 100644 --- a/src/components/mixins/SplashMixin.vue +++ b/src/components/mixins/SplashMixin.vue @@ -44,6 +44,7 @@ export default class SplashMixin extends Vue { }; ThunderstorePackages.EXCLUSIONS = await ConnectionProvider.instance.getExclusions(showProgress); + this.getRequestItem('ExclusionsList').setProgress(100); } // Get the list of Thunderstore mods from API. @@ -62,6 +63,8 @@ export default class SplashMixin extends Vue { this.isOffline = true; this.heroTitle = 'Failed to get mods from Thunderstore'; this.loadingText = 'You may be offline or Thunderstore is unavailabe. Checking cache.'; + } finally { + this.getRequestItem('ThunderstoreDownload').setProgress(100); } if (response) { diff --git a/src/pages/Splash.vue b/src/pages/Splash.vue index 56ea90ce7..807e5ed06 100644 --- a/src/pages/Splash.vue +++ b/src/pages/Splash.vue @@ -194,6 +194,9 @@ export default class Splash extends mixins(SplashMixin) { } retryConnection() { + this.getRequestItem('UpdateCheck').setProgress(0); + this.getRequestItem('ExclusionsList').setProgress(0); + this.getRequestItem('ThunderstoreDownload').setProgress(0); this.isOffline = false; this.checkForUpdates(); } diff --git a/src/utils/HttpUtils.ts b/src/utils/HttpUtils.ts index 68c93da79..1be34a0ad 100644 --- a/src/utils/HttpUtils.ts +++ b/src/utils/HttpUtils.ts @@ -31,11 +31,7 @@ export const getAxiosWithTimeouts = (responseTimeout = 5000, totalTimeout = 1000 }; interface LongRunningRequestOptions { - /** - * Custom function to be called when progress is made. Doesn't work - * properly currently, since the progress percentage can't be - * calculated because the total length of the content isn't known. - */ + /** Custom function to be called when progress is made. */ downloadProgressed?: DownloadProgressed; /** * Time (in ms) the request has to trigger the first download @@ -84,10 +80,9 @@ export const makeLongRunningGetRequest = async ( rollingTimeout = setTimeout(abort, transmissionTimeout); if (typeof downloadProgressed === "function") { - // TODO: Progress percentage can't be calculated since the - // content length is unknown. Looks like this hasn't worked - // in a while. - downloadProgressed(0); + // Backend might not provided total content length. + const percent = progress.total ? (progress.loaded / progress.total) * 100 : 0; + downloadProgressed(percent); } }