diff --git a/src/ext/lib/Logger.js b/src/ext/lib/Logger.js index 587cac8..82de7ed 100644 --- a/src/ext/lib/Logger.js +++ b/src/ext/lib/Logger.js @@ -10,6 +10,7 @@ class Logger { this.isBackgroundScript = true; this.vuexStore = options?.vuexStore; + this.uwInstance = options?.uwInstance; } static saveConfig(conf) { @@ -120,6 +121,10 @@ class Logger { }); } + setVuexStore(store) { + this.vuexStore = store; + } + clear() { this.log = []; this.startTime = performance.now(); @@ -295,6 +300,10 @@ class Logger { return false; } + isLoggingAllowed() { + return this.conf.allowLogging; + } + isLoggingToFile() { return this.conf.allowLogging && this.conf.fileOptions?.enabled; } @@ -470,8 +479,13 @@ class Logger { } if (!this.vuexStore) { - console.error("[info] No vue store. Log will not be exported."); - return; + console.error("[info] No vue store."); + if (!this.uwInstance) { + console.error('[info] no vue instance either. Not logging.'); + return; + } + console.info("[info] Initializing vue and vuex instance ..."); + this.uwInstance.initVue(); } console.info('[info] vuex store present. Parsing logs.'); diff --git a/src/ext/uw.js b/src/ext/uw.js index d1ab769..03b608b 100644 --- a/src/ext/uw.js +++ b/src/ext/uw.js @@ -41,6 +41,8 @@ class UW { this.actionHandler = undefined; this.logger = undefined; this.vuexStore = {}; + this.uiInitiated = false; + this.vueInitiated = false; } reloadSettings() { @@ -87,9 +89,16 @@ class UW { 'handleMouseMove': false } }; - this.logger = new Logger({vuexStore: this.vuexStore}); + this.logger = new Logger(); await this.logger.init(loggingOptions); + if (this.logger.isLoggingAllowed()) { + console.info("[uw::init] Logging is allowed! Initalizing vue and UI!"); + this.initVue(); + this.initUi(); + this.logger.setVuexStore(this.vuexStore); + } + // show popup if logging to file is enabled if (this.logger.isLoggingToFile()) { console.info('[uw::init] Logging to file is enabled. Will show popup!'); @@ -228,14 +237,23 @@ class UW { } showLogger() { + if (! this.vueInitiated) { + this.initVue(); + } + if (!this.uiInitiated) { + this.initUi(); + } + this.vuexStore.dispatch('uw-show-logger'); } hideLogger() { - this.vuexStore.dispatch('uw-hide-logger'); + // if either of these two is false, then we know that UI doesn't exist + // since UI doesn't exist, we don't need to dispatch uw-hide-logger + if (this.vueInitiated && this.uiInitiated) { + this.vuexStore.dispatch('uw-hide-logger'); + } } } var main = new UW(); -main.initVue(); -main.initUi(); main.init();