diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index 5fe4f9c..ad3bca8 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -27,6 +27,7 @@ var _ard_sampleLines = [ 0, 360, 720, 1080, 1440, 1800, 2160, 2520, 2876] var _arSetup = function(){ if(Debug.debug) console.log("%c[ArDetect::_ard_setup] Starting automatic aspect ratio detection", _ard_console_start); + this._halted = false; var vid = document.getElementsByTagName("video")[0]; @@ -420,17 +421,23 @@ var _ard_stop = function(){ console.log("%c[ArDetect::_ard_stop] Stopping automatic aspect ratio detection", _ard_console_stop); } this._forcehalt = true; + this._halted = true; clearTimeout(_ard_timer); clearTimeout(_ard_setup_timer); } +var _ard_isRunning = function(){ + return ! this._halted; +} + var ArDetect = { _forcehalt: false, - + _halted: false, arSetup: _arSetup, init: _arSetup, vdraw: _ard_vdraw, detectedAr: 1, arChangedCallback: function() {}, stop: _ard_stop, + isRunning: _ard_isRunning } diff --git a/js/uw-bg.js b/js/uw-bg.js index e13cc1d..94c2dcc 100644 --- a/js/uw-bg.js +++ b/js/uw-bg.js @@ -37,6 +37,34 @@ async function _uwbg_rcvmsg(message){ } return Promise.resolve(response); } + if(message.cmd == "get-config"){ + + var config = {}; + config.videoAlignment = Settings.miscFullscreenSettings.videoFloat; + config.arConf = {}; + config.arConf.enabled_global = Settings.arDetect.enabled == "global"; + + + + // predvidevajmo, da je enako. Če je drugače, bomo popravili ko dobimo odgovor + // assume current is same as global & change that when you get response from content script + config.arConf.enabled_current = Settings.arDetect.enabled == "global"; + + try{ + message.cmd = "get-ardetect-active"; + var response = await sendMessage(message); + if(Debug.debug){ + console.log("[uw-bg::_uwbg_rcvmsg] received response to get-ardetect-active!", {message: message, response: response}); + } + config.arConf.enabled_current = response.response.arDetect_active; + + } + catch(ex){ + console.log("%c[uw-bg::_uwbg_rcvmsg] there was something wrong with request for get-ardetect-active.", "color: #f00", ex); + } + + return Promise.resolve({response: config}); + } else if(message.cmd == "force-ar"){ sendMessage(message); // args: {cmd: string, newAr: number/"auto"} } diff --git a/js/uw.js b/js/uw.js index 537f728..185c290 100644 --- a/js/uw.js +++ b/js/uw.js @@ -79,7 +79,16 @@ function receiveMessage(message) { if(Debug.debug) console.log("[uw::receiveMessage] we received a message.", message); - if(message.cmd == "force-ar"){ + + if(message.cmd == "has-videos"){ + var anyVideos = PageInfo.hasVideos(); + return Promise.resolve({response: {"hasVideos": anyVideos }}); + } + else if(message.cmd == "get-ardetect-active"){ + var arDetect_active = ArDetect.isRunning(); + return Promise.resolve({response: {"arDetect_active": arDetect_active }}); + } + else if(message.cmd == "force-ar"){ if(Debug.debug) console.log("[uw::receiveMessage] we're being commanded to change aspect ratio to", message.newAr); @@ -93,24 +102,20 @@ function receiveMessage(message) { // we aren't in full screen, but we will want aspect ratio to be fixed when we go to Resizer.setFsAr(message.newAr); } - } - if(message.cmd == "force-video-float"){ + } + else if(message.cmd == "force-video-float"){ if(Debug.debug) console.log("[uw::receiveMessage] we're aligning video to", message.newFloat); Settings.miscFullscreenSettings.videoFloat = message.newFloat; Settings.save(); } - if(message.cmd == "stop-autoar"){ + else if(message.cmd == "stop-autoar"){ ArDetect.stop(); } - if(message.cmd == "reload-settings"){ + else if(message.cmd == "reload-settings"){ Settings.reload(); } - if(message.cmd == "has-videos"){ - var anyVideos = PageInfo.hasVideos(); - return Promise.resolve({response: {"hasVideos": anyVideos }}); - } } diff --git a/res/popup/js/popup.js b/res/popup/js/popup.js index 7e3f641..658944a 100644 --- a/res/popup/js/popup.js +++ b/res/popup/js/popup.js @@ -16,9 +16,23 @@ MenuTab.arSettings = document.getElementById("_menu_aspectratio"); MenuTab.cssHacks = document.getElementById("_menu_hacks"); MenuTab.about = document.getElementById("_menu_about"); +var ArPanel = {} +ArPanel.alignment = {}; +ArPanel.alignment.left = document.getElementById("_align_left"); +ArPanel.alignment.center = document.getElementById("_align_center"); +ArPanel.alignment.right = document.getElementById("_align_right"); +ArPanel.autoar = {}; +ArPanel.autoar.enable = document.getElementById("_autoar_enable"); +ArPanel.autoar.disable = document.getElementById("_autoar_disable"); +ArPanel.autoar.enable_tmp = document.getElementById("_autoar_enable_tmp"); +ArPanel.autoar.disable_tmp = document.getElementById("_autoar_disable_tmp"); + + var selectedMenu = "arSettings"; var hasVideos = false; +var _config; + function check4videos(){ var command = {}; command.cmd = "has-videos"; @@ -43,6 +57,46 @@ function check4videos(){ }); } +function check4conf(){ + var command = {}; + command.cmd = "get-config"; + command.sender = "popup"; + command.receiver = "uwbg"; + + browser.runtime.sendMessage(command) + .then(response => { + if(Debug.debug) + console.log("[popup.js::check4conf] received response:",response); + + loadConfig(response.response); + }) + .catch(error => { + if(Debug.debug) + console.log("%c[popup.js::check4conf] sending message failed with error", "color: #f00", error, "%c retrying in 1s ...", "color: #f00"); + + setTimeout(check4conf, 1000); + }); +} + +function loadConfig(config){ + if(Debug.debug) + console.log("[popup.js::loadConfig] loading config. conf object:",config); + + _config = config; + + // process video alignment: + if(config.videoAlignment){ + for(var button in ArPanel.alignment) + ArPanel.alignment[button].classList.remove("selected"); + + ArPanel.alignment[config.videoAlignment].classList.add("selected"); + } + + // process aspect ratio settings + showArctlButtons(); +} + + function openMenu(menu){ if(Debug.debug){ console.log("[popup.js::openMenu] trying to open menu", menu, "| element: ", Menu[menu]); @@ -79,6 +133,51 @@ function openMenu(menu){ } } +function _arctl_onclick(command){ + if(! _config) + return; + + if(command.cmd == "stop-autoar") + _config.arConf.enabled_current = false; + else if(command.cmd == "force-ar") + _config.arConf.enabled_current = true; + else if(command.cmd == "disable-autoar") + _config.arConf.enabled_global = false; + else if(command.cmd == "enable-autoar") + _config.arConf.enabled_global = true; + + showArctlButtons(); +} + +function showArctlButtons(){ + if(! _config) + return; + + if(_config.arConf){ + if(! _config.arConf.enabled_global){ + ArPanel.autoar.disable.classList.add("hidden"); + ArPanel.autoar.enable.classList.remove("hidden"); + + ArPanel.autoar.enable_tmp.textContent = "Temporarily enable"; + ArPanel.autoar.disable_tmp.textContent = "Temporarily disable"; + } + else{ + ArPanel.autoar.disable.classList.remove("hidden"); + ArPanel.autoar.enable.classList.add("hidden"); + + ArPanel.autoar.enable_tmp.textContent = "Re-enable"; + ArPanel.autoar.disable_tmp.textContent = "Temporarily disable"; + } + if(! _config.arConf.enabled_current){ + ArPanel.autoar.disable_tmp.classList.add("hidden"); + ArPanel.autoar.enable_tmp.classList.remove("hidden"); + } + else{ + ArPanel.autoar.disable_tmp.classList.remove("hidden"); + ArPanel.autoar.enable_tmp.classList.add("hidden"); + } + } +} document.addEventListener("click", (e) => { @@ -146,15 +245,21 @@ document.addEventListener("click", (e) => { } if(e.target.classList.contains("_autoar")){ + var command = {}; if(e.target.classList.contains("_autoar_temp-disable")){ - return {cmd: "stop-autoar", sender: "popup", receiver: "uwbg"}; + command = {cmd: "stop-autoar", sender: "popup", receiver: "uwbg"}; } - if(e.target.classList.contains("_autoar_disable")){ - return {cmd: "disable-autoar", sender: "popup", receiver: "uwbg"}; + else if(e.target.classList.contains("_autoar_disable")){ + command = {cmd: "disable-autoar", sender: "popup", receiver: "uwbg"}; } - if(e.target.classList.contains("_autoar_enable")){ - return {cmd: "enable-autoar", sender: "popup", receiver: "uwbg"}; + else if(e.target.classList.contains("_autoar_enable")){ + command = {cmd: "enable-autoar", sender: "popup", receiver: "uwbg"}; } + else{ + command = {cmd: "force-ar", newAr: "auto", sender: "popup", receiver: "uwbg"}; + } + _arctl_onclick(command); + return command; } if(e.target.classList.contains("_align")){ @@ -190,3 +295,4 @@ document.addEventListener("click", (e) => { check4videos(); +check4conf(); diff --git a/res/popup/popup.html b/res/popup/popup.html index e373e4d..a75848c 100644 --- a/res/popup/popup.html +++ b/res/popup/popup.html @@ -23,6 +23,12 @@ font-weight: 200; } + .label{ + font-size: 1.1em; + font-weight: 600; + color: #ffe; + } + .smallcaps{ font-variant: small-caps; } @@ -87,6 +93,11 @@ border: 1px solid #444; margin-top: 3px; margin-bottom: 3px; + color: #dbb; + } + .button:hover { + color: #fff; + background-color: #433221; } .row { @@ -148,7 +159,7 @@
@@ -181,10 +193,10 @@