From f3e5aeb9e61c51243381a44672f978f37fc1fc8c Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Mon, 27 Jan 2020 22:32:38 +0100 Subject: [PATCH] Fix logger crashing the extension --- src/ext/lib/Logger.js | 45 +++++++++++++++++++++---------------------- src/ext/uw-bg.js | 15 ++++++++------- src/ext/uw.js | 31 ++++++++++++++--------------- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/ext/lib/Logger.js b/src/ext/lib/Logger.js index cfbcca0..3db6b56 100644 --- a/src/ext/lib/Logger.js +++ b/src/ext/lib/Logger.js @@ -3,22 +3,6 @@ import currentBrowser from '../conf/BrowserDetect'; class Logger { constructor(conf) { - this.initLogger(); - if (conf && process.env.CHANNEL === 'dev') { - this.conf = conf; - } - if (this.conf.consoleOptions === undefined) { - this.conf.consoleOptions = {}; - } - if (!this.conf.fileOptions === undefined) { - this.conf.fileOptions = {}; - } - this.isBackgroundPage = !!conf.isBackgroundPage; - this.history = []; - this.globalHistory = {}; - this.startTime = performance.now(); - this.temp_disable = false; - this.stopTime = conf.timeout ? performance.now() + (conf.timeout * 1000) : undefined; } static saveConfig(conf) { @@ -66,7 +50,28 @@ class Logger { } } - initLogger() { + async init(conf) { + if (conf && process.env.CHANNEL === 'dev') { + this.conf = conf; + } else { + this.conf = await Logger.getConfig(); + } + if (this.conf.consoleOptions === undefined) { + this.conf.consoleOptions = {}; + } + if (!this.conf.fileOptions === undefined) { + this.conf.fileOptions = {}; + } + // this is the only property that always gets passed via conf + // and doesn't get ignored even if the rest of the conf gets + // loaded from browser storage + this.isBackgroundPage = !!conf.isBackgroundPage; + this.history = []; + this.globalHistory = {}; + this.startTime = performance.now(); + this.temp_disable = false; + this.stopTime = conf.timeout ? performance.now() + (conf.timeout * 1000) : undefined; + const ths = this; const br = currentBrowser.firefox ? browser : chrome; br.storage.onChanged.addListener( (changes, area) => { @@ -81,14 +86,8 @@ class Logger { } }); - this.init(); } - async init() { - if (!this.conf) { - this.conf = await this.getSaved(); - } - } clear() { this.log = []; diff --git a/src/ext/uw-bg.js b/src/ext/uw-bg.js index b8fb97e..7e0ab7f 100644 --- a/src/ext/uw-bg.js +++ b/src/ext/uw-bg.js @@ -31,13 +31,14 @@ class UWServer { async setup() { // logger is the first thing that goes up - this.logger = new Logger({ - allowLogging: true, - logToFile: false, - logToConsole: true, - logAll: true, - }); - await this.logger.init(); + const loggingOptions = { + allowLogging: true, + logToFile: false, + logToConsole: true, + logAll: true, + }; + this.logger = new Logger(); + await this.logger.init(loggingOptions); this.settings = new Settings({logger: this.logger}); await this.settings.init(); diff --git a/src/ext/uw.js b/src/ext/uw.js index cbaa0a0..8d9c93b 100644 --- a/src/ext/uw.js +++ b/src/ext/uw.js @@ -52,23 +52,24 @@ class UW { }, consoleOptions: { enabled: true, // if logging is enabled at all - // 'debug': true, - // 'init': true, - // 'settings': true, - // 'keyboard': true, - // 'mousemove': false, - // 'actionHandler': false, - // 'comms': false, - // 'playerDetect': false, - // 'resizer': true, - // 'scaler': true, - // 'stretcher': true, - // 'videoRescan': false, - // 'arDetect': true, - // 'arDetect_verbose': true, + 'debug': true, + 'init': true, + 'settings': true, + 'keyboard': true, + 'mousemove': false, + 'actionHandler': false, + 'comms': false, + 'playerDetect': false, + 'resizer': true, + 'scaler': true, + 'stretcher': true, + 'videoRescan': false, + 'arDetect': true, + 'arDetect_verbose': true, } }; - this.logger = new Logger(loggingOptions); + this.logger = new Logger(); + await this.logger.init(loggingOptions); // await this.logger.init(); // not needed if logging options are provided at creation } } catch (e) {