Comms: accounted for the possibility of pageInfo missing when extension is disabled

This commit is contained in:
Tamius Han 2018-08-22 23:46:59 +02:00
parent 2619b02263
commit 107c9b12bd
3 changed files with 11 additions and 2 deletions

View File

@ -16,6 +16,7 @@ class CommsClient {
this.port.onMessage.addListener(m => ths.processReceivedMessage(m));
this.settings = settings;
this.pageInfo = undefined;
}
setPageInfo(pageInfo){
@ -27,6 +28,13 @@ class CommsClient {
console.log("[CommsClient.js::processMessage] Received message from background script!", message);
}
if (! this.pageInfo) {
if(Debug.debug && Debug.comms){
console.log("[CommsClient.js::processMessage] this.pageInfo not defined. Extension is probably disabled for this site.");
}
return;
}
if (message.cmd === "set-ar") {
this.pageInfo.setAr(message.ratio);
} else if (message.cmd === 'set-video-float') {
@ -282,6 +290,7 @@ class CommsServer {
} else if (message.cmd === "set-autoar-for-site") {
if (this.settings.active.sites[this.server.currentSite]) {
this.settings.active.sites[this.server.currentSite].arStatus = message.mode;
console.log("SAVING AUTOAR MODE FOR SITE", this.server.currentSite, "\nnew site obj",this.settings.active.sites[this.server.currentSite] )
this.settings.save();
} else {
this.settings.active.sites[this.server.currentSite] = {

View File

@ -17,6 +17,7 @@ class PageInfo {
if(comms){
this.comms = comms;
this.comms.setPageInfo(this);
if(this.videos.length > 0){
comms.registerVideo();
}
@ -24,7 +25,7 @@ class PageInfo {
}
reset(){
reset() {
for(video of this.videos) {
video.destroy();
}

View File

@ -57,7 +57,6 @@ async function init(){
}
pageInfo = new PageInfo(comms, settings);
comms.setPageInfo(pageInfo);
if(Debug.debug){
console.log("[uw.js::setup] pageInfo initialized. Here's the object:", pageInfo);