diff --git a/src/csui/LoggerUi.vue b/src/csui/LoggerUi.vue index 12dc6e4..0b70300 100644 --- a/src/csui/LoggerUi.vue +++ b/src/csui/LoggerUi.vue @@ -1,8 +1,24 @@ @@ -49,14 +91,14 @@ import Logger from '../ext/lib/Logger'; export default { data() { return { - showLoggerUi: true, + showLoggerUi: false, header: { header: 'whoopsie daisy', subheader: 'you broke the header choosing script' }, parsedSettings: '', lastSettings: {}, - hasError: false, + confHasError: false, logStringified: '', } }, @@ -76,43 +118,50 @@ export default { this.lastSettings = await Logger.getConfig() || {}; this.parsedSettings = JSON.stringify(this.lastSettings, null, 2) || ''; - - // this.$store.watch( - // (state, getters) => {}, - // (newValue, oldValue) => { - // console.log("$store.watch — updating from", oldValue, "to", newValue); - // } - // ) }, computed: { ...mapState([ 'uwLog', + 'showLogger' ]), }, watch: { uwLog(newValue, oldValue) { - console.log("updating status from", oldValue, "to", newValue); if (oldValue !== newValue) { this.logStringified = JSON.stringify(newValue, null, 2); } + }, + showLogger(newValue) { + this.showLoggerUi = newValue; } }, methods: { updateSettings(val) { try { // this.settings.active = JSON.parse(val.target.textContent); - this.hasError = false; + this.confHasError = false; } catch (e) { - this.hasError = true; + this.confHasError = true; } }, + hidePopup() { + // this function only works as 'close' if logging has finished + if (this.logStringified) { + Logger.saveConfig({...this.lastSettings, allowLogging: false}); + } + this.$store.dispatch('uw-hide-logger'); + }, + stopLogging() { + Logger.saveConfig({...this.lastSettings, allowLogging: false}); + this.$store.dispatch('uw-hide-logger'); + } } } diff --git a/src/ext/lib/Logger.js b/src/ext/lib/Logger.js index 72d2b2d..04626e1 100644 --- a/src/ext/lib/Logger.js +++ b/src/ext/lib/Logger.js @@ -287,6 +287,10 @@ class Logger { return false; } + isLoggingToFile() { + return this.conf.allowLogging && this.conf.fileOptions?.enabled; + } + // NOTE: THIS FUNCTION IS NEVER USED INTERNALLY! canLog(component) { const stackInfo = this.parseStack(); diff --git a/src/ext/uw.js b/src/ext/uw.js index fdbf122..6cbd0f3 100644 --- a/src/ext/uw.js +++ b/src/ext/uw.js @@ -41,11 +41,10 @@ class UW { this.settings = undefined; this.actionHandler = undefined; this.logger = undefined; - this.store = {}; + this.vuexStore = {}; } async init(){ - this.createUi(); if (Debug.debug) { console.log("[uw::main] loading configuration ..."); } @@ -84,9 +83,18 @@ class UW { 'handleMouseMove': false } }; - this.logger = new Logger({vuexStore: this.store}); + this.logger = new Logger({vuexStore: this.vuexStore}); await this.logger.init(loggingOptions); - // await this.logger.init(); // not needed if logging options are provided at creation + + // show popup if logging to file is enabled + if (this.logger.isLoggingToFile()) { + console.info('[uw::init] Logging to file is enabled. Will show popup!'); + try { + this.vuexStore.dispatch('uw-show-logger'); + } catch (e) { + console.error('[uw::init] Failed to open popup!', e) + } + } } } catch (e) { console.error("logger init failed!", e) @@ -109,6 +117,10 @@ class UW { } this.comms = new CommsClient('content-client-port', this.settings, this.logger); + + // add showPopup, hidePopup listener to comms + this.comms.subscribe('show-logger', () => this.showLogger()); + this.comms.subscribe('hide-logger', () => this.hideLogger()); // če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar // If extension is soft-disabled, don't do shit @@ -144,38 +156,48 @@ class UW { } catch (e) { this.logger.log('error', 'debug', "[uw::init] FAILED TO START EXTENSION. Error:", e); } - - } initVue() { Vue.prototype.$browser = global.browser; Vue.use(Vuex); - this.store = new Vuex.Store({ + this.vuexStore = new Vuex.Store({ plugins: [VuexWebExtensions({ persistentStates: [ - 'uwLog' + 'uwLog', + 'showLogger', ], })], state: { uwLog: '', + showLogger: false, }, mutations: { 'uw-set-log'(state, payload) { - console.info('setting state') state['uwLog'] = payload; + }, + 'uw-show-logger'(state) { + state['showLogger'] = true; + }, + 'uw-hide-logger'(state) { + state['showLogger'] = false; } }, actions: { 'uw-set-log' ({commit}, payload) { - console.info("comitting uw-set-log with payload", payload); commit('uw-set-log', payload); + }, + 'uw-show-logger'({commit}) { + commit('uw-show-logger'); + }, + 'uw-hide-logger'({commit}) { + commit('uw-hide-logger'); } } }) } - createUi() { + initUi() { console.log("CREATING UI"); const random = Math.round(Math.random() * 69420); const uwid = `uw-ui-root-${random}`; @@ -192,14 +214,22 @@ class UW { components: { LoggerUi }, - store: this.store, + store: this.vuexStore, render(h) { return h('logger-ui'); } }) } + + showLogger() { + this.vuexStore.dispatch('uw-show-logger'); + } + hideLogger() { + this.vuexStore.dispatch('uw-hide-logger'); + } } var main = new UW(); main.initVue(); +main.initUi(); main.init(); diff --git a/src/res/css/colors.scss b/src/res/css/colors.scss index 4328a3a..5db4ec4 100644 --- a/src/res/css/colors.scss +++ b/src/res/css/colors.scss @@ -7,6 +7,7 @@ $secondary-color: #e70c0c; $input-background: #141414; $input-border: #4e3527; $page-background: #101010; +$popup-header-background: #7f1416; $background-primary: #101010; $selected-color: #f5cbaf; diff --git a/src/res/css/common.scss b/src/res/css/common.scss index d700e96..e48df82 100644 --- a/src/res/css/common.scss +++ b/src/res/css/common.scss @@ -215,7 +215,9 @@ small { text-align: center; width: 100%; } - +.text-center { + text-align: center; +} .invalid-input {