From c35a8c5f5945b9de3af96b61b6480a6d3b558c99 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 5 May 2018 23:06:39 +0200 Subject: [PATCH] Added a safety thingy that disables autodetection if autodetection consistenly causes lag. --- CHANGELOG.md | 9 ++++++--- js/modules/ArDetect.js | 9 +++++++++ js/uw-bg.js | 2 ++ res/popup/js/popup.js | 2 +- res/popup/popup.html | 6 +++++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c59e6a8..c605b25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Changelog +### v2.2.5 (AMO, Chrome) -### v2.2.4 (AMO) +Added some anti-lag measures. This seems to be an issue affecting _only_ Chrome (and only then some installs), where canvas.drawImage() won't work properly for some reason. + +### v2.2.4 Lots of mostly incredibly minor stuff. @@ -12,7 +15,7 @@ Lots of mostly incredibly minor stuff. * Fixed some under-the-hood bugs nobody knew they even existed * A lil bit of refactoring -### v2.2.3 (AMO) +### v2.2.3 * Fixed automatic aspect ratio detection on DRM-protected sites. @@ -20,7 +23,7 @@ Lots of mostly incredibly minor stuff. * Fixes problems with switching from normal to fullscreen player on youtube. If 2.2.1 didn't fix the font issue, this version should have. -### v2.2.1 (Chrome) +### v2.2.1 * Fixes few chrome-specific fixes/bugs that v2.2.0 introduced. Maybe fixed the font problem. diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index 16f4d37..f6bbf95 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -31,6 +31,7 @@ var _arSetup = function(cwidth, cheight){ console.log("%c[ArDetect::_ard_setup] Starting automatic aspect ratio detection", _ard_console_start); this._halted = false; + GlobalVars.arDetect.autoDisable.eventCount = 0; // vstavimo začetne stolpce v _ard_sampleCols. // let's insert initial columns to _ard_sampleCols @@ -1386,7 +1387,15 @@ function _ard_getTimeout(baseTimeout, startTime){ if( execTime > ExtensionConf.arDetect.autoDisable.maxExecutionTime ){ GlobalVars.arDetect.autoDisable.eventCount++; + if(Debug.debug){ + console.log("[ArDetect::_ard_getTimeout] Exec time exceeded maximum allowed execution time. This has now happened" + GlobalVars.arDetect.autoDisable.eventCount + "times in a row."); + } + if(GlobalVars.arDetect.autoDisable.eventCount >= ExtensionConf.arDetect.autoDisable.consecutiveTimeoutCount ){ + if (Debug.debug){ + console.log("[ArDetect::_ard_getTimeout] Maximum execution time was exceeded too many times. Automatic aspect ratio detection has been disabled."); + } + Comms.sendToBackgroundScript({cmd: 'disable-autoar', reason: 'Automatic aspect ratio detection was taking too much time and has been automatically disabled in order to avoid lag.'}); _ard_stop(); return 999999; diff --git a/js/uw-bg.js b/js/uw-bg.js index 5c71d60..356594e 100644 --- a/js/uw-bg.js +++ b/js/uw-bg.js @@ -68,6 +68,7 @@ async function _uwbg_onTabSwitched(activeInfo){ // <===[///]----------------------------[\\\]===> // Check if any frame has a video in it. To enable the popup there only needs to be at least one, // but the popup controls all frames. + var hasVideos = false; for(frame of videoFrameList){ hasVideos |= frame.response.hasVideos; @@ -148,6 +149,7 @@ function _uwbg_rcvmsg(message, sender, sendResponse){ config.mode = ExtensionConf.extensionMode; config.arMode = ExtensionConf.arDetect.mode; + config.arDisabledReason = ExtensionConf.arDetect.disabledReason; config.arTimerPlaying = ExtensionConf.arDetect.timer_playing; if(Debug.debug) diff --git a/res/popup/js/popup.js b/res/popup/js/popup.js index f8239ba..851dba3 100644 --- a/res/popup/js/popup.js +++ b/res/popup/js/popup.js @@ -176,7 +176,7 @@ function loadConfig(config){ } document.getElementById("_checkbox_autoArEnabled").checked = config.arMode == "blacklist"; - + document.getElementById("_autoAr_disabled_reason").textContent = config.arDisabledReason; document.getElementById("_input_autoAr_frequency").value = parseInt(1000/config.arTimerPlaying); // process video alignment: diff --git a/res/popup/popup.html b/res/popup/popup.html index 39ce428..48aa5cf 100644 --- a/res/popup/popup.html +++ b/res/popup/popup.html @@ -112,6 +112,10 @@ .w24 { width: 100px; } + + .color_warn { + color: #d6ba4a; + } .warning { /*background-*/color: #d6ba4a; /* color: #000; */ @@ -217,7 +221,7 @@ if your browser has been opened for a while.

Keeping check frequency low will make the problem go away (mostly), but aspect ratio corrections will be delayed a bit.

--> -

Enable automatic aspect ratio detection?

+

Enable automatic aspect ratio detection?

Checks per second: Save

NOTE: increasing the frequency can result in very high RAM usage and slow performance.