diff --git a/src/services/LayoutService.ts b/src/services/LayoutService.ts index 2b90cad305f707c48d656b7f6a33e6a20948ee2f..1d7a6f1cc39f01ed50627f38a72e1ba08ba000f7 100644 --- a/src/services/LayoutService.ts +++ b/src/services/LayoutService.ts @@ -13,11 +13,14 @@ export class LayoutService { static async init(): Promise<void> { try { - const activeConfigs = await fetch("/activeConfigs.json").then(content => content.json()); - const configFetches = (activeConfigs as string[]) - .map(configPath => fetch(configPath).then(content => content.json())); - - LayoutService.configs = await Promise.all(configFetches); + LayoutService.configs = await fetchActiveConfigs(); + const autoRefreshInterval = 1000 * 60 * 10; + + setInterval(() => { + fetchActiveConfigs() + .then(cfg => this.configs = cfg) + .catch(_ => console.log("cannot refresh layout config")); + }, autoRefreshInterval); } catch (e) { console.error("LayoutService could not init", e) } @@ -37,10 +40,17 @@ export class LayoutService { }, false); }); - console.log(activeConfigs) - - /* ToDo: This is not great, as it assumes there is always an active layout. If you don't configure this correctly, - consider yourself warned now and don't blame me */ - return activeConfigs.at(0) ?? NO_LAYOUT_CONFIG; + const defaultConfig = this.configs.filter(config => config.id === "default").at(0); + return activeConfigs.at(0) ?? defaultConfig ?? NO_LAYOUT_CONFIG; } } + +async function fetchActiveConfigs(): Promise<LayoutConfig[]> { + const activeConfigs = await fetch("/activeConfigs.json").then(content => content.json()); + + const configFetches = (activeConfigs as string[]) + .map(configPath => fetch(configPath).then(content => content.json())); + + const configs: LayoutConfig[] = (await Promise.all(configFetches)).map(item => item as LayoutConfig); + return configs; +}