Add "check for updates" to main menu and AppMenu v2

Tag #963.
This commit is contained in:
wolfbeast 2019-02-12 16:13:57 +01:00 • committed by Roy Tam
commit 114e3529bc
5 changed files with 145 additions and 2 deletions

View file

@ -541,6 +541,117 @@ function isBidiEnabled() {
return rv;
}
#ifdef MOZ_UPDATER
/**
* Opens the update manager and checks for updates to the application.
*/
function checkForUpdates()
{
var um =
Components.classes["@mozilla.org/updates/update-manager;1"].
getService(Components.interfaces.nsIUpdateManager);
var prompter =
Components.classes["@mozilla.org/updates/update-prompt;1"].
createInstance(Components.interfaces.nsIUpdatePrompt);
// If there's an update ready to be applied, show the "Update Downloaded"
// UI instead and let the user know they have to restart the application for
// the changes to be applied.
if (um.activeUpdate && um.activeUpdate.state == "pending")
prompter.showUpdateDownloaded(um.activeUpdate);
else
prompter.checkForUpdates();
}
#endif
/**
* Set up the help menu software update items to show proper status,
* also disabling the items if update is disabled.
*/
function buildHelpMenu()
{
#ifdef MOZ_UPDATER
var updates =
Components.classes["@mozilla.org/updates/update-service;1"].
getService(Components.interfaces.nsIApplicationUpdateService);
var um =
Components.classes["@mozilla.org/updates/update-manager;1"].
getService(Components.interfaces.nsIUpdateManager);
// Disable the UI if the update enabled pref has been locked by the
// administrator or if we cannot update for some other reason.
var checkForUpdates = document.getElementById("checkForUpdates");
var appMenuCheckForUpdates = document.getElementById("appmenu_checkForUpdates");
var canCheckForUpdates = updates.canCheckForUpdates;
checkForUpdates.setAttribute("disabled", !canCheckForUpdates);
appMenuCheckForUpdates.setAttribute("disabled", !canCheckForUpdates);
if (!canCheckForUpdates)
return;
var strings = document.getElementById("bundle_browser");
var activeUpdate = um.activeUpdate;
// If there's an active update, substitute its name into the label
// we show for this item, otherwise display a generic label.
function getStringWithUpdateName(key) {
if (activeUpdate && activeUpdate.name)
return strings.getFormattedString(key, [activeUpdate.name]);
return strings.getString(key + "Fallback");
}
// By default, show "Check for Updates..." from updatesItem_default or
// updatesItem_defaultFallback
var key = "default";
if (activeUpdate) {
switch (activeUpdate.state) {
case "downloading":
// If we're downloading an update at present, show the text:
// "Downloading Thunderbird x.x..." from updatesItem_downloading or
// updatesItem_downloadingFallback, otherwise we're paused, and show
// "Resume Downloading Thunderbird x.x..." from updatesItem_resume or
// updatesItem_resumeFallback
key = updates.isDownloading ? "downloading" : "resume";
break;
case "pending":
// If we're waiting for the user to restart, show: "Apply Downloaded
// Updates Now..." from updatesItem_pending or
// updatesItem_pendingFallback
key = "pending";
break;
}
}
checkForUpdates.label = getStringWithUpdateName("updatesItem_" + key);
appMenuCheckForUpdates.label = getStringWithUpdateName("updatesItem_" + key);
// updatesItem_default.accesskey, updatesItem_downloading.accesskey,
// updatesItem_resume.accesskey or updatesItem_pending.accesskey
checkForUpdates.accessKey = strings.getString("updatesItem_" + key +
".accesskey");
appMenuCheckForUpdates.accessKey = strings.getString("updatesItem_" + key +
".accesskey");
if (um.activeUpdate && updates.isDownloading) {
checkForUpdates.setAttribute("loading", "true");
appMenuCheckForUpdates.setAttribute("loading", "true");
} else {
checkForUpdates.removeAttribute("loading");
appMenuCheckForUpdates.removeAttribute("loading");
}
#else
#ifndef XP_MACOSX
// Some extensions may rely on these being present so only hide the about
// separator when there are no elements besides the check for updates menuitem
// in between the about separator and the updates separator.
var updatesSeparator = document.getElementById("updatesSeparator");
var aboutSeparator = document.getElementById("aboutSeparator");
var checkForUpdates = document.getElementById("checkForUpdates");
if (updatesSeparator.nextSibling === checkForUpdates &&
checkForUpdates.nextSibling === aboutSeparator)
updatesSeparator.hidden = true;
#endif
#endif
}
function openAboutDialog() {
var enumerator = Services.wm.getEnumerator("Browser:About");
while (enumerator.hasMoreElements()) {