diff --git a/js/conf/ExtensionConf.js b/js/conf/ExtensionConf.js index a59e878..4b67f3a 100644 --- a/js/conf/ExtensionConf.js +++ b/js/conf/ExtensionConf.js @@ -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] diff --git a/js/modules/ArDetect.js b/js/modules/ArDetect.js index 2e14aa2..16f4d37 100644 --- a/js/modules/ArDetect.js +++ b/js/modules/ArDetect.js @@ -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; diff --git a/js/run/GlobalVars.js b/js/run/GlobalVars.js index 432f5e3..5db8e17 100644 --- a/js/run/GlobalVars.js +++ b/js/run/GlobalVars.js @@ -22,6 +22,9 @@ var GlobalVars = { left: null }, arDetect: { + autoDisable: { + eventCount: 0 + }, canvas: null, blackLevel: 10, sampleCols_current: 0, diff --git a/js/uw-bg.js b/js/uw-bg.js index afad743..5c71d60 100644 --- a/js/uw-bg.js +++ b/js/uw-bg.js @@ -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){ diff --git a/manifest.json b/manifest.json index df18bd4..7981a7d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Ultrawidify", - "version": "2.2.4", + "version": "2.2.5", "icons": { "32":"res/icons/uw-32.png",