1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-24 00:02:27 +01:00

Allow :time to be interrupted

This commit is contained in:
Kris Maglione
2008-10-12 18:58:32 +00:00
parent afcd5cbaeb
commit 0f92110012
3 changed files with 30 additions and 20 deletions

View File

@@ -188,8 +188,8 @@ liberator.IO = function () //{{{
function () { liberator.echo(liberator.io.getCurrentDirectory()); }, function () { liberator.echo(liberator.io.getCurrentDirectory()); },
{ argCount: "0" }); { argCount: "0" });
// mkv[imperatorrc] or mkm[uttatorrc] // "mkv[imperatorrc]" or "mkm[uttatorrc]"
liberator.commands.add(["mk" + EXTENSION_NAME.substr(0, 1) + "[" + EXTENSION_NAME.substr(1) + "rc]"], liberator.commands.add([EXTENSION_NAME.replace(/(.)(.*)/, "mk$1[$2rc]")],
"Write current key mappings and changed options to the config file", "Write current key mappings and changed options to the config file",
function (args, special) function (args, special)
{ {

View File

@@ -392,50 +392,43 @@ const liberator = (function () //{{{
function (args, special, count) function (args, special, count)
{ {
args = args.string; args = args.string;
let method = args[0] == ":" ? "execute" : "eval";
try try
{ {
if (count > 1) if (count > 1)
{ {
var i = count; let total = 0;
var beforeTime = Date.now(); var beforeTime = Date.now();
liberator.interrupted = false; for (let i in liberator.util.rangeInterruptable(0, count, 500))
if (args && args[0] == ":")
{ {
while (i-- && !liberator.interrupted) let now = Date.now();
liberator.execute(args); liberator[method](args);
} total += Date.now() - now;
else
{
while (i--)
liberator.eval(args);
} }
if (special) if (special)
return; return;
var afterTime = Date.now(); if (total / count >= 100)
if ((afterTime - beforeTime) / count >= 100)
{ {
var each = ((afterTime - beforeTime) / 1000.0 / count); var each = (total / 1000.0) / count;
var eachUnits = "sec"; var eachUnits = "sec";
} }
else else
{ {
var each = ((afterTime - beforeTime) / count); var each = total / count;
var eachUnits = "msec"; var eachUnits = "msec";
} }
if (afterTime - beforeTime >= 100) if (total >= 100)
{ {
var total = ((afterTime - beforeTime) / 1000.0); var total = total / 1000.0;
var totalUnits = "sec"; var totalUnits = "sec";
} }
else else
{ {
var total = (afterTime - beforeTime);
var totalUnits = "msec"; var totalUnits = "msec";
} }

View File

@@ -295,6 +295,23 @@ liberator.util = { //{{{
yield start++; yield start++;
}, },
rangeInterruptable: function (start, end, time)
{
let endTime = Date.now() + time;
while (start < end)
{
if (Date.now() > endTime)
{
liberator.interrupted = false;
liberator.threadYield();
if (liberator.interrupted)
throw new Error("Interrupted");
endTime = Date.now() + time;
}
yield start++;
}
},
// same as Firefox's readFromClipboard function, but needed for apps like Thunderbird // same as Firefox's readFromClipboard function, but needed for apps like Thunderbird
readFromClipboard: function () readFromClipboard: function ()
{ {