From c1d34fceb19dda2cc7fe6a5283467fe513c792d2 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Wed, 13 Feb 2019 23:58:19 +0100 Subject: [PATCH] Popups sorta work --- src/ext/lib/Settings.js | 26 ++++++--- src/popup/App.vue | 11 +++- src/popup/js/ExecAction.js | 28 +++++++--- src/popup/panels/DefaultSettingsPanel.vue | 64 ++++++++++++++++++----- 4 files changed, 99 insertions(+), 30 deletions(-) diff --git a/src/ext/lib/Settings.js b/src/ext/lib/Settings.js index 1006eaa..1c69939 100644 --- a/src/ext/lib/Settings.js +++ b/src/ext/lib/Settings.js @@ -3,6 +3,8 @@ import currentBrowser from '../conf/BrowserDetect'; import ExtensionConf from '../conf/ExtensionConf'; import ExtensionMode from '../../common/enums/extension-mode.enum'; import ObjectCopy from '../lib/ObjectCopy'; +import Stretch from '../../common/enums/stretch.enum'; +import VideoAlignment from '../../common/enums/video-alignment.enum'; class Settings { @@ -13,14 +15,6 @@ class Settings { this.version = undefined; this.updateCallback = updateCallback; - - console.log("chrome object:", chrome) - console.log("browser.storage", browser.storage) - console.log("browser object:", browser) - console.log("window.browser", window.browser) - console.log("ExtensionConf", ExtensionConf) - - const ths = this; if(currentBrowser.firefox) { @@ -353,6 +347,22 @@ class Settings { } } + getDefaultOption(option) { + const allDefault = { + mode: ExtensionMode.Default, + autoar: ExtensionMode.Default, + autoarFallback: ExtensionMode.Default, + stretch: Stretch.Default, + videoAlignment: VideoAlignment.Default, + }; + + if (!option || allDefault[option] === undefined) { + return allDefault; + } + + return allDefault[option]; + } + getDefaultAr(site) { site = this.getSiteSettings(site); diff --git a/src/popup/App.vue b/src/popup/App.vue index 27a585c..b8a114c 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -74,6 +74,15 @@
+ This is some debug stuff. Please remove before release. Site: {{site.host}}
+ NOTE: in case you're using nightly builds, this extension could be completely broken. + It's also possible that everything is getting logged excessively, which may result in + degraded performance. If settings don't persist, check whether Debug.flushStorageSettings is set to true. + + this.processReceivedMessage(m,p)); this.execAction.setSettings(this.settings); diff --git a/src/popup/js/ExecAction.js b/src/popup/js/ExecAction.js index 475b142..581d5b0 100644 --- a/src/popup/js/ExecAction.js +++ b/src/popup/js/ExecAction.js @@ -1,13 +1,17 @@ import Comms from '../../ext/lib/comms/Comms'; class ExecAction { - constructor(settings) { + constructor(settings, site) { this.settings = settings; + this.site = site; } setSettings(settings) { this.settings = settings; } + setSite(site) { + this.site = site; + } exec(action, scope, frame) { for (var cmd of action.cmd) { @@ -21,14 +25,24 @@ class ExecAction { } Comms.sendMessage(message); } else if (scope === 'site') { + + let site = this.site; + if (!this.site) { + site = window.location.host; + } + + if (!this.settings.active.sites[site]) { + this.settings.active.sites[site] = this.settings.getDefaultOption(); + } + if (cmd.action === "set-stretch") { - this.settings.active.sites[window.location.host].stretch = cmd.arg; + this.settings.active.sites[site].stretch = cmd.arg; } else if (cmd.action === "set-alignment") { - this.settings.active.sites[window.location.host].videoAlignment = cmd.arg; + this.settings.active.sites[site].videoAlignment = cmd.arg; } else if (cmd.action === "set-extension-mode") { - this.settings.active.sites[window.location.host].status = cmd.arg; + this.settings.active.sites[site].mode = cmd.arg; } else if (cmd.action === "set-autoar-mode") { - this.settings.active.sites[window.location.host].arStatus = cmd.arg; + this.settings.active.sites[site].autoar = cmd.arg; } this.settings.save(); } else if (scope === 'global') { @@ -37,9 +51,9 @@ class ExecAction { } else if (cmd.action === "set-alignment") { this.settings.active.sites['@global'].videoAlignment = cmd.arg; } else if (cmd.action === "set-extension-mode") { - this.settings.active.sites['@global'] = cmd.arg; + this.settings.active.sites['@global'].mode = cmd.arg; } else if (cmd.action === "set-autoar-mode") { - this.settings.active.sites['@global'].autoar.arStatus = cmd.arg; + this.settings.active.sites['@global'].autoar = cmd.arg; } this.settings.save(); } diff --git a/src/popup/panels/DefaultSettingsPanel.vue b/src/popup/panels/DefaultSettingsPanel.vue index f8794cb..cecc6f5 100644 --- a/src/popup/panels/DefaultSettingsPanel.vue +++ b/src/popup/panels/DefaultSettingsPanel.vue @@ -1,16 +1,15 @@