added auto-disable if autodetection takes too long

This commit is contained in:
Tamius Han 2018-05-04 00:27:40 +02:00
parent b5a5609898
commit 081f8e968f
5 changed files with 28 additions and 2 deletions

View File

@ -11,6 +11,7 @@ var ExtensionConf = {
// 'blacklist' - work by default, problem sites need to be blocked
// 'whitelist' - only work if site has been specifically approved
// 'disabled' - don't work at all
disabledReason: "", // if automatic aspect ratio has been disabled, show reason
allowedMisaligned: 0.05, // top and bottom letterbox thickness can differ by this much.
// Any more and we don't adjust ar.
allowedArVariance: 0.075, // amount by which old ar can differ from the new (1 = 100%)
@ -18,6 +19,11 @@ var ExtensionConf = {
timer_paused: 3000,
timer_error: 3000,
timer_minimumTimeout: 5, // but regardless of above, we wait this many msec before retriggering
autoDisable: { // settings for automatically disabling the extension
maxExecutionTime: 15, // if execution time of main autodetect loop exceeds this many milliseconds,
// we disable it.
consecutiveTimeoutCount: 5 // we only do it if it happens this many consecutive times
},
hSamples: 640,
vSamples: 360,
samplingInterval: 10, // we sample at columns at (width/this) * [ 1 .. this - 1]

View File

@ -1381,8 +1381,20 @@ var _ard_isRunning = function(){
}
function _ard_getTimeout(baseTimeout, startTime){
// baseTimeout -= (performance.now() - startTime);
var execTime = (performance.now() - startTime);
if( execTime > ExtensionConf.arDetect.autoDisable.maxExecutionTime ){
GlobalVars.arDetect.autoDisable.eventCount++;
if(GlobalVars.arDetect.autoDisable.eventCount >= ExtensionConf.arDetect.autoDisable.consecutiveTimeoutCount ){
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;
}
} else {
GlobalVars.arDetect.autoDisable.eventCount = 0;
}
// return baseTimeout > ExtensionConf.arDetect.minimumTimeout ? baseTimeout : ExtensionConf.arDetect.minimumTimeout;
return baseTimeout;

View File

@ -22,6 +22,9 @@ var GlobalVars = {
left: null
},
arDetect: {
autoDisable: {
eventCount: 0
},
canvas: null,
blackLevel: 10,
sampleCols_current: 0,

View File

@ -212,6 +212,11 @@ function _uwbg_rcvmsg(message, sender, sendResponse){
}
else if(message.cmd == "disable-autoar"){
ExtensionConf.arDetect.mode = "disabled";
if(message.reason){
ExtensionConf.arDetect.disabledReason = message.reason;
} else {
ExtensionConf.arDetect.disabledReason = '';
}
Settings.save(ExtensionConf);
// Comms.sendToAll({cmd: "reload-settings", sender: "uwbg"});
if(Debug.debug){

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ultrawidify",
"version": "2.2.4",
"version": "2.2.5",
"icons": {
"32":"res/icons/uw-32.png",