@c8y/bootstrap
Version:
Bootstrap layer
31 lines • 1.09 kB
JavaScript
export async function applyPreviewOptions(options) {
if (!options.brandingPreview) {
return;
}
const dynamicOptionsUrl = options.dynamicOptionsUrl;
const lastUpdated = options.lastUpdated;
while (true) {
await sleep();
try {
const date = new Date();
const result = await fetch(`${dynamicOptionsUrl}?nocache=${date.getTime()}`);
if (result.status !== 200) {
continue;
}
const newOptions = await result.json();
const newLastUpdated = newOptions.lastUpdated;
if (!newLastUpdated || newLastUpdated === lastUpdated) {
continue;
}
console.log(`The current branding seems to be outdated. Reloading the page...`);
window.location.reload();
}
catch (e) {
console.warn(`An error occurred while checking for an updated branding.`, e);
}
}
}
function sleep() {
return new Promise(resolve => setTimeout(resolve, 5000));
}
//# sourceMappingURL=branding-preview.js.map