]> git.donarmstrong.com Git - dactyl.git/blob - common/components/commandline-handler.js
Import 1.0 supporting Firefox up to 14.*
[dactyl.git] / common / components / commandline-handler.js
1 // Copyright (c) 2009 by Doug Kearns
2 //
3 // This work is licensed for reuse under an MIT license. Details are
4 // given in the LICENSE.txt file included with this file.
5 "use strict";
6
7 function reportError(e) {
8     dump("dactyl: command-line-handler: " + e + "\n" + (e.stack || Error().stack));
9     Cu.reportError(e);
10 }
11
12 var global = this;
13 var NAME = "command-line-handler";
14 var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
15
16 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
17
18 function init() {
19     Cu.import("resource://dactyl/bootstrap.jsm");
20     if (!JSMLoader.initialized)
21         JSMLoader.init();
22     JSMLoader.load("base.jsm", global);
23     require(global, "config");
24     require(global, "util");
25 }
26
27 function CommandLineHandler() {
28     this.wrappedJSObject = this;
29 }
30 CommandLineHandler.prototype = {
31
32     classDescription: "Dactyl command line Handler",
33
34     classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"),
35
36     contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl",
37
38     _xpcom_categories: [
39         {
40             category: "command-line-handler",
41             entry: "m-dactyl"
42         },
43
44         // FIXME: Belongs elsewhere
45          {
46             category: "profile-after-change",
47             entry: "m-dactyl"
48         }
49     ],
50
51     observe: function observe(subject, topic, data) {
52         if (topic === "profile-after-change") {
53             init();
54             require(global, "main");
55         }
56     },
57
58     QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsICommandLineHandler]),
59
60     handle: function (commandLine) {
61         init();
62         try {
63             var remote = commandLine.handleFlagWithParam(config.name + "-remote", false);
64         }
65         catch (e) {
66             util.dump("option '-" + config.name + "-remote' requires an argument\n");
67         }
68
69         try {
70             if (remote) {
71                 commandLine.preventDefault = true;
72                 require(global, "services");
73                 util.dactyl.execute(remote);
74             }
75         }
76         catch (e) {
77             util.reportError(e);
78         }
79
80         try {
81             this.optionValue = commandLine.handleFlagWithParam(config.name, false);
82         }
83         catch (e) {
84             util.dump("option '-" + config.name + "' requires an argument\n");
85         }
86     },
87
88     get helpInfo() "  -" + config.name + " <opts>" + "             Additional options for " + config.appName + " startup\n".substr(config.name.length)
89 };
90
91 if (XPCOMUtils.generateNSGetFactory)
92     var NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]);
93 else
94     var NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]);
95 var EXPORTED_SYMBOLS = ["NSGetFactory", "global"];
96
97 // vim: set fdm=marker sw=4 ts=4 et: