uberf-7765: retry config load desktop (#6272)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-08-06 19:31:00 +04:00 committed by GitHub
parent 36b2a0f8c6
commit 4e7700c4f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,6 @@
// preload.js
import { BrandingMap, Config, IPCMainExposed, NotificationParams } from './types'
import { contextBridge, ipcRenderer } from 'electron'
/**
@ -18,6 +17,25 @@ export function concatLink (host: string, path: string): string {
}
}
async function loadServerConfig (url: string): Promise<any> {
let retries = 5
let error: any
do {
try {
return await (await fetch(url)).json()
} catch (e) {
error = e
retries--
if (retries > 0) {
await new Promise((resolve) => setTimeout(resolve, 1000 * (5 - retries)))
}
}
} while (retries > 0)
throw new Error(`Failed to load server config: ${error}`)
}
const openArg = (process.argv.find((it) => it.startsWith('--open=')) ?? '').split('--open=')[1]
console.log('Open passed', openArg)
let configPromise: Promise<Config> | undefined
@ -41,7 +59,7 @@ const expose: IPCMainExposed = {
configPromise = new Promise((resolve, reject) => {
ipcRenderer.invoke('get-main-config').then(
async (mainConfig) => {
const serverConfig = await (await fetch(concatLink(mainConfig.FRONT_URL, mainConfig.CONFIG_URL))).json()
const serverConfig = await loadServerConfig(concatLink(mainConfig.FRONT_URL, mainConfig.CONFIG_URL))
const combinedConfig = {
...serverConfig,
...mainConfig,