mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 19:42:26 +01:00
Allow :time to be interrupted
This commit is contained in:
@@ -188,8 +188,8 @@ liberator.IO = function () //{{{
|
||||
function () { liberator.echo(liberator.io.getCurrentDirectory()); },
|
||||
{ argCount: "0" });
|
||||
|
||||
// mkv[imperatorrc] or mkm[uttatorrc]
|
||||
liberator.commands.add(["mk" + EXTENSION_NAME.substr(0, 1) + "[" + EXTENSION_NAME.substr(1) + "rc]"],
|
||||
// "mkv[imperatorrc]" or "mkm[uttatorrc]"
|
||||
liberator.commands.add([EXTENSION_NAME.replace(/(.)(.*)/, "mk$1[$2rc]")],
|
||||
"Write current key mappings and changed options to the config file",
|
||||
function (args, special)
|
||||
{
|
||||
|
||||
@@ -392,50 +392,43 @@ const liberator = (function () //{{{
|
||||
function (args, special, count)
|
||||
{
|
||||
args = args.string;
|
||||
let method = args[0] == ":" ? "execute" : "eval";
|
||||
|
||||
try
|
||||
{
|
||||
if (count > 1)
|
||||
{
|
||||
var i = count;
|
||||
let total = 0;
|
||||
var beforeTime = Date.now();
|
||||
|
||||
liberator.interrupted = false;
|
||||
if (args && args[0] == ":")
|
||||
for (let i in liberator.util.rangeInterruptable(0, count, 500))
|
||||
{
|
||||
while (i-- && !liberator.interrupted)
|
||||
liberator.execute(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (i--)
|
||||
liberator.eval(args);
|
||||
let now = Date.now();
|
||||
liberator[method](args);
|
||||
total += Date.now() - now;
|
||||
}
|
||||
|
||||
if (special)
|
||||
return;
|
||||
|
||||
var afterTime = Date.now();
|
||||
|
||||
if ((afterTime - beforeTime) / count >= 100)
|
||||
if (total / count >= 100)
|
||||
{
|
||||
var each = ((afterTime - beforeTime) / 1000.0 / count);
|
||||
var each = (total / 1000.0) / count;
|
||||
var eachUnits = "sec";
|
||||
}
|
||||
else
|
||||
{
|
||||
var each = ((afterTime - beforeTime) / count);
|
||||
var each = total / count;
|
||||
var eachUnits = "msec";
|
||||
}
|
||||
|
||||
if (afterTime - beforeTime >= 100)
|
||||
if (total >= 100)
|
||||
{
|
||||
var total = ((afterTime - beforeTime) / 1000.0);
|
||||
var total = total / 1000.0;
|
||||
var totalUnits = "sec";
|
||||
}
|
||||
else
|
||||
{
|
||||
var total = (afterTime - beforeTime);
|
||||
var totalUnits = "msec";
|
||||
}
|
||||
|
||||
|
||||
@@ -295,6 +295,23 @@ liberator.util = { //{{{
|
||||
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
|
||||
readFromClipboard: function ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user