Skip to content
Snippets Groups Projects
Commit 3bad5d55 authored by Niklas Schrötler's avatar Niklas Schrötler
Browse files

Merge branch 'master' into 'master'

LayoutService: periodic config reload

See merge request tudo-fsinfo/infoscreen/infoscreen!4
parents cfb1d00a 6a9c7b82
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment