mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 11:01:54 +03:00
uberf-7765: retry config load desktop (#6272)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
36b2a0f8c6
commit
4e7700c4f2
@ -1,7 +1,6 @@
|
|||||||
// preload.js
|
// preload.js
|
||||||
|
|
||||||
import { BrandingMap, Config, IPCMainExposed, NotificationParams } from './types'
|
import { BrandingMap, Config, IPCMainExposed, NotificationParams } from './types'
|
||||||
|
|
||||||
import { contextBridge, ipcRenderer } from 'electron'
|
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]
|
const openArg = (process.argv.find((it) => it.startsWith('--open=')) ?? '').split('--open=')[1]
|
||||||
console.log('Open passed', openArg)
|
console.log('Open passed', openArg)
|
||||||
let configPromise: Promise<Config> | undefined
|
let configPromise: Promise<Config> | undefined
|
||||||
@ -41,7 +59,7 @@ const expose: IPCMainExposed = {
|
|||||||
configPromise = new Promise((resolve, reject) => {
|
configPromise = new Promise((resolve, reject) => {
|
||||||
ipcRenderer.invoke('get-main-config').then(
|
ipcRenderer.invoke('get-main-config').then(
|
||||||
async (mainConfig) => {
|
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 = {
|
const combinedConfig = {
|
||||||
...serverConfig,
|
...serverConfig,
|
||||||
...mainConfig,
|
...mainConfig,
|
||||||
|
Loading…
Reference in New Issue
Block a user