X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fcomponents%2Fcommandline-handler.js;fp=common%2Fcomponents%2Fcommandline-handler.js;h=0fd118958e77d4b873c26ed3e8da0b65f6152f9e;hb=9044153cb63835e39b9de8ec4ade237c03e3888a;hp=918d7bf300b8980c2d0d50e676f7c29224467b89;hpb=70740024f9c028c1fd63e1a1850ab062ff956054;p=dactyl.git diff --git a/common/components/commandline-handler.js b/common/components/commandline-handler.js index 918d7bf..0fd1189 100644 --- a/common/components/commandline-handler.js +++ b/common/components/commandline-handler.js @@ -11,37 +11,72 @@ function reportError(e) { var global = this; var NAME = "command-line-handler"; -var Cc = Components.classes; -var Ci = Components.interfaces; -var Cu = Components.utils; +var { classes: Cc, interfaces: Ci, utils: Cu } = Components; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +function init() { + Cu.import("resource://dactyl/bootstrap.jsm"); + if (!JSMLoader.initialized) + JSMLoader.init(); + JSMLoader.load("base.jsm", global); + require(global, "config"); + require(global, "util"); +} + function CommandLineHandler() { this.wrappedJSObject = this; - - Cu.import("resource://dactyl/base.jsm"); - require(global, "util"); - require(global, "config"); } CommandLineHandler.prototype = { - classDescription: "Dactyl Command-line Handler", + classDescription: "Dactyl command line Handler", classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"), contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl", - _xpcom_categories: [{ - category: "command-line-handler", - entry: "m-dactyl" - }], + _xpcom_categories: [ + { + category: "command-line-handler", + entry: "m-dactyl" + }, - QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]), + // FIXME: Belongs elsewhere + { + category: "profile-after-change", + entry: "m-dactyl" + } + ], + + observe: function observe(subject, topic, data) { + if (topic === "profile-after-change") { + init(); + require(global, "main"); + } + }, + + QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsICommandLineHandler]), handle: function (commandLine) { + init(); + try { + var remote = commandLine.handleFlagWithParam(config.name + "-remote", false); + } + catch (e) { + util.dump("option '-" + config.name + "-remote' requires an argument\n"); + } + + try { + if (remote) { + commandLine.preventDefault = true; + require(global, "services"); + util.dactyl.execute(remote); + } + } + catch(e) { + util.reportError(e) + }; - // TODO: handle remote launches differently? try { this.optionValue = commandLine.handleFlagWithParam(config.name, false); }