diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-02-12 16:13:57 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-02-12 16:13:57 +0100 |
commit | dd418226c6a91301002134f699117ba00f1e0804 (patch) | |
tree | f3cd6bb7ed885199bb60e54ca09f0b19951fc32c /application/palemoon/base | |
parent | 487afe9f45a846daaf8aab8b0cc0022dbc92ce09 (diff) | |
download | UXP-dd418226c6a91301002134f699117ba00f1e0804.tar UXP-dd418226c6a91301002134f699117ba00f1e0804.tar.gz UXP-dd418226c6a91301002134f699117ba00f1e0804.tar.lz UXP-dd418226c6a91301002134f699117ba00f1e0804.tar.xz UXP-dd418226c6a91301002134f699117ba00f1e0804.zip |
Add "check for updates" to main menu and AppMenu v2
Tag #963.
Diffstat (limited to 'application/palemoon/base')
-rw-r--r-- | application/palemoon/base/content/baseMenuOverlay.xul | 10 | ||||
-rw-r--r-- | application/palemoon/base/content/browser-appmenu.inc | 9 | ||||
-rw-r--r-- | application/palemoon/base/content/utilityOverlay.js | 111 |
3 files changed, 128 insertions, 2 deletions
diff --git a/application/palemoon/base/content/baseMenuOverlay.xul b/application/palemoon/base/content/baseMenuOverlay.xul index e9019dc55..d7c983671 100644 --- a/application/palemoon/base/content/baseMenuOverlay.xul +++ b/application/palemoon/base/content/baseMenuOverlay.xul @@ -41,7 +41,7 @@ label="&helpMenu.label;" accesskey="&helpMenu.accesskey;"> #endif - <menupopup id="menu_HelpPopup"> + <menupopup id="menu_HelpPopup" onpopupshowing="buildHelpMenu();"> <menuitem id="menu_openHelp" oncommand="openHelpLink('firefox-help')" onclick="checkForMiddleClick(this, event);" @@ -66,6 +66,14 @@ accesskey="&helpSafeMode.accesskey;" label="&helpSafeMode.label;" oncommand="restart(true);"/> + <menuseparator id="updateSeparator"/> + <menuitem id="checkForUpdates" class="menuitem-iconic" +#ifdef MOZ_UPDATER + label="&updateCmd.label;" + oncommand="checkForUpdates();"/> +#else + hidden="true"/> +#endif <menuseparator id="aboutSeparator"/> <menuitem id="aboutName" accesskey="&aboutProduct.accesskey;" diff --git a/application/palemoon/base/content/browser-appmenu.inc b/application/palemoon/base/content/browser-appmenu.inc index cfc855484..ffb117a60 100644 --- a/application/palemoon/base/content/browser-appmenu.inc +++ b/application/palemoon/base/content/browser-appmenu.inc @@ -341,7 +341,7 @@ <splitmenu id="appmenu_help" label="&helpMenu.label;" oncommand="openHelpLink('firefox-help')"> - <menupopup id="appmenu_helpMenupopup"> + <menupopup id="appmenu_helpMenupopup" onpopupshowing="buildHelpMenu();"> <menuitem id="appmenu_openHelp" label="&helpMenu.label;" oncommand="openHelpLink('firefox-help')" @@ -358,6 +358,13 @@ <menuitem id="appmenu_safeMode" label="&appMenuSafeMode.label;" oncommand="restart(true);"/> +#ifdef MOZ_UPDATER + <menuseparator/> + <menuitem id="appmenu_checkForUpdates" + class="menuitem-iconic" + label="&updateCmd.label;" + oncommand="checkForUpdates();"/> +#endif <menuseparator/> <menuitem id="appmenu_about" label="&aboutProduct.label;" diff --git a/application/palemoon/base/content/utilityOverlay.js b/application/palemoon/base/content/utilityOverlay.js index 2c1a95f83..fe148ad04 100644 --- a/application/palemoon/base/content/utilityOverlay.js +++ b/application/palemoon/base/content/utilityOverlay.js @@ -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()) { |