-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-for-updates.mozcmd
75 lines (64 loc) · 2.34 KB
/
check-for-updates.mozcmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Contributor(s):
* - LouCypher (original code)
*/
[
{
name: "chkupd",
description: "Check " + Application.name + " for updates.",
params: [
{
name: "option",
type: "string",
defaultValue: null,
description: "notes: open release notes; changeset: open changeset;\
history: show update history; no parameter: check for updates"
}
],
returnType: "string",
exec: function(args, context) {
function openURL(aURL) {
let chromeWin = context.environment.chromeWindow ||
context.environment.chromeDocument.defaultView;
chromeWin.switchToTabHavingURI(aURL, true);
}
let um = Cc['@mozilla.org/updates/update-manager;1'].getService(Ci.nsIUpdateManager);
let option = args.option.toLowerCase();
if (option === "notes" || option === "n") {
let relNotesURL;
if (um.getUpdateAt(0))
relNotesURL = um.getUpdateAt(0).detailsURL;
if (!relNotesURL)
return "No release notes.";
if (/mozilla.com/.test(relNotesURL))
relNotesURL = relNotesURL.replace(/mozilla.com/, "mozilla.org");
openURL(relNotesURL);
}
else if (option === "changeset" || option === "c") {
let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
req.open("GET", "about:buildconfig", false);
req.send(null);
let changeset = req.responseText.match(/http:\/\/hg.mozilla.org\/[^\"]*/);
if (!changeset)
return "No changeset on this release.";
openURL(changeset);
}
else if (option === "history" || option === "h") {
if (!um.getUpdateAt(0))
return "No updates installed yet.";
openURL("chrome://mozapps/content/update/history.xul");
}
else {
let prompter = Cc['@mozilla.org/updates/update-prompt;1'].createInstance(Ci.nsIUpdatePrompt);
if (um.activeUpdate && um.activeUpdate.state === "pending")
prompter.showUpdateDownloaded(um.activeUpdate);
else
prompter.checkForUpdates();
}
}
}
]