X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=app.js;h=c35e4c7da7aa1f4c8a7297434d886473657a8508;hb=deff5e387a8c29536988db03d0b551d516a79b14;hp=dc8b6cc65ff9fe055f74cfefccc2e4b4fbcd7525;hpb=4877ec98e668b1741d7a2a4d3e4a177ec495db39;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/app.js b/app.js index dc8b6cc..c35e4c7 100644 --- a/app.js +++ b/app.js @@ -4,17 +4,37 @@ const app = new Vue({ config: null, offline: false, filter: '', - vlayout: true + vlayout: true, + isDark: null }, - created: function () { + created: async function () { let that = this; + this.isDark = 'overrideDark' in localStorage ? + JSON.parse(localStorage.overrideDark) : matchMedia("(prefers-color-scheme: dark)").matches; + + if ('vlayout' in localStorage) { + this.vlayout = JSON.parse(localStorage.vlayout) + } + 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 && 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") { @@ -44,6 +64,22 @@ 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; + }, + toggleLayout: function() { + this.vlayout = !this.vlayout; + localStorage.vlayout = this.vlayout; + }, } }); @@ -51,7 +87,7 @@ Vue.component('service', { props: ['item'], template: `
- +
@@ -69,7 +105,9 @@ Vue.component('service', {

{{ item.subtitle }}

- #{{ item.tag }} +
+ #{{ item.tag }} +
` @@ -77,6 +115,6 @@ Vue.component('service', { if ('serviceWorker' in navigator) { window.addEventListener('load', function () { - navigator.serviceWorker.register('/worker.js'); + navigator.serviceWorker.register('worker.js'); }); }