|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const { Cc, Ci, Cu } = require("chrome"); |
|
8 const gcli = require("gcli/index"); |
|
9 const Services = require("Services"); |
|
10 |
|
11 const BRAND_SHORT_NAME = Cc["@mozilla.org/intl/stringbundle;1"] |
|
12 .getService(Ci.nsIStringBundleService) |
|
13 .createBundle("chrome://branding/locale/brand.properties") |
|
14 .GetStringFromName("brandShortName"); |
|
15 |
|
16 /** |
|
17 * Restart command |
|
18 * |
|
19 * @param boolean nocache |
|
20 * Disables loading content from cache upon restart. |
|
21 * |
|
22 * Examples : |
|
23 * >> restart |
|
24 * - restarts browser immediately |
|
25 * >> restart --nocache |
|
26 * - restarts immediately and starts Firefox without using cache |
|
27 */ |
|
28 exports.items = [ |
|
29 { |
|
30 name: "restart", |
|
31 description: gcli.lookupFormat("restartBrowserDesc", [ BRAND_SHORT_NAME ]), |
|
32 params: [ |
|
33 { |
|
34 name: "nocache", |
|
35 type: "boolean", |
|
36 description: gcli.lookup("restartBrowserNocacheDesc") |
|
37 } |
|
38 ], |
|
39 returnType: "string", |
|
40 exec: function Restart(args, context) { |
|
41 let canceled = Cc["@mozilla.org/supports-PRBool;1"] |
|
42 .createInstance(Ci.nsISupportsPRBool); |
|
43 Services.obs.notifyObservers(canceled, "quit-application-requested", "restart"); |
|
44 if (canceled.data) { |
|
45 return gcli.lookup("restartBrowserRequestCancelled"); |
|
46 } |
|
47 |
|
48 // disable loading content from cache. |
|
49 if (args.nocache) { |
|
50 Services.appinfo.invalidateCachesOnRestart(); |
|
51 } |
|
52 |
|
53 // restart |
|
54 Cc["@mozilla.org/toolkit/app-startup;1"] |
|
55 .getService(Ci.nsIAppStartup) |
|
56 .quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart); |
|
57 return gcli.lookupFormat("restartBrowserRestarting", [ BRAND_SHORT_NAME ]); |
|
58 } |
|
59 } |
|
60 ]; |