Close over init so that we can return if a feature isn't detected

I guess alternatively, just use an if/else block.
This commit is contained in:
Arlo Breault 2019-07-06 16:40:03 +02:00
parent f97c37fe5d
commit 27a92ab03a
2 changed files with 130 additions and 121 deletions

View file

@ -2,34 +2,38 @@
Entry point. Entry point.
*/ */
var snowflake, query, debug, silenceNotifications, log, dbg, init;
;(function() {
if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) { if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
console.log('webrtc feature not detected. shutting down'); console.log('webrtc feature not detected. shutting down');
return; return;
} }
var snowflake = null; snowflake = null;
var query = Query.parse(location); query = Query.parse(location);
var debug = Params.getBool(query, 'debug', false); debug = Params.getBool(query, 'debug', false);
var silenceNotifications = Params.getBool(query, 'silent', false); silenceNotifications = Params.getBool(query, 'silent', false);
// Log to both console and UI if applicable. // Log to both console and UI if applicable.
// Requires that the snowflake and UI objects are hooked up in order to // Requires that the snowflake and UI objects are hooked up in order to
// log to console. // log to console.
var log = function(msg) { log = function(msg) {
console.log('Snowflake: ' + msg); console.log('Snowflake: ' + msg);
return snowflake != null ? snowflake.ui.log(msg) : void 0; return snowflake != null ? snowflake.ui.log(msg) : void 0;
}; };
var dbg = function(msg) { dbg = function(msg) {
if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) { if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) {
return log(msg); return log(msg);
} }
}; };
var init = function() { init = function() {
var broker, config, ui; var broker, config, ui;
config = new Config; config = new Config;
if ('off' !== query['ratelimit']) { if ('off' !== query['ratelimit']) {
@ -71,3 +75,5 @@ window.onunload = function() {
}; };
window.onload = init; window.onload = init;
}());

View file

@ -2,25 +2,26 @@
Entry point. Entry point.
*/ */
var debug = false; var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications;
var snowflake = null; ;(function () {
var config = null; silenceNotifications = false;
debug = false;
var broker = null; snowflake = null;
config = null;
var ui = null; broker = null;
ui = null;
// Log to both console and UI if applicable. // Log to both console and UI if applicable.
// Requires that the snowflake and UI objects are hooked up in order to // Requires that the snowflake and UI objects are hooked up in order to
// log to console. // log to console.
var log = function(msg) { log = function(msg) {
console.log('Snowflake: ' + msg); console.log('Snowflake: ' + msg);
return snowflake != null ? snowflake.ui.log(msg) : void 0; return snowflake != null ? snowflake.ui.log(msg) : void 0;
}; };
var dbg = function(msg) { dbg = function(msg) {
if (debug) { if (debug) {
return log(msg); return log(msg);
} }
@ -35,7 +36,7 @@ if (!Util.featureDetect()) {
return; return;
} }
var init = function() { init = function() {
config = new Config; config = new Config;
ui = new WebExtUI(); ui = new WebExtUI();
broker = new Broker(config.brokerUrl); broker = new Broker(config.brokerUrl);
@ -44,7 +45,7 @@ var init = function() {
return ui.initToggle(); return ui.initToggle();
}; };
var update = function() { update = function() {
if (!ui.enabled) { if (!ui.enabled) {
// Do not activate the proxy if any number of conditions are true. // Do not activate the proxy if any number of conditions are true.
snowflake.disable(); snowflake.disable();
@ -72,3 +73,5 @@ window.onunload = function() {
}; };
window.onload = init; window.onload = init;
}());