From 1feeaed257ecb1a4505f8a4cc8756ac3cd1b13cc Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Thu, 23 Aug 2018 01:04:37 +0200 Subject: [PATCH] Some more attempts at making comms/setting saving behave --- js/lib/Comms.js | 4 ++-- js/lib/Settings.js | 18 ++++++++++++++++++ js/lib/VideoData.js | 2 +- js/modules/PageInfo.js | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/js/lib/Comms.js b/js/lib/Comms.js index 52965e4..ef8036a 100644 --- a/js/lib/Comms.js +++ b/js/lib/Comms.js @@ -28,7 +28,7 @@ class CommsClient { console.log("[CommsClient.js::processMessage] Received message from background script!", message); } - if (! this.pageInfo) { + if (! this.pageInfo || this.settings.active) { if(Debug.debug && Debug.comms){ console.log("[CommsClient.js::processMessage] this.pageInfo not defined. Extension is probably disabled for this site."); } @@ -233,7 +233,7 @@ class CommsServer { processReceivedMessage(message, port){ if (Debug.debug && Debug.comms) { - console.log("[CommsServer.js::processMessage] Received message from background script!", message, "port", port); + console.log("[CommsServer.js::processMessage] Received message from background script!", message, "port", port, "\nsettings and server:", this.settings,this.server); } if (message.cmd === 'get-config') { diff --git a/js/lib/Settings.js b/js/lib/Settings.js index 9f72188..b34ecf6 100644 --- a/js/lib/Settings.js +++ b/js/lib/Settings.js @@ -5,6 +5,16 @@ class Settings { this.default = ExtensionConf; this.useSync = false; this.version = undefined; + + const ths = this; + + if(BrowserDetect.firefox) { + browser.storage.onChanged.addListener( (changes, area) => { + if(changes['uwSettings'] && changes['uwSettings'].newValue) { + ths.active = JSON.parse(changes.uwSettings.newValue); + } + }); + } } async init() { @@ -72,6 +82,10 @@ class Settings { } async set(extensionConf) { + if (Debug.debug) { + console.log("[Settings::set] setting new settings:", extensionConf) + } + if (BrowserDetect.firefox || BrowserDetect.edge) { extensionConf.version = this.version; return this.useSync ? browser.storage.sync.set( {'uwSettings': JSON.stringify(extensionConf)}): browser.storage.local.set( {'uwSettings': JSON.stringify(extensionConf)}); @@ -89,6 +103,10 @@ class Settings { } async save() { + if (Debug.debug) { + console.log("[Settings::save] Saving active settings:", this.active); + } + this.set(this.active); } diff --git a/js/lib/VideoData.js b/js/lib/VideoData.js index 5a9a6c9..15a0154 100644 --- a/js/lib/VideoData.js +++ b/js/lib/VideoData.js @@ -50,7 +50,7 @@ class VideoData { this.resizer.destroy(); } if(this.player){ - player.destroy(); + this.player.destroy(); } this.video = null; } diff --git a/js/modules/PageInfo.js b/js/modules/PageInfo.js index 48db0f0..424ac0f 100644 --- a/js/modules/PageInfo.js +++ b/js/modules/PageInfo.js @@ -26,7 +26,7 @@ class PageInfo { reset() { - for(video of this.videos) { + for(var video of this.videos) { video.destroy(); } this.rescan(RescanReason.MANUAL);