mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-30 19:32:26 +01:00
Fix some startup bottlenecks.
This commit is contained in:
@@ -60,6 +60,33 @@ var ConfigBase = Class("ConfigBase", {
|
||||
"resource://dactyl-content/")));
|
||||
});
|
||||
|
||||
if (this.VCSPath) {
|
||||
this.branch = new Promise(resolve => {
|
||||
this.timeout(() => {
|
||||
io.system(["hg", "-R", this.VCSPath, "branch"], "", true)
|
||||
.then(result => {
|
||||
resolve(result.output);
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
this._version = new Promise(resolve => {
|
||||
this.timeout(() => {
|
||||
io.system(["hg", "-R", this.VCSPath, "log", "-r.",
|
||||
"--template=hg{rev}-{branch}"], "", true)
|
||||
.then(result => {
|
||||
this.version = result.output;
|
||||
resolve(this.version);
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
this.branch = Promise.resolve((/pre-hg\d+-(\S*)/.exec(this.version) || [])[1]);
|
||||
this._version = null;
|
||||
}
|
||||
|
||||
this.protocolLoaded = true;
|
||||
this.timeout(function () {
|
||||
cache.register("config.dtd", () => util.makeDTD(config.dtd),
|
||||
@@ -208,8 +235,19 @@ var ConfigBase = Class("ConfigBase", {
|
||||
get addonID() { return this.name + "@dactyl.googlecode.com"; },
|
||||
|
||||
addon: Class.Memoize(function () {
|
||||
return (JSMLoader.bootstrap || {}).addon ||
|
||||
AddonManager.getAddonByID(this.addonID);
|
||||
return (JSMLoader.bootstrap || {}).addon;
|
||||
}),
|
||||
|
||||
addonData: Class.Memoize(function () {
|
||||
return (JSMLoader.bootstrap || {}).addonData;
|
||||
}),
|
||||
|
||||
basePath: Class.Memoize(function () {
|
||||
return (JSMLoader.bootstrap || {}).basePath;
|
||||
}),
|
||||
|
||||
resourceURI: Class.Memoize(function () {
|
||||
return this.addonData.resourceURI;
|
||||
}),
|
||||
|
||||
get styleableChrome() { return Object.keys(this.overlays); },
|
||||
@@ -379,8 +417,10 @@ var ConfigBase = Class("ConfigBase", {
|
||||
* proxy file.
|
||||
*/
|
||||
VCSPath: Class.Memoize(function () {
|
||||
if (/pre$/.test(this.addon.version)) {
|
||||
let uri = util.newURI(this.addon.getResourceURI("").spec + "../.hg");
|
||||
if (/pre$/.test(this.addonData.version)) {
|
||||
// XXX: Sync.
|
||||
let uri = util.newURI("../.hg", null, this.resourceURI);
|
||||
|
||||
if (uri instanceof Ci.nsIFileURL &&
|
||||
uri.file.exists() &&
|
||||
io.pathSearch("hg"))
|
||||
@@ -389,17 +429,6 @@ var ConfigBase = Class("ConfigBase", {
|
||||
return null;
|
||||
}),
|
||||
|
||||
/**
|
||||
* @property {string} The name of the VCS branch that the application is
|
||||
* running from if using an extension proxy file or was built from if
|
||||
* installed as an XPI.
|
||||
*/
|
||||
branch: Class.Memoize(function () {
|
||||
if (this.VCSPath)
|
||||
return io.system(["hg", "-R", this.VCSPath, "branch"]).output;
|
||||
return (/pre-hg\d+-(\S*)/.exec(this.version) || [])[1];
|
||||
}),
|
||||
|
||||
/** @property {string} The name of the current user profile. */
|
||||
profileName: Class.Memoize(function () {
|
||||
// NOTE: services.profile.selectedProfile.name doesn't return
|
||||
@@ -417,10 +446,6 @@ var ConfigBase = Class("ConfigBase", {
|
||||
|
||||
/** @property {string} The Dactyl version string. */
|
||||
version: Class.Memoize(function () {
|
||||
if (this.VCSPath)
|
||||
return io.system(["hg", "-R", this.VCSPath, "log", "-r.",
|
||||
"--template=hg{rev}-{branch}"]).output;
|
||||
|
||||
return this.addon.version;
|
||||
}),
|
||||
|
||||
@@ -659,10 +684,13 @@ config.INIT = update(Object.create(config.INIT), config.INIT, {
|
||||
load: function load(dactyl, modules, window) {
|
||||
load.superapply(this, arguments);
|
||||
|
||||
this.timeout(function () {
|
||||
if (this.branch && this.branch !== "default" &&
|
||||
modules.yes_i_know_i_should_not_report_errors_in_these_branches_thanks.indexOf(this.branch) === -1)
|
||||
dactyl.warn(_("warn.notDefaultBranch", config.appName, this.branch));
|
||||
this.timeout(() => {
|
||||
let list = modules.yes_i_know_i_should_not_report_errors_in_these_branches_thanks;
|
||||
|
||||
this.branch.then(branch => {
|
||||
if (branch && branch !== "default" && !list.includes(branch))
|
||||
dactyl.warn(_("warn.notDefaultBranch", config.appName, branch));
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -219,6 +219,20 @@ var IO = Module("io", {
|
||||
};
|
||||
},
|
||||
|
||||
shell: Class.Memoize(() => {
|
||||
if (config.OS.isWindows)
|
||||
return "cmd.exe";
|
||||
else
|
||||
return services.environment.get("SHELL") || "sh";
|
||||
}),
|
||||
|
||||
shellcmdflag: Class.Memoize(() => {
|
||||
if (config.OS.isWindows)
|
||||
return "/c";
|
||||
else
|
||||
return "-c";
|
||||
}),
|
||||
|
||||
charsets: Class.Memoize(function () {
|
||||
const BASE = "@mozilla.org/intl/unicode/decoder;1?charset=";
|
||||
return Object.keys(Cc).filter(k.startsWith(BASE))
|
||||
@@ -513,12 +527,14 @@ var IO = Module("io", {
|
||||
* command string or an array of strings (a command and arguments)
|
||||
* which will be escaped and concatenated.
|
||||
* @param {string} input Any input to be provided to the command on stdin.
|
||||
* @param {function(object)} callback A callback to be called when
|
||||
* the command completes. @optional
|
||||
* @param {function(object) | boolean} async A callback to be called when
|
||||
* the command completes, or a boolean indicating that a
|
||||
* promise should be returned. @optional
|
||||
* @returns {object|null}
|
||||
*/
|
||||
system: function system(command, input, callback) {
|
||||
util.dactyl.echomsg(_("io.callingShell", command), 4);
|
||||
system: function system(command, input = "", async = false) {
|
||||
if (loaded.overlay)
|
||||
util.dactyl.echomsg(_("io.callingShell", command), 4);
|
||||
|
||||
let { shellEscape } = util.bound;
|
||||
|
||||
@@ -545,16 +561,28 @@ var IO = Module("io", {
|
||||
});
|
||||
}
|
||||
|
||||
function async(status) {
|
||||
let output = stdout.read();
|
||||
for (let f of [stdin, stdout, cmd])
|
||||
if (f.exists())
|
||||
f.remove(false);
|
||||
callback(result(status, output));
|
||||
let deferred;
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
deferred = { resolve, reject };
|
||||
});
|
||||
if (callable(async))
|
||||
promise.then(async);
|
||||
|
||||
function handleResult(status) {
|
||||
stdout.async.read().then(output => {
|
||||
deferred.resolve(result(status, output));
|
||||
});
|
||||
}
|
||||
|
||||
let shell = io.pathSearch(storage["options"].get("shell").value);
|
||||
let shcf = storage["options"].get("shellcmdflag").value;
|
||||
if (!storage["options"])
|
||||
var { shell, shellcmdflag } = this;
|
||||
else {
|
||||
shell = storage["options"].get("shell").value;
|
||||
shellcmdflag = storage["options"].get("shellcmdflag").value;
|
||||
}
|
||||
|
||||
shell = io.pathSearch(shell);
|
||||
|
||||
util.assert(shell, _("error.invalid", "'shell'"));
|
||||
|
||||
if (isArray(command))
|
||||
@@ -563,16 +591,18 @@ var IO = Module("io", {
|
||||
// TODO: implement 'shellredir'
|
||||
if (config.OS.isWindows && !/sh/.test(shell.leafName)) {
|
||||
command = "cd /D " + this.cwd.path + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path;
|
||||
var res = this.run(shell, shcf.split(/\s+/).concat(command), callback ? async : true);
|
||||
var res = this.run(shell, shellcmdflag.split(/\s+/).concat(command), async ? handleResult : true);
|
||||
}
|
||||
else {
|
||||
cmd.write("cd " + shellEscape(this.cwd.path) + "\n" +
|
||||
["exec", ">" + shellEscape(stdout.path), "2>&1", "<" + shellEscape(stdin.path),
|
||||
shellEscape(shell.path), shcf, shellEscape(command)].join(" "));
|
||||
res = this.run("/bin/sh", ["-e", cmd.path], callback ? async : true);
|
||||
shellEscape(shell.path), shellcmdflag, shellEscape(command)].join(" "));
|
||||
res = this.run("/bin/sh", ["-e", cmd.path], async ? handleResult : true);
|
||||
}
|
||||
|
||||
return callback ? true : result(res, stdout.read());
|
||||
if (async)
|
||||
return promise;
|
||||
return result(res, stdout.read());
|
||||
}, this, true);
|
||||
},
|
||||
|
||||
@@ -591,6 +621,11 @@ var IO = Module("io", {
|
||||
let args = Array.from(util.range(0, func.length),
|
||||
() => this.createTempFile(ext, label));
|
||||
|
||||
function cleanup() {
|
||||
// XXX: Sync.
|
||||
args.forEach(f => { f.remove(false); });
|
||||
}
|
||||
|
||||
try {
|
||||
if (!args.every(identity))
|
||||
return false;
|
||||
@@ -598,8 +633,10 @@ var IO = Module("io", {
|
||||
var res = func.apply(self || this, args);
|
||||
}
|
||||
finally {
|
||||
if (!checked || res !== true)
|
||||
args.forEach(f => { f.remove(false); });
|
||||
if (res && typeof res === "object" && "then" in res && callable(res.then))
|
||||
res.then(cleanup, cleanup);
|
||||
else if (!checked || res !== true)
|
||||
cleanup();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -1180,15 +1217,7 @@ unlet s:cpo_save
|
||||
options: function initOptions(dactyl, modules, window) {
|
||||
const { completion, options } = modules;
|
||||
|
||||
var shell, shellcmdflag;
|
||||
if (config.OS.isWindows) {
|
||||
shell = "cmd.exe";
|
||||
shellcmdflag = "/c";
|
||||
}
|
||||
else {
|
||||
shell = services.environment.get("SHELL") || "sh";
|
||||
shellcmdflag = "-c";
|
||||
}
|
||||
let { shell, shellcmdflag } = io;
|
||||
|
||||
options.add(["banghist", "bh"],
|
||||
"Replace occurrences of ! with the previous command when executing external commands",
|
||||
|
||||
@@ -920,9 +920,9 @@ var AsyncFile = Class("AsyncFile", File, {
|
||||
}),
|
||||
|
||||
_setEncoding: function _setEncoding(options) {
|
||||
if (this.encoding != null && !("encoding" in options))
|
||||
if (this.charset != null && !("encoding" in options))
|
||||
options = update({}, options,
|
||||
{ encoding: this.encoding });
|
||||
{ encoding: this.charset });
|
||||
|
||||
return options;
|
||||
},
|
||||
|
||||
@@ -122,15 +122,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
global = Class.objectGlobal(obj);
|
||||
|
||||
return (global && global.dactyl ||
|
||||
overlay.activeWindow && overlay.activeWindow.dactyl ||
|
||||
loaded.overlay && overlay.activeWindow && overlay.activeWindow.dactyl ||
|
||||
anythingObjectHack);
|
||||
}, {
|
||||
get(target, prop) {
|
||||
if (prop in target)
|
||||
return target[prop];
|
||||
|
||||
if (loaded.overlay)
|
||||
return target()[prop];
|
||||
return target()[prop];
|
||||
},
|
||||
}),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user