diff --git a/js/lib/Comms.js b/js/lib/Comms.js index ad7e9b9..2e3d727 100644 --- a/js/lib/Comms.js +++ b/js/lib/Comms.js @@ -232,6 +232,9 @@ class CommsServer { } if (message.cmd === 'get-config') { + if(Debug.debug) { + console.log("CommsServer: received get-config. Active settings?", this.settings.active, "\n(settings:", this.settings, ")") + } port.postMessage({cmd: "set-config", conf: this.settings.active, site: this.server.currentSite}) } else if (message.cmd === 'set-stretch') { this.sendToActive(message); diff --git a/js/lib/Settings.js b/js/lib/Settings.js index 2981b50..2d1cd98 100644 --- a/js/lib/Settings.js +++ b/js/lib/Settings.js @@ -3,18 +3,18 @@ class Settings { constructor(activeSettings) { this.active = activeSettings ? activeSettings : {}; this.default = ExtensionConf; + this.useSync = false; } async init() { - const settings = await this.get('uw-settings'); + const settings = await this.get(); if(Debug.debug) { - console.log("[Settings::init] Configuration fetched from background script:", settings); + console.log("[Settings::init] Configuration fetched from storage:", settings); } // if there's no settings saved, return default settings. if(! settings || (Object.keys(settings).length === 0 && settings.constructor === Object)) { - console.log("NO SETTINGS") this.setDefaultSettings(); this.active = this.getDefaultSettings(); return this.active; @@ -50,8 +50,12 @@ class Settings { async get() { if (BrowserDetect.firefox || BrowserDetect.edge) { - const ret = browser.storage.sync.get('uw-settings'); - return ret['uw-settings']; + const ret = this.useSync ? await browser.storage.sync.get('uw-settings') : await browser.storage.local.get('uw-settings'); + try { + return JSON.parse(ret['uw-settings']); + } catch(e) { + return undefined; + } } else if (BrowserDetect.chrome) { const ret = chrome.storage.sync.get('uw-settings'); return ret['uw-settings']; @@ -60,7 +64,7 @@ class Settings { async set(extensionConf) { if (BrowserDetect.firefox || BrowserDetect.edge) { - return browser.storage.sync.set( {'uw-settings': extensionConf}); + return this.useSync ? browser.storage.sync.set( {'uw-settings': JSON.stringify(extensionConf)}): browser.storage.local.set( {'uw-settings': JSON.stringify(extensionConf)}); } else if (BrowserDetect.chrome) { return chrome.storage.sync.set( {'uw-settings': extensionConf}); } @@ -125,11 +129,11 @@ class Settings { const cse = this.canStartExtension(site); Debug.debug = true; - console.log("[Settings::canStartExtension] ----------------\nCAN WE START THIS EXTENSION ON SITE", site, - "?\n\nsettings.active.sites[site]=", this.active.sites[site], - "\nExtension mode?", this.active.extensionMode, - "\nCan extension be started?", cse - ); + // console.log("[Settings::canStartExtension] ----------------\nCAN WE START THIS EXTENSION ON SITE", site, + // "?\n\nsettings.active.sites[site]=", this.active.sites[site], + // "\nExtension mode?", this.active.extensionMode, + // "\nCan extension be started?", cse + // ); } try{ // if site is not defined, we use default mode: diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index fdb29f1..6e83f65 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -228,12 +228,14 @@ class ArDetector { ); } - scheduleFrameCheck(timeout, force_reset){ + async scheduleFrameCheck(timeout, force_reset){ if(! timeout){ this.frameCheck(); return; } + var e = await this.settings.get(); + console.log("settings?", this.settings.active, e); // run anything that needs to be run after frame check this.postFrameCheck(); diff --git a/res/popup/js/popup.js b/res/popup/js/popup.js index 2de3c06..ec468af 100644 --- a/res/popup/js/popup.js +++ b/res/popup/js/popup.js @@ -69,6 +69,11 @@ port.onMessage.addListener( (m,p) => processReceivedMessage(m,p)); async function processReceivedMessage(message, port){ if(message.cmd === 'set-config'){ + + if(Debug.debug){ + console.log("[popup.js] setting config. Message was:", message) + } + this.loadConfig(message.conf, message.site); } } diff --git a/res/popup/popup.html b/res/popup/popup.html index 8dacc5a..113512a 100644 --- a/res/popup/popup.html +++ b/res/popup/popup.html @@ -257,10 +257,9 @@ - - +