From 343a80f6423464ceefa8fbbf97225ada76e1d247 Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Wed, 16 Oct 2024 15:58:24 +0400 Subject: [PATCH] uberf-8481: upgrade desktop upgrade UX (#6957) Signed-off-by: Alexey Zinoviev --- plugins/guest-resources/src/connect.ts | 25 ++++++++++++++++------ plugins/workbench-resources/src/connect.ts | 25 ++++++++++++++++------ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/plugins/guest-resources/src/connect.ts b/plugins/guest-resources/src/connect.ts index 5064ac5452..c122081a31 100644 --- a/plugins/guest-resources/src/connect.ts +++ b/plugins/guest-resources/src/connect.ts @@ -16,7 +16,8 @@ import presentation, { loadServerConfig, refreshClient, setClient, - setPresentationCookie + setPresentationCookie, + upgradeDownloadProgress } from '@hcengineering/presentation' import { desktopPlatform, @@ -25,7 +26,8 @@ import { navigate, setMetadataLocalStorage } from '@hcengineering/ui' -import { writable } from 'svelte/store' +import { writable, get } from 'svelte/store' + export const versionError = writable(undefined) const versionStorageKey = 'last_server_version' @@ -82,20 +84,29 @@ export async function connect (title: string): Promise { frontVersion !== serverVersion ) { const reloaded = localStorage.getItem(`versionUpgrade:s${serverVersion}:f${frontVersion}`) + const isUpgrading = get(upgradeDownloadProgress) >= 0 if (reloaded === null) { localStorage.setItem(`versionUpgrade:s${serverVersion}:f${frontVersion}`, 't') - location.reload() + // It might have been refreshed manually and download has started - do not reload + if (!isUpgrading) { + location.reload() + } + return false } else { versionError.set(`Front version ${frontVersion} is not in sync with server version ${serverVersion}`) - if (!desktopPlatform) { + if (!desktopPlatform || !isUpgrading) { setTimeout(() => { - location.reload() - }, 5000) + // It might be possible that this callback will fire after the user has spent some time + // in the upgrade !modal! dialog and clicked upgrade - check again and do not reload + if (get(upgradeDownloadProgress) < 0) { + location.reload() + } + }, 10000) } - // For embedded it should download the upgrade and restart the app + // For embedded if the download has started it should download the upgrade and restart the app return false } diff --git a/plugins/workbench-resources/src/connect.ts b/plugins/workbench-resources/src/connect.ts index 5e46301be6..83f0b30f5c 100644 --- a/plugins/workbench-resources/src/connect.ts +++ b/plugins/workbench-resources/src/connect.ts @@ -24,7 +24,8 @@ import presentation, { refreshClient, setClient, setPresentationCookie, - uiContext + uiContext, + upgradeDownloadProgress } from '@hcengineering/presentation' import { desktopPlatform, @@ -34,7 +35,8 @@ import { navigate, setMetadataLocalStorage } from '@hcengineering/ui' -import { writable } from 'svelte/store' +import { writable, get } from 'svelte/store' + import plugin from './plugin' import { workspaceCreating } from './utils' @@ -164,20 +166,29 @@ export async function connect (title: string): Promise { frontVersion !== serverVersion ) { const reloaded = localStorage.getItem(`versionUpgrade:s${serverVersion}:f${frontVersion}`) + const isUpgrading = get(upgradeDownloadProgress) >= 0 if (reloaded === null) { localStorage.setItem(`versionUpgrade:s${serverVersion}:f${frontVersion}`, 't') - location.reload() + // It might have been refreshed manually and download has started - do not reload + if (!isUpgrading) { + location.reload() + } + return false } else { versionError.set(`Front version ${frontVersion} is not in sync with server version ${serverVersion}`) - if (!desktopPlatform) { + if (!desktopPlatform || !isUpgrading) { setTimeout(() => { - location.reload() - }, 5000) + // It might be possible that this callback will fire after the user has spent some time + // in the upgrade !modal! dialog and clicked upgrade - check again and do not reload + if (get(upgradeDownloadProgress) < 0) { + location.reload() + } + }, 10000) } - // For embedded it should download the upgrade and restart the app + // For embedded if the download has started it should download the upgrade and restart the app return false }