diff options
author | Bastien Wirtz <bastien.wirtz@gmail.com> | 2019-12-27 10:40:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-27 10:40:03 -0800 |
commit | 2e7bedd13e0ce409e5bfa45095a9154463257870 (patch) | |
tree | 8bb5434679911ad2302fedbea14d3853cd6b169b /app.js | |
parent | 5738264ea00221c0ca128d5e7f74d31a8ec0490c (diff) | |
parent | db409f74e016b35421c2aaa2a5ade1e42553664e (diff) | |
download | homer-2e7bedd13e0ce409e5bfa45095a9154463257870.tar.gz homer-2e7bedd13e0ce409e5bfa45095a9154463257870.tar.zst homer-2e7bedd13e0ce409e5bfa45095a9154463257870.zip |
Merge pull request #7 from bastienwirtz/dynamic-message
Optionaly load message from an endpoint.
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -7,7 +7,7 @@ const app = new Vue({ | |||
7 | vlayout: true, | 7 | vlayout: true, |
8 | isDark: null | 8 | isDark: null |
9 | }, | 9 | }, |
10 | created: function () { | 10 | created: async function () { |
11 | let that = this; | 11 | let that = this; |
12 | 12 | ||
13 | this.isDark = 'overrideDark' in localStorage ? | 13 | this.isDark = 'overrideDark' in localStorage ? |
@@ -18,11 +18,23 @@ const app = new Vue({ | |||
18 | } | 18 | } |
19 | 19 | ||
20 | this.checkOffline(); | 20 | this.checkOffline(); |
21 | that.getConfig().then(function (config) { | 21 | try { |
22 | that.config = config; | 22 | this.config = await this.getConfig(); |
23 | }).catch(function () { | 23 | } catch (error) { |
24 | that.offline = true; | 24 | this.offline = true; |
25 | }); | 25 | } |
26 | |||
27 | // Look for a new message if an endpoint is provided. | ||
28 | if (this.config.message.url) { | ||
29 | this.getMessage(this.config.message.url).then(function(message){ | ||
30 | // keep the original config value if no value is provided by the endpoint | ||
31 | for (const prop of ['title','style','content']) { | ||
32 | if (prop in message && message[prop] !== null) { | ||
33 | that.config.message[prop] = message[prop]; | ||
34 | } | ||
35 | } | ||
36 | }); | ||
37 | } | ||
26 | 38 | ||
27 | document.addEventListener('visibilitychange', function () { | 39 | document.addEventListener('visibilitychange', function () { |
28 | if (document.visibilityState == "visible") { | 40 | if (document.visibilityState == "visible") { |
@@ -52,6 +64,14 @@ const app = new Vue({ | |||
52 | }); | 64 | }); |
53 | }); | 65 | }); |
54 | }, | 66 | }, |
67 | getMessage: function (url) { | ||
68 | return fetch(url).then(function (response) { | ||
69 | if (response.status != 200) { | ||
70 | return; | ||
71 | } | ||
72 | return response.json(); | ||
73 | }); | ||
74 | }, | ||
55 | toggleTheme: function() { | 75 | toggleTheme: function() { |
56 | this.isDark = !this.isDark; | 76 | this.isDark = !this.isDark; |
57 | localStorage.overrideDark = this.isDark; | 77 | localStorage.overrideDark = this.isDark; |