Changing persistent settings (the ones _not_ limited to current page) bypasses comms

This commit is contained in:
Tamius Han 2018-08-29 21:23:08 +02:00
parent 6c93a19248
commit 38a94e3bd3

View File

@ -64,9 +64,25 @@ var _config;
var _changeAr_button_shortcuts = { "autoar":"none", "reset":"none", "219":"none", "189":"none", "169":"none", "custom":"none" } var _changeAr_button_shortcuts = { "autoar":"none", "reset":"none", "219":"none", "189":"none", "169":"none", "custom":"none" }
var comms = new Comms(); var comms = new Comms();
var settings = new Settings();
var port = browser.runtime.connect({name: 'popup-port'}); var port = browser.runtime.connect({name: 'popup-port'});
port.onMessage.addListener( (m,p) => processReceivedMessage(m,p)); port.onMessage.addListener( (m,p) => processReceivedMessage(m,p));
// let's init settings and check if they're loaded
await settings.init();
if (Debug.debug) {
console.log("[popup] Are settings loaded?", settings)
}
async function processReceivedMessage(message, port){ async function processReceivedMessage(message, port){
if(message.cmd === 'set-config'){ if(message.cmd === 'set-config'){
@ -100,16 +116,16 @@ function stringToKeyCombo(key_in){
return keys_out; return keys_out;
} }
function loadConfig(extensionConf, site){ async function loadConfig(){
if(Debug.debug) if(Debug.debug)
console.log("[popup.js::loadConfig] loading config. conf object:", extensionConf, "\n\n\n\n\n\n\n\n-------------------------------------"); console.log("[popup.js::loadConfig] loading config. conf object:", settings.active, "\n\n\n\n\n\n\n\n-------------------------------------");
_extensionConf = extensionConf;
// ---------------------- // ----------------------
//#region extension-basics - SET BASIC EXTENSION OPTIONS //#region extension-basics - SET BASIC EXTENSION OPTIONS
if(Debug.debug) if(Debug.debug)
console.log("EXT: site is:", site, "|extensionConf for this site: ", (site && extensionConf.sites[site]) ? extensionConf.sites[site] : "default site") console.log("EXT: site is:", site, "|settings for this site: ", (site && settings.active.sites[site]) ? settings.active.sites[site] : "default site")
for(var button in ExtPanel.globalOptions) { for(var button in ExtPanel.globalOptions) {
@ -119,9 +135,9 @@ function loadConfig(extensionConf, site){
ExtPanel.siteOptions[button].classList.remove("selected"); ExtPanel.siteOptions[button].classList.remove("selected");
} }
ExtPanel.globalOptions[extensionConf.extensionMode].classList.add("selected"); ExtPanel.globalOptions[settings.active.extensionMode].classList.add("selected");
if(site && extensionConf.sites[site]) { if(site && settings.active.sites[site]) {
ExtPanel.siteOptions[extensionConf.sites[site].status].classList.add("selected"); ExtPanel.siteOptions[settings.active.sites[site].status].classList.add("selected");
} else { } else {
ExtPanel.siteOptions.default.classList.add("selected"); ExtPanel.siteOptions.default.classList.add("selected");
} }
@ -131,9 +147,9 @@ function loadConfig(extensionConf, site){
// ------------ // ------------
//#region autoar - SET AUTOAR OPTIONS //#region autoar - SET AUTOAR OPTIONS
// if(Debug.debug) // if(Debug.debug)
// console.log("Autodetect mode?", extensionConf.arDetect.mode, "| site & site options:", site, ",", (site && extensionConf.sites[site]) ? extensionConf.sites[site].arStatus : "fucky wucky?" ); // console.log("Autodetect mode?", settings.active.arDetect.mode, "| site & site options:", site, ",", (site && settings.active.sites[site]) ? settings.active.sites[site].arStatus : "fucky wucky?" );
// document.getElementById("_autoAr_disabled_reason").textContent = extensionConf.arDetect.DisabledReason; // document.getElementById("_autoAr_disabled_reason").textContent = settings.active.arDetect.DisabledReason;
document.getElementById("_input_autoAr_timer").value = extensionConf.arDetect.timer_playing; document.getElementById("_input_autoAr_timer").value = settings.active.arDetect.timer_playing;
for(var button in AutoArPanel.globalOptions) { for(var button in AutoArPanel.globalOptions) {
@ -144,20 +160,20 @@ function loadConfig(extensionConf, site){
} }
AutoArPanel.globalOptions[extensionConf.arDetect.mode].classList.add("selected"); AutoArPanel.globalOptions[settings.active.arDetect.mode].classList.add("selected");
if(site && extensionConf.sites[site]) { if(site && settings.active.sites[site]) {
AutoArPanel.siteOptions[extensionConf.sites[site].arStatus].classList.add("selected"); AutoArPanel.siteOptions[settings.active.sites[site].arStatus].classList.add("selected");
} else { } else {
AutoArPanel.siteOptions.default.classList.add("selected"); AutoArPanel.siteOptions.default.classList.add("selected");
} }
//#endregion //#endregion
// process video alignment: // process video alignment:
if(extensionConf.miscFullscreenSettings.videoFloat){ if(settings.active.miscFullscreenSettings.videoFloat){
for(var button in ArPanel.alignment) for(var button in ArPanel.alignment)
ArPanel.alignment[button].classList.remove("selected"); ArPanel.alignment[button].classList.remove("selected");
ArPanel.alignment[extensionConf.miscFullscreenSettings.videoFloat].classList.add("selected"); ArPanel.alignment[settings.active.miscFullscreenSettings.videoFloat].classList.add("selected");
} }
//#region - SET STRETCH //#region - SET STRETCH
@ -166,21 +182,21 @@ function loadConfig(extensionConf, site){
for (var button in StretchPanel.global) { for (var button in StretchPanel.global) {
StretchPanel.global[button].classList.remove("selected"); StretchPanel.global[button].classList.remove("selected");
} }
if (extensionConf.stretch.initialMode === 0) { if (settings.active.stretch.initialMode === 0) {
StretchPanel.global.none.classList.add("selected"); StretchPanel.global.none.classList.add("selected");
} else if (extensionConf.stretch.initialMode === 1) { } else if (settings.active.stretch.initialMode === 1) {
StretchPanel.global.basic.classList.add("selected"); StretchPanel.global.basic.classList.add("selected");
} else if (extensionConf.stretch.initialMode === 2) { } else if (settings.active.stretch.initialMode === 2) {
StretchPanel.global.hybrid.classList.add("selected"); StretchPanel.global.hybrid.classList.add("selected");
} else if (extensionConf.stretch.initialMode === 3) { } else if (settings.active.stretch.initialMode === 3) {
StretchPanel.global.conditional.classList.add("selected"); StretchPanel.global.conditional.classList.add("selected");
} }
//#endregion //#endregion
// process keyboard shortcuts: // process keyboard shortcuts:
if(extensionConf.keyboard.shortcuts){ if(settings.active.keyboard.shortcuts){
for(var key in extensionConf.keyboard.shortcuts){ for(var key in settings.active.keyboard.shortcuts){
var shortcut = extensionConf.keyboard.shortcuts[key]; var shortcut = settings.active.keyboard.shortcuts[key];
var keypress = stringToKeyCombo(key); var keypress = stringToKeyCombo(key);
@ -217,8 +233,8 @@ function loadConfig(extensionConf, site){
} }
// fill in custom aspect ratio // fill in custom aspect ratio
if (extensionConf.keyboard.shortcuts.q) { if (settings.active.keyboard.shortcuts.q) {
document.getElementById("_input_custom_ar").value = extensionConf.keyboard.shortcuts.q.arg; document.getElementById("_input_custom_ar").value = settings.active.keyboard.shortcuts.q.arg;
} }
} }
for(var key in _changeAr_button_shortcuts){ for(var key in _changeAr_button_shortcuts){
@ -379,15 +395,15 @@ document.addEventListener("click", (e) => {
if(e.target.classList.contains("_ext")) { if(e.target.classList.contains("_ext")) {
var command = {}; var command = {};
if(e.target.classList.contains("_ext_global_options")){ if(e.target.classList.contains("_ext_global_options")){
command.cmd = "set-extension-defaults";
if (e.target.classList.contains("_blacklist")) { if (e.target.classList.contains("_blacklist")) {
command.mode = "blacklist"; settings.active.extensionMode = "blacklist";
} else if (e.target.classList.contains("_whitelist")) { } else if (e.target.classList.contains("_whitelist")) {
command.mode = "whitelist"; settings.active.extensionMode = "whitelist";
} else { } else {
command.mode = "disabled"; settings.active.extensionMode = "disabled";
} }
return command; settings.save();
return;
} else if (e.target.classList.contains("_ext_site_options")) { } else if (e.target.classList.contains("_ext_site_options")) {
command.cmd = "set-extension-for-site"; command.cmd = "set-extension-for-site";
if(e.target.classList.contains("_blacklist")){ if(e.target.classList.contains("_blacklist")){
@ -456,17 +472,17 @@ document.addEventListener("click", (e) => {
} }
if(e.target.classList.contains("_stretch")){ if(e.target.classList.contains("_stretch")){
if (e.target.classList.contains("_ar_stretch_global")) { if (e.target.classList.contains("_ar_stretch_global")) {
command.cmd = "set-stretch-default"
if (e.target.classList.contains("_none")) { if (e.target.classList.contains("_none")) {
command.mode = 0; settings.active.stretch.initialMode = 0;
} else if (e.target.classList.contains("_basic")) { } else if (e.target.classList.contains("_basic")) {
command.mode = 1; settings.active.stretch.initialMode = 1;
} else if (e.target.classList.contains("_hybrid")) { } else if (e.target.classList.contains("_hybrid")) {
command.mode = 2; settings.active.stretch.initialMode = 2;
} else if (e.target.classList.contains("_conditional")) { } else if (e.target.classList.contains("_conditional")) {
command.mode = 3; settings.active.stretch.initialMode = 3;
} }
return command; settings.save();
return;
} }
if(e.target.classList.contains("_ar_stretch_none")) { if(e.target.classList.contains("_ar_stretch_none")) {
@ -486,22 +502,22 @@ document.addEventListener("click", (e) => {
} }
if(e.target.classList.contains("_autoAr")){ if(e.target.classList.contains("_autoAr")){
if(e.target.classList.contains("_ar_global_options")){ if(e.target.classList.contains("_ar_global_options")){
command.cmd = "set-autoar-defaults";
if (e.target.classList.contains("_blacklist")) { if (e.target.classList.contains("_blacklist")) {
command.mode = "blacklist"; settings.active.arDetect.mode = "blacklist";
} else if (e.target.classList.contains("_whitelist")) { } else if (e.target.classList.contains("_whitelist")) {
command.mode = "whitelist"; settings.active.arDetect.mode = "whitelist";
} else { } else {
command.mode = "disabled"; settings.active.arDetect.mode = "disabled";
} }
return command; settings.save();
return;
} else if (e.target.classList.contains("_save_autoAr_frequency")) { } else if (e.target.classList.contains("_save_autoAr_frequency")) {
var value = parseInt(document.getElementById("_input_autoAr_frequency").value.trim()); var value = parseInt(document.getElementById("_input_autoAr_frequency").value.trim());
if(! isNaN(value)){ if(! isNaN(value)){
var timeout = parseInt(value); var timeout = parseInt(value);
command = {cmd: "autoar-set-timer-playing", timeout: timeout, sender: "popup", receiver: "uwbg"}; settings.active.arDetect.timer_playing = timeout;
Comms.sendToBackgroundScript(command); settings.save();
} }
return; return;
} else if (e.target.classList.contains("_ar_site_options")) { } else if (e.target.classList.contains("_ar_site_options")) {
@ -521,29 +537,17 @@ document.addEventListener("click", (e) => {
command.global = true; command.global = true;
if(e.target.classList.contains("_align_left")){ if (e.target.classList.contains("_align_left")) {
command.cmd = "set-video-float", settings.active.miscFullscreenSettings.videoFloat = 'left';
command.newFloat = "left" } else if (e.target.classList.contains("_align_center")) {
settings.active.miscFullscreenSettings.videoFloat = 'center';
// console.log(".................\n\n\n..........\n\n >>command<< \n\n\n\n ",command,"\n\n\n.........\n\n\n................................"); } else if (e.target.classList.contains("_align_right")) {
settings.active.miscFullscreenSettings.videoFloat = 'left';
return command;
} }
if(e.target.classList.contains("_align_center")){
command.cmd = "set-video-float" settings.save();
command.newFloat = "center" return;
return command; }
}
if(e.target.classList.contains("_align_right")){
command.cmd = "set-video-float";
command.newFloat = "right";
return command;
}
}
if(e.target.classList.contains("extensionEnabledOnCurrentSite")){ // legacy? can be removed?
toggleSite(document.extensionEnabledOnCurrentSite.mode.value);
}
} }
var command = getcmd(e); var command = getcmd(e);