Query string settings support. Closes @22

master
William Toohey 9 years ago
parent 3265fb9956
commit 378e415f18
  1. 8
      README.md
  2. 40
      src/js/HuesSettings.js

@ -36,6 +36,14 @@ var defaults = {
## Settings object ## Settings object
See [HuesSettings.js](./src/js/HuesSettings.js#L29) for the possible options you can put into the `defaults` object. See [HuesSettings.js](./src/js/HuesSettings.js#L29) for the possible options you can put into the `defaults` object.
## Query string
Any setting that can go in the `defaults` object can also be dynamically specified in the URL.
For example: http://0x40.mon.im/custom.html?packs=BIOS.zip,kitchen.zip&currentUI=v4.20
There are two special settings here:
* `firstSong` can just be written as `song`.
* Anything given as `packs` or `respacks` will be appended to the respacks specified in the `defaults` object, as opposed to overwriting them.
## Building ## Building
Install [Node.js](https://nodejs.org/en/), v5 preferred. Install [Node.js](https://nodejs.org/en/), v5 preferred.
Install the required packages for the build: Install the required packages for the build:

@ -30,6 +30,9 @@ const defaultSettings = {
// Location relative to root - where do the audio/zip workers live // Location relative to root - where do the audio/zip workers live
// This is required because Web Workers need an absolute path // This is required because Web Workers need an absolute path
workersPath : "lib/workers/", workersPath : "lib/workers/",
// ONLY USED FOR QUERY STRINGS this will be prepended to any respacks
// passed in as a ?packs=query
respackPath : "respacks/",
// Debugging var, for loading zips or not // Debugging var, for loading zips or not
load : true, load : true,
// Debug, play first song automatically? // Debug, play first song automatically?
@ -85,6 +88,7 @@ const ephemeralSettings = [
"autoplay", "autoplay",
"overwriteLocal", "overwriteLocal",
"respacks", "respacks",
"respackPath",
"firstSong", "firstSong",
"firstImage", "firstImage",
"disableRemoteResources", "disableRemoteResources",
@ -255,6 +259,42 @@ class HuesSettings {
} }
this.defaults = defaults; this.defaults = defaults;
// Override with our query string
let querySettings = this.getQuerySettings();
this.defaults.respacks = this.defaults.respacks.concat(querySettings.respacks);
for(let attr in querySettings) {
if(querySettings.hasOwnProperty(attr) && attr != "respacks") {
this.defaults[attr] = querySettings[attr];
if(ephemeralSettings.indexOf(attr) == -1) {
// TODO: Everything that checks localStorage for settings should
// change to get() to preserve local changes
localStorage[attr] = querySettings[attr];
}
}
}
}
getQuerySettings() {
let results = {};
results.respacks = [];
let query = window.location.search.substring(1);
let vars = query.split("&");
for (let i=0;i<vars.length;i++) {
let pair = vars[i].split("=");
if(pair[0] == "packs" || pair[0] == "respacks"){
let packs = pair[1].split(",");
for(let j = 0; j < packs.length; j++) {
results.respacks.push(this.defaults.respackPath + packs[j]);
}
} else if(pair[0] == "song") { // alias for firstSong
results.firstSong = pair[1];
} else {
results[pair[0]] = pair[1];
}
}
return results;
} }
initUI(huesWin) { initUI(huesWin) {

Loading…
Cancel
Save