Sending commands to single frames seems to work, kinda

This commit is contained in:
Tamius Han 2019-01-20 20:36:24 +01:00
parent b49f8c6d26
commit a2f1c8eba2
5 changed files with 30 additions and 39 deletions

View File

@ -3,8 +3,7 @@ import BrowserDetect from '../../conf/BrowserDetect';
class Comms { class Comms {
static async sendMessage(message){ static async sendMessage(message){
message = JSON.parse(JSON.stringify(message)); // vue quirk. We should really use vue store instead
if(BrowserDetect.firefox){ if(BrowserDetect.firefox){
return browser.runtime.sendMessage(message) return browser.runtime.sendMessage(message)
} else { } else {

View File

@ -73,7 +73,7 @@ class CommsServer {
} }
async sendToFrame(message, tab, frame) { 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){ if(Debug.debug && Debug.comms){
console.log(`%c[CommsServer::sendToFrame] attempting to send message to tab ${tab}, frame ${frame}`, "background: #dda; color: #11D", message); console.log(`%c[CommsServer::sendToFrame] attempting to send message to tab ${tab}, frame ${frame}`, "background: #dda; color: #11D", message);
} }

View File

@ -32,15 +32,18 @@
@click="selectTab('video')" @click="selectTab('video')"
> >
<div class=""> <div class="">
Video settings ({{activeFrames.length}}) Video settings
</div> </div>
<div class=""> <div class="">
</div> </div>
<div class=""> <div class="">
<div v-for="frame of activeFrames" <div class=""
:class="{'tabitem-selected': selectedFrame === frame.id}"
v-for="frame of activeFrames"
:key="frame.id" :key="frame.id"
@click="selectFrame(frame.id)"
> >
{{frame.label}} {{frame.label}} {{frame.id}}
</div> </div>
</div> </div>
</div> </div>
@ -180,13 +183,8 @@ export default {
} else if (message.cmd === 'set-current-zoom') { } else if (message.cmd === 'set-current-zoom') {
this.setCurrentZoom(message.zoom); this.setCurrentZoom(message.zoom);
} }
console.log("this?", this, "this.site:", JSON.parse(JSON.stringify(this.site)));
}, },
loadFrames(videoTab) { 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) { if (videoTab.selected) {
this.selectedSubitem = videoTab.selected; this.selectedSubitem = videoTab.selected;
// selectedSubitemLoaded = true; // selectedSubitemLoaded = true;
@ -196,47 +194,37 @@ export default {
if (videoTab.frames.length < 2 || Object.keys(videoTab.frames).length < 2) { if (videoTab.frames.length < 2 || Object.keys(videoTab.frames).length < 2) {
this.selectedFrame = '__all'; this.selectedFrame = '__all';
console.log("set-c NOT ENOUGH FRAMES ______________________________________\n", videoTab.frames.length, Object.keys(videoTab.frames), Object.keys(videoTab.frames).length )
return; return;
} }
console.log("set-c loading frames \n\n\n------------------------------------------------------------------\n\n\n2\n\n") for (const frame in videoTab.frames) {
try { if (frame && !this.frameStore[frame]) {
for (const frame in videoTab.frames) { const fs = {
name: this.frameStoreCount++,
if (frame && !this.frameStore[frame]) { color: this.getRandomColor()
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
}));
} }
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'}]; this.activeFrames = [{id: '__all', label: 'All'},{id: '__playing', label: 'Currently playing'}];
for (const frame in videoTab.frames) { for (const frame in videoTab.frames) {
this.activeFrames.push({ this.activeFrames.push({
id: `${this.site.id}-${frame}`,
label: videoTab.frames[frame].host, label: videoTab.frames[frame].host,
...this.frameStore[frame], ...this.frameStore[frame],
}) })
} }
console.log("set-c active frmaes", this.activeFrames, JSON.parse(JSON.stringify(this.activeFrames)))
}, },
getRandomColor() { getRandomColor() {
return `rgb(${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)})`; 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){ updateZoom(nz){
this.currentZoom = nz; this.currentZoom = nz;
},
selectFrame(id){
this.selectedFrame = id;
} }
} }
} }

View File

@ -15,6 +15,7 @@ class ExecAction {
const message = { const message = {
forwardToContentScript: true, forwardToContentScript: true,
targetFrame: frame, targetFrame: frame,
frame: frame,
cmd: cmd.action, cmd: cmd.action,
arg: cmd.arg arg: cmd.arg
} }

View File

@ -125,7 +125,7 @@ export default {
} }
}, },
methods: { methods: {
execAction(action) { execAction(action) {
this.exec.exec(action, 'page', this.frame); this.exec.exec(action, 'page', this.frame);
}, },
parseShortcut(action) { parseShortcut(action) {