Fix logger crashing the extension

This commit is contained in:
Tamius Han 2020-01-27 22:32:38 +01:00
parent f1d2881359
commit f3e5aeb9e6
3 changed files with 46 additions and 45 deletions

View File

@ -3,22 +3,6 @@ import currentBrowser from '../conf/BrowserDetect';
class Logger { class Logger {
constructor(conf) { 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) { 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 ths = this;
const br = currentBrowser.firefox ? browser : chrome; const br = currentBrowser.firefox ? browser : chrome;
br.storage.onChanged.addListener( (changes, area) => { 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() { clear() {
this.log = []; this.log = [];

View File

@ -31,13 +31,14 @@ class UWServer {
async setup() { async setup() {
// logger is the first thing that goes up // logger is the first thing that goes up
this.logger = new Logger({ const loggingOptions = {
allowLogging: true, allowLogging: true,
logToFile: false, logToFile: false,
logToConsole: true, logToConsole: true,
logAll: true, logAll: true,
}); };
await this.logger.init(); this.logger = new Logger();
await this.logger.init(loggingOptions);
this.settings = new Settings({logger: this.logger}); this.settings = new Settings({logger: this.logger});
await this.settings.init(); await this.settings.init();

View File

@ -52,23 +52,24 @@ class UW {
}, },
consoleOptions: { consoleOptions: {
enabled: true, // if logging is enabled at all enabled: true, // if logging is enabled at all
// 'debug': true, 'debug': true,
// 'init': true, 'init': true,
// 'settings': true, 'settings': true,
// 'keyboard': true, 'keyboard': true,
// 'mousemove': false, 'mousemove': false,
// 'actionHandler': false, 'actionHandler': false,
// 'comms': false, 'comms': false,
// 'playerDetect': false, 'playerDetect': false,
// 'resizer': true, 'resizer': true,
// 'scaler': true, 'scaler': true,
// 'stretcher': true, 'stretcher': true,
// 'videoRescan': false, 'videoRescan': false,
// 'arDetect': true, 'arDetect': true,
// 'arDetect_verbose': 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 // await this.logger.init(); // not needed if logging options are provided at creation
} }
} catch (e) { } catch (e) {