From a2f1c8eba202a3517711308bdbd334cc1f041e30 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 20 Jan 2019 20:36:24 +0100 Subject: [PATCH] Sending commands to single frames seems to work, kinda --- src/ext/lib/comms/Comms.js | 3 +- src/ext/lib/comms/CommsServer.js | 2 +- src/popup/App.vue | 61 ++++++++++++++------------------ src/popup/js/ExecAction.js | 1 + src/popup/panels/VideoPanel.vue | 2 +- 5 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/ext/lib/comms/Comms.js b/src/ext/lib/comms/Comms.js index 6474c74..a07b75a 100644 --- a/src/ext/lib/comms/Comms.js +++ b/src/ext/lib/comms/Comms.js @@ -3,8 +3,7 @@ import BrowserDetect from '../../conf/BrowserDetect'; class Comms { static async sendMessage(message){ - message = JSON.parse(JSON.stringify(message)); // vue quirk. We should really use vue store instead - + if(BrowserDetect.firefox){ return browser.runtime.sendMessage(message) } else { diff --git a/src/ext/lib/comms/CommsServer.js b/src/ext/lib/comms/CommsServer.js index 9e2e8f6..13617b4 100644 --- a/src/ext/lib/comms/CommsServer.js +++ b/src/ext/lib/comms/CommsServer.js @@ -73,7 +73,7 @@ class CommsServer { } async sendToFrame(message, tab, frame) { - message = JSON.parse(JSON.stringify(message)); // vue quirk. We should really use vue store instead + // message = JSON.parse(JSON.stringify(message)); // vue quirk. We should really use vue store instead if(Debug.debug && Debug.comms){ console.log(`%c[CommsServer::sendToFrame] attempting to send message to tab ${tab}, frame ${frame}`, "background: #dda; color: #11D", message); } diff --git a/src/popup/App.vue b/src/popup/App.vue index 1a61f3d..75f05be 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -32,15 +32,18 @@ @click="selectTab('video')" >
- Video settings ({{activeFrames.length}}) + Video settings
-
- {{frame.label}} + {{frame.label}} {{frame.id}}
@@ -180,13 +183,8 @@ export default { } else if (message.cmd === 'set-current-zoom') { this.setCurrentZoom(message.zoom); } - - - console.log("this?", this, "this.site:", JSON.parse(JSON.stringify(this.site))); }, loadFrames(videoTab) { - console.log("set-c loading frames \n\n\n------------------------------------------------------------------\n\n\n1\n\n") - console.log('set-c loading frames', videoTab, JSON.parse(JSON.stringify(videoTab))) if (videoTab.selected) { this.selectedSubitem = videoTab.selected; // selectedSubitemLoaded = true; @@ -196,47 +194,37 @@ export default { if (videoTab.frames.length < 2 || Object.keys(videoTab.frames).length < 2) { this.selectedFrame = '__all'; - console.log("set-c NOT ENOUGH FRAMES ______________________________________\n", videoTab.frames.length, Object.keys(videoTab.frames), Object.keys(videoTab.frames).length ) return; } - console.log("set-c loading frames \n\n\n------------------------------------------------------------------\n\n\n2\n\n") + for (const frame in videoTab.frames) { - try { - for (const frame in videoTab.frames) { - - if (frame && !this.frameStore[frame]) { - const fs = { - name: this.frameStoreCount++, - color: this.getRandomColor() - } - - this.frameStore[frame] = fs; - - this.port.postMessage(this.toObject({ - cmd: 'mark-player', - targetTab: videoTab.id, - targetFrame: frame, - name: fs.name, - color: fs.color - })); + if (frame && !this.frameStore[frame]) { + const fs = { + name: this.frameStoreCount++, + color: this.getRandomColor() } - console.log("set-c loading frames \n\n\n------------------------------------------------------------------\n\n\n22\n\n") - } - } catch (e) { - console.log("set-c loading frames \n\n\n------------------------------------------------------------------\n\n\ne", e, "\n\n") + this.frameStore[frame] = fs; + + this.port.postMessage({ + cmd: 'mark-player', + targetTab: videoTab.id, + targetFrame: frame, + name: fs.name, + color: fs.color + }); + } } - console.log("set-c loading frames \n\n\n------------------------------------------------------------------\n\n\n3\n\n") this.activeFrames = [{id: '__all', label: 'All'},{id: '__playing', label: 'Currently playing'}]; + for (const frame in videoTab.frames) { this.activeFrames.push({ + id: `${this.site.id}-${frame}`, label: videoTab.frames[frame].host, ...this.frameStore[frame], }) } - - console.log("set-c active frmaes", this.activeFrames, JSON.parse(JSON.stringify(this.activeFrames))) }, getRandomColor() { return `rgb(${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)})`; @@ -246,6 +234,9 @@ export default { }, updateZoom(nz){ this.currentZoom = nz; + }, + selectFrame(id){ + this.selectedFrame = id; } } } diff --git a/src/popup/js/ExecAction.js b/src/popup/js/ExecAction.js index aacc52e..8346e33 100644 --- a/src/popup/js/ExecAction.js +++ b/src/popup/js/ExecAction.js @@ -15,6 +15,7 @@ class ExecAction { const message = { forwardToContentScript: true, targetFrame: frame, + frame: frame, cmd: cmd.action, arg: cmd.arg } diff --git a/src/popup/panels/VideoPanel.vue b/src/popup/panels/VideoPanel.vue index 0135188..ef47d7a 100644 --- a/src/popup/panels/VideoPanel.vue +++ b/src/popup/panels/VideoPanel.vue @@ -125,7 +125,7 @@ export default { } }, methods: { - execAction(action) { + execAction(action) { this.exec.exec(action, 'page', this.frame); }, parseShortcut(action) {