Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 /** | 7 /** |
8 * @module main | 8 * @module main |
saroyanm
2015/05/04 18:13:43
I think this should be file overview, maybe smth l
Wladimir Palant
2015/05/07 00:04:59
As Sebastian noted elsewhere, @module is actually
| |
9 */ | 9 */ |
10 | 10 |
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 11 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
12 Cu.import("resource://gre/modules/Services.jsm"); | 12 Cu.import("resource://gre/modules/Services.jsm"); |
13 Cu.import("resource://gre/modules/Promise.jsm"); | 13 Cu.import("resource://gre/modules/Promise.jsm"); |
14 | 14 |
15 require("commandLine"); | 15 require("commandLine"); |
16 let {run} = require("crawler"); | 16 let {run} = require("crawler"); |
17 let {reportException} = require("debug"); | |
17 | 18 |
18 let baseURL = null; | 19 let baseURL = null; |
19 | 20 |
20 /** | 21 /** |
21 * Waits for the application to initialize. | 22 * Waits for the application to initialize. |
22 * @type {Promise} | 23 * @type {Promise} |
23 */ | 24 */ |
24 let applicationReady = (function() | 25 let applicationReady = (function() |
25 { | 26 { |
26 let deferred = Promise.defer(); | 27 return new Promise((resolve, reject) => |
saroyanm
2015/05/04 18:13:43
As mentioned in crawler.js please also don't use D
Wladimir Palant
2015/05/07 00:04:59
Done.
| |
28 { | |
29 let observer = { | |
30 observe: function(subject, topic, data) | |
31 { | |
32 Services.obs.removeObserver(this, "sessionstore-windows-restored"); | |
33 resolve(); | |
34 }, | |
35 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakR eference]) | |
36 }; | |
27 | 37 |
28 let observer = { | 38 Services.obs.addObserver(observer, "sessionstore-windows-restored", true); |
29 observe: function(subject, topic, data) | 39 onShutdown.add(() => Services.obs.removeObserver(observer, "sessionstore-win dows-restored")); |
30 { | 40 }); |
31 Services.obs.removeObserver(this, "sessionstore-windows-restored"); | |
32 deferred.resolve(); | |
33 }, | |
34 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRef erence]) | |
35 }; | |
36 | |
37 Services.obs.addObserver(observer, "sessionstore-windows-restored", true); | |
38 onShutdown.add(() => Services.obs.removeObserver(observer, "sessionstore-windo ws-restored")); | |
39 | |
40 return deferred.promise; | |
41 })(); | 41 })(); |
42 | 42 |
43 /** | 43 /** |
44 * Startup function, called from command line handler. | 44 * Startup function, called from command line handler. |
45 * | 45 * |
46 * @param {int} port Port to communicate with | 46 * @param {int} port Port to communicate with |
47 */ | 47 */ |
48 function startup(port) | 48 function startup(port) |
49 { | 49 { |
50 baseURL = "http://localhost:" + port + "/"; | 50 baseURL = "http://localhost:" + port + "/"; |
(...skipping 16 matching lines...) Expand all Loading... | |
67 { | 67 { |
68 let {urls, timeout, maxtabs} = event.target.response; | 68 let {urls, timeout, maxtabs} = event.target.response; |
69 | 69 |
70 applicationReady.then(function() | 70 applicationReady.then(function() |
71 { | 71 { |
72 let window = Services.wm.getMostRecentWindow("navigator:browser"); | 72 let window = Services.wm.getMostRecentWindow("navigator:browser"); |
73 run(window, urls, timeout, maxtabs, baseURL + "save", function() | 73 run(window, urls, timeout, maxtabs, baseURL + "save", function() |
74 { | 74 { |
75 Services.startup.quit(Services.startup.eAttemptQuit); | 75 Services.startup.quit(Services.startup.eAttemptQuit); |
76 }); | 76 }); |
77 }, function(exception) | 77 }, reportException); |
78 { | |
79 Cu.reportError(exception); | |
80 dump(exception + "\n") | |
81 }); | |
82 } | 78 } |
83 | 79 |
84 /** | 80 /** |
85 * Called if requesting parameters failed. | 81 * Called if requesting parameters failed. |
86 * | 82 * |
87 * @param {Event} event | 83 * @param {Event} event |
88 */ | 84 */ |
89 function onParametersFailed(event) | 85 function onParametersFailed(event) |
90 { | 86 { |
91 Cu.reportError("Failed loading parameters"); | 87 reportException(new Error("Failed loading parameters")); |
saroyanm
2015/05/04 18:13:43
Maybe also make sense to print the message in the
Wladimir Palant
2015/05/07 00:04:59
Done.
| |
92 } | 88 } |
LEFT | RIGHT |