Skip to content

Commit b4a1892

Browse files
authored
qfix: Desktop should recover on network lose (#9967)
Signed-off-by: Andrey Sobolev <[email protected]>
1 parent 547c9d5 commit b4a1892

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

desktop/src/ui/preload.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// preload.js
22

33
import { contextBridge, ipcRenderer } from 'electron'
4-
import { BrandingMap, Config, IPCMainExposed, MenuBarAction, NotificationParams, JumpListSpares } from './types'
4+
import { BrandingMap, Config, IPCMainExposed, JumpListSpares, MenuBarAction, NotificationParams } from './types'
55

66
/**
77
* @public
@@ -18,27 +18,23 @@ export function concatLink (host: string, path: string): string {
1818
}
1919

2020
async function loadServerConfig (url: string): Promise<any> {
21-
let retries = 5
21+
let retries = 1
2222
let res: Response | undefined
2323

24-
do {
24+
while (true) {
2525
try {
2626
res = await fetch(url, {
2727
keepalive: true
2828
})
29+
if (res === undefined) {
30+
// In theory should never get here
31+
throw new Error('Failed to load server config')
32+
}
2933
break
3034
} catch (e) {
31-
retries--
32-
if (retries === 0) {
33-
throw new Error(`Failed to load server config: ${e}`)
34-
}
35-
await new Promise((resolve) => setTimeout(resolve, 1000 * (5 - retries)))
35+
retries++
36+
await new Promise((resolve) => setTimeout(resolve, 1000 * Math.min(5, retries)))
3637
}
37-
} while (retries > 0)
38-
39-
if (res === undefined) {
40-
// In theory should never get here
41-
throw new Error('Failed to load server config')
4238
}
4339

4440
return await res.json()

plugins/workbench-resources/src/connect.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,13 @@ export async function connect (title: string): Promise<Client | undefined> {
366366
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? ''
367367
const currentFrontVersion = getMetadata(presentation.metadata.FrontVersion)
368368
if (currentFrontVersion !== undefined) {
369-
const frontConfig = await loadServerConfig(concatLink(frontUrl, '/config.json'))
370-
if (frontConfig?.version !== undefined && frontConfig.version !== currentFrontVersion) {
369+
try {
370+
const frontConfig = await loadServerConfig(concatLink(frontUrl, '/config.json'))
371+
if (frontConfig?.version !== undefined && frontConfig.version !== currentFrontVersion) {
372+
location.reload()
373+
}
374+
} catch (err: any) {
375+
// Failed to load server config, reload location
371376
location.reload()
372377
}
373378
}

0 commit comments

Comments
 (0)