Skip to content

Commit

Permalink
Added configuration import (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonPuglisi authored May 21, 2018
1 parent 7620620 commit 533caf8
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 5 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
67 changes: 67 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion source/js/utility/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function processKey(event) {
}
// Handle T to toggle date and time
case 84: {
toggleCookie('datetimeEnabled');
toggleCookie('datetimeOn');
toggleDisplay('.datetime');
break;
}
Expand Down
2 changes: 1 addition & 1 deletion source/js/utility/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function initDatetime() {
setTimeout(() => { updateDatetime(); setInterval(updateDatetime, 1000); }, nextUpdate);
updateDatetime();

if (cookieEnabled('datetimeEnabled'))
if (cookieEnabled('datetimeOn'))
toggleDisplay('.datetime', true);
}

Expand Down

0 comments on commit 533caf8

Please sign in to comment.