diff --git a/README.md b/README.md index c8ad387..8171531 100644 --- a/README.md +++ b/README.md @@ -46,14 +46,53 @@ client ID and client secret assigned by Spotify. Set your client ID as the `SPOTIFY_CLIENT` environment variable, and your client secret as the `SPOTIFY_SECRET` environment variable. -### General User Configuration +### Descent Configuration To configure the background, weather, and time displays, visit [`/now/app/config`](https://descent.live/now/app/config). Dark Sky can automatically determine weather units, but OpenWeatherMap cannot, so Descent defaults to imperial units unless otherwise specified. -### Phillips Hue Control User Configuration +### Descent Configuration Import + +You can import settings through a POST request to +[`/now/app/config/set`](https://descent.live/now/app/config/set). Each post +parameter correponds to a cookie. Valid parameters and values are as follows: + +**Background type** +`background`: `artist`, `album`, `transparent`, `none` + +**Background blurring** +`blur`: `true`, `false` + +**Default background image** +`defaultBackground`: any valid image URL + +**Weather units** +`units`: `imperial`, `metric` + +**Date/time 24-hour display** +`24hr`: `true`, `false` + +**Date/time weekday display** +`weekday`: `true`, `false` + +**Date/time seconds display** +`seconds`: `true`, `false` + +**User to redirect to** +`lastUser`: any valid Last.fm username + +**Weather display enabled** +`weatherOn`: `true`, `false` + +**Date/time display enabled** +`datetimeOn`: `true`, `false` + +**Extended information display enabled** +`extendedOn`: `true`, `false` + +### Phillips Hue Configuration To enable Phillips Hue control, visit [`/now/app/hue`](https://descent.live/now/app/hue) and follow the setup diff --git a/package.json b/package.json index 75cdc6e..f56065d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "descent", - "version": "1.5.4", + "version": "1.6.0", "description": "Elegant now playing display for Last.fm showing song metadata and local weather.", "keywords": [ "descent", diff --git a/server.js b/server.js index 9686d17..c2c1745 100644 --- a/server.js +++ b/server.js @@ -49,6 +49,73 @@ app.get('/now/app/config', (req, res) => { res.render('config', { title }); }); +app.post('/now/app/config/set', (req, res) => { + let cookies = [ + { + 'name': 'background', + 'options': ['artist', 'album', 'transparent', 'none'] + }, + { + 'name': 'blur', + 'options': ['true', 'false'] + }, + { + 'name': 'defaultBackground' + }, + { + 'name': 'units', + 'options': ['imperial', 'metric'] + }, + { + 'name': '24hr', + 'options': ['true', 'false'] + }, + { + 'name': 'weekday', + 'options': ['true', 'false'] + }, + { + 'name': 'seconds', + 'options': ['true', 'false'] + }, + { + 'name': 'lastUser' + }, + { + 'name': 'weatherOn', + 'options': ['true', 'false'] + }, + { + 'name': 'datetimeOn', + 'options': ['true', 'false'] + }, + { + 'name': 'extendedOn', + 'options': ['true', 'false'] + } + ]; + + for (let cookie of cookies) { + let name = cookie.name; + let options = cookie.options; + let selected = req.body[name]; + + if (selected === undefined || (options !== undefined && !options.includes(selected))) + continue; + + res.cookie(name, selected, { maxAge: 315360000000 }); + } + + let user = req.body.lastUser; + + if (user === undefined || user === null) { + res.redirect('/now'); + return; + } + + res.redirect(`/now/${user}`); +}); + app.get('/now/app/hue', (req, res) => { let title = 'Descent Hue Setup'; diff --git a/source/js/utility/menu.js b/source/js/utility/menu.js index 8b14851..7b3434f 100644 --- a/source/js/utility/menu.js +++ b/source/js/utility/menu.js @@ -62,7 +62,7 @@ function processKey(event) { } // Handle T to toggle date and time case 84: { - toggleCookie('datetimeEnabled'); + toggleCookie('datetimeOn'); toggleDisplay('.datetime'); break; } diff --git a/source/js/utility/time.js b/source/js/utility/time.js index 7873663..8efe8dd 100644 --- a/source/js/utility/time.js +++ b/source/js/utility/time.js @@ -6,7 +6,7 @@ function initDatetime() { setTimeout(() => { updateDatetime(); setInterval(updateDatetime, 1000); }, nextUpdate); updateDatetime(); - if (cookieEnabled('datetimeEnabled')) + if (cookieEnabled('datetimeOn')) toggleDisplay('.datetime', true); }