Add parseQueryString and packsURL to settings (#36)

* Allow disabling query string parsing

* Allow configuring packsURL in settings
master
Anna-Maria Meriniemi 7 years ago committed by Will
parent a225a103b1
commit 9faf6e5b8c
  1. 21
      src/js/HuesSettings.js
  2. 5
      src/js/ResourceManager.js

@ -32,6 +32,8 @@ const defaultSettings = {
workersPath : "lib/workers/", workersPath : "lib/workers/",
// List of respacks to load // List of respacks to load
respacks : [], respacks : [],
// If true, the query string (?foo=bar&baz=boz) will be parsed for settings
parseQueryString : true,
// ONLY USED FOR QUERY STRINGS this will be prepended to any respacks // ONLY USED FOR QUERY STRINGS this will be prepended to any respacks
// passed in as a ?packs=query // passed in as a ?packs=query
respackPath : "respacks/", respackPath : "respacks/",
@ -47,6 +49,9 @@ const defaultSettings = {
firstImage: null, firstImage: null,
// set to false to never change images // set to false to never change images
fullAuto: true, fullAuto: true,
// The remote respack listing JSON endpoint
// NOTE: Any packs referenced need CORS enabled or loads fail
packsURL: "https://cdn.0x40.ga/getRespacks.php",
// If set, will disable the remote resources menu. For custom pages. // If set, will disable the remote resources menu. For custom pages.
disableRemoteResources: false, disableRemoteResources: false,
// You will rarely want to change this. Enables/disables the Hues Window. // You will rarely want to change this. Enables/disables the Hues Window.
@ -248,16 +253,18 @@ class HuesSettings {
} }
} }
let querySettings = this.getQuerySettings(); if (this.parseQueryString) {
let querySettings = this.getQuerySettings();
for(let attr in defaultSettings) { for(let attr in defaultSettings) {
// query string overrides, finally // query string overrides, finally
if(querySettings[attr] !== undefined && attr != 'respacks') { if(querySettings[attr] !== undefined && attr != 'respacks') {
this.ephemerals[attr] = querySettings[attr]; this.ephemerals[attr] = querySettings[attr];
}
} }
}
this.respacks = this.respacks.concat(querySettings.respacks); this.respacks = this.respacks.concat(querySettings.respacks);
}
} }
getQuerySettings() { getQuerySettings() {

@ -31,9 +31,6 @@ let getAndIncrementUnique = function() {
return unique++; return unique++;
}; };
// NOTE: Any packs referenced need CORS enabled or loads fail
let packsURL = "https://cdn.0x40.ga/getRespacks.php";
class Resources { class Resources {
constructor(core, huesWin) { constructor(core, huesWin) {
this.core = core; this.core = core;
@ -719,7 +716,7 @@ class Resources {
let item = this.appendSimpleListItem("Loading...", remoteList); let item = this.appendSimpleListItem("Loading...", remoteList);
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.open('GET', packsURL, true); req.open('GET', this.core.settings.packsURL, true);
req.responseType = 'json'; req.responseType = 'json';
req.onload = () => { req.onload = () => {
if(!req.response) { if(!req.response) {

Loading…
Cancel
Save