Fix popup not working at all in Chrome

This commit is contained in:
Tamius Han 2020-12-21 19:29:52 +01:00
parent becf7c328e
commit 4b5c5a8dce

View File

@ -210,6 +210,7 @@ import DefaultSettingsPanel from './panels/DefaultSettingsPanel';
import AboutPanel from './panels/AboutPanel'; import AboutPanel from './panels/AboutPanel';
import ExtensionMode from '../common/enums/extension-mode.enum'; import ExtensionMode from '../common/enums/extension-mode.enum';
import Logger from '../ext/lib/Logger'; import Logger from '../ext/lib/Logger';
import {ChromeShittinessMitigations as CSM} from '../common/js/ChromeShittinessMitigations';
export default { export default {
data () { data () {
@ -219,7 +220,6 @@ export default {
selectedSite: '', selectedSite: '',
activeFrames: [], activeFrames: [],
activeSites: [], activeSites: [],
port: BrowserDetect.firefox ? browser.runtime.connect({name: 'popup-port'}) : chrome.runtime.connect({name: 'popup-port'}),
comms: new Comms(), comms: new Comms(),
frameStore: {}, frameStore: {},
frameStoreCount: 0, frameStoreCount: 0,
@ -249,12 +249,15 @@ export default {
await this.settings.init(); await this.settings.init();
this.settingsInitialized = true; this.settingsInitialized = true;
this.port.onMessage.addListener( (m,p) => this.processReceivedMessage(m,p)); const port = BrowserDetect.firefox ? browser.runtime.connect({name: 'popup-port'}) : chrome.runtime.connect({name: 'popup-port'});
port.onMessage.addListener( (m,p) => this.processReceivedMessage(m,p));
CSM.setProperty('port', port);
this.execAction.setSettings(this.settings); this.execAction.setSettings(this.settings);
// ensure we'll clean player markings on popup close // ensure we'll clean player markings on popup close
window.addEventListener("unload", () => { window.addEventListener("unload", () => {
this.port.postMessage({ CSM.port.postMessage({
cmd: 'unmark-player', cmd: 'unmark-player',
forwardToAll: true, forwardToAll: true,
}); });
@ -314,7 +317,7 @@ export default {
getSite() { getSite() {
try { try {
this.logger.log('info','popup', '[popup::getSite] Requesting current site ...') this.logger.log('info','popup', '[popup::getSite] Requesting current site ...')
this.port.postMessage({cmd: 'get-current-site'}); CSM.port.postMessage({cmd: 'get-current-site'});
} catch (e) { } catch (e) {
this.logger.log('error','popup','[popup::getSite] sending get-current-site failed for some reason. Reason:', e); this.logger.log('error','popup','[popup::getSite] sending get-current-site failed for some reason. Reason:', e);
} }
@ -370,9 +373,8 @@ export default {
} }
} }
if (!this.site || this.site.host !== message.site.host) { if (!this.site || this.site.host !== message.site.host) {
this.port.postMessage({cmd: 'get-current-zoom'}); CSM.port.postMessage({cmd: 'get-current-zoom'});
} }
console.log("processing received message:", message)
this.site = message.site; this.site = message.site;
// update activeSites // update activeSites
@ -472,7 +474,7 @@ export default {
this.frameStore[frame] = fs; this.frameStore[frame] = fs;
this.port.postMessage({ CSM.port.postMessage({
cmd: 'mark-player', cmd: 'mark-player',
forwardToContentScript: true, forwardToContentScript: true,
targetTab: videoTab.id, targetTab: videoTab.id,
@ -525,7 +527,6 @@ export default {
this.selectedSite = host; this.selectedSite = host;
}, },
toggleSideMenu(visible) { toggleSideMenu(visible) {
console.warn('toggling side menu visible to:', visible ?? !this.sideMenuVisible, "arg:", visible )
this.sideMenuVisible = visible ?? !this.sideMenuVisible; this.sideMenuVisible = visible ?? !this.sideMenuVisible;
} }
} }