X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=app.js;h=6c2ba9078ef73da8214034e360530a33e7a3a55c;hb=db409f74e016b35421c2aaa2a5ade1e42553664e;hp=40830da1a457f3053b4ff230b54e0814c0add6a2;hpb=5738264ea00221c0ca128d5e7f74d31a8ec0490c;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/app.js b/app.js index 40830da..6c2ba90 100644 --- a/app.js +++ b/app.js @@ -7,7 +7,7 @@ const app = new Vue({ vlayout: true, isDark: null }, - created: function () { + created: async function () { let that = this; this.isDark = 'overrideDark' in localStorage ? @@ -18,11 +18,23 @@ const app = new Vue({ } this.checkOffline(); - that.getConfig().then(function (config) { - that.config = config; - }).catch(function () { - that.offline = true; - }); + try { + this.config = await this.getConfig(); + } catch (error) { + this.offline = true; + } + + // Look for a new message if an endpoint is provided. + if (this.config.message.url) { + this.getMessage(this.config.message.url).then(function(message){ + // keep the original config value if no value is provided by the endpoint + for (const prop of ['title','style','content']) { + if (prop in message && message[prop] !== null) { + that.config.message[prop] = message[prop]; + } + } + }); + } document.addEventListener('visibilitychange', function () { if (document.visibilityState == "visible") { @@ -52,6 +64,14 @@ const app = new Vue({ }); }); }, + getMessage: function (url) { + return fetch(url).then(function (response) { + if (response.status != 200) { + return; + } + return response.json(); + }); + }, toggleTheme: function() { this.isDark = !this.isDark; localStorage.overrideDark = this.isDark;