Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(desktop): sync self-hosted instance version from manifest (#6423)

cassiocaueeca92e91855f8
diff --git a/packages/hoppscotch-desktop/src/composables/useAppInitialization.ts b/packages/hoppscotch-desktop/src/composables/useAppInitialization.ts
index c50edce82..7b1255482 100644
--- a/packages/hoppscotch-desktop/src/composables/useAppInitialization.ts
+++ b/packages/hoppscotch-desktop/src/composables/useAppInitialization.ts
@@ -214,14 +214,44 @@ export function useAppInitialization() {
target: instance.serverUrl,
})
- await download({ serverUrl: instance.serverUrl })
+ const dlResp = await download({ serverUrl: instance.serverUrl })
+ const updatedInstance: Instance = {
+ ...instance,
+ version: dlResp.version,
+ bundleName: dlResp.bundleName,
+ }
+ const DESKTOP_APP_SERVER_PATH = "/desktop-app-server"
+ const normUrl = (u: string) => {
+ let n = u.toLowerCase()
+ while (n.endsWith("/")) n = n.slice(0, -1)
+ if (n.endsWith(DESKTOP_APP_SERVER_PATH))
+ n = n.slice(0, -DESKTOP_APP_SERVER_PATH.length)
+ while (n.endsWith("/")) n = n.slice(0, -1)
+ return n
+ }
+ try {
+ const recentInstances = await persistence.recentInstances.get()
+ await persistence.recentInstances.set(
+ recentInstances.map((r) =>
+ normUrl(r.serverUrl) === normUrl(updatedInstance.serverUrl)
+ ? {
+ ...r,
+ version: dlResp.version,
+ bundleName: dlResp.bundleName,
+ }
+ : r
+ )
+ )
+ } catch (syncErr) {
+ console.error("Failed to sync recent instance version:", syncErr)
+ }
mainDiag(
- `loadVendoredIfMatches: loading non-vendored instance, bundle=${instance.bundleName}`
+ `loadVendoredIfMatches: loading non-vendored instance, bundle=${updatedInstance.bundleName}`
)
await desktopSettings.ready()
const loadResp = await load({
- bundleName: instance.bundleName!,
+ bundleName: updatedInstance.bundleName!,
window: {
title: "Hoppscotch",
zoomLevel: desktopSettings.settings.zoomLevel,
@@ -237,7 +267,7 @@ export function useAppInitialization() {
await saveConnectionState({
status: "connected",
- instance: instance,
+ instance: updatedInstance,
})
console.log(`Successfully loaded instance: ${instance.displayName}`)
diff --git a/packages/hoppscotch-selfhost-web/src/platform/instance/desktop/index.ts b/packages/hoppscotch-selfhost-web/src/platform/instance/desktop/index.ts
index 2ad1ed9c6..5054a7f93 100644
--- a/packages/hoppscotch-selfhost-web/src/platform/instance/desktop/index.ts
+++ b/packages/hoppscotch-selfhost-web/src/platform/instance/desktop/index.ts
@@ -1012,6 +1012,7 @@ export class DesktopInstanceService
instance: Instance,
options?: Partial<LoadOptions>
): TE.TaskEither<string, LoadResponse> {
+ let loadedInstance: Instance = instance
return pipe(
instance.kind === "vendored"
? TE.of(undefined)
@@ -1020,19 +1021,23 @@ export class DesktopInstanceService
console.log(
`[InstanceService] Ensuring bundle is available for: ${instance.displayName}`
)
- await download({ serverUrl: instance.serverUrl })
- return undefined
+ const dlResp = await download({ serverUrl: instance.serverUrl })
+ loadedInstance = {
+ ...instance,
+ version: dlResp.version,
+ bundleName: dlResp.bundleName,
+ }
},
(error) => `Failed to ensure bundle is available: ${error}`
),
- TE.chain(() => this.getBundleNameTE(instance)),
- TE.map(() => this.buildLoadOptions(instance, options)),
+ TE.chain(() => this.getBundleNameTE(loadedInstance)),
+ TE.map(() => this.buildLoadOptions(loadedInstance, options)),
TE.chain((loadOptions) => this.performLoadTE(loadOptions)),
TE.chain((response) =>
- this.validateLoadResponseTE(response, instance.displayName)
+ this.validateLoadResponseTE(response, loadedInstance.displayName)
),
- TE.chainFirst(() => this.updateInstanceStateTE(instance)),
- TE.chainFirst(() => this.updateInstanceLastUsed(instance)),
+ TE.chainFirst(() => this.updateInstanceStateTE(loadedInstance)),
+ TE.chainFirst(() => this.updateInstanceLastUsed(loadedInstance)),
TE.chainFirst((_loadResponse) =>
TE.fromTask(async () => {
try {
@@ -1271,7 +1276,12 @@ export class DesktopInstanceService
this.recentInstances$.value,
A.map((i) =>
i.serverUrl === instance.serverUrl
- ? { ...i, lastUsed: new Date().toISOString() }
+ ? {
+ ...i,
+ version: instance.version,
+ bundleName: instance.bundleName,
+ lastUsed: new Date().toISOString(),
+ }
: i
),
sortByLastUsedDesc,