From e14e9f4eafaab810deb7ca8de87a2e9dfe63d291 Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Thu, 21 Feb 2019 10:51:37 +0530 Subject: [PATCH 1/3] Update notification - based on current platform --- src/utils/Global.js | 18 ++++++++++++++++++ src/utils/UpdateNotification.js | 11 ++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/utils/Global.js b/src/utils/Global.js index 76c85cfdf1d..48e02ec801c 100644 --- a/src/utils/Global.js +++ b/src/utils/Global.js @@ -83,6 +83,24 @@ define(function (require, exports, module) { global.brackets.platform = "win"; } + // Expose platform info for build applicability consumption + global.brackets.getPlatformInfo = function () { + var OS = ""; + + if (/Windows|Win32|WOW64|Win64/.test(window.navigator.userAgent)) { + OS = "WIN"; + } else if (/Mac/.test(window.navigator.userAgent)) { + OS = "OSX"; + } else if (/Linux|X11/.test(window.navigator.userAgent)) { + OS = "LINUX32"; + if (/x86_64/.test(window.navigator.appVersion + window.navigator.userAgent)) { + OS = "LINUX64"; + } + } + + return OS; + } + global.brackets.inBrowser = !global.brackets.hasOwnProperty("fs"); // Are we in a desktop shell with a native menu bar? diff --git a/src/utils/UpdateNotification.js b/src/utils/UpdateNotification.js index dd012e4027c..3f6ae5a96a2 100644 --- a/src/utils/UpdateNotification.js +++ b/src/utils/UpdateNotification.js @@ -261,6 +261,13 @@ define(function (require, exports, module) { return result.promise(); } + /** + * Checks whether a build is applicable to the current platform. + */ + function _checkBuildApplicability(buildInfo) { + return !buildInfo.platforms || buildInfo.platforms[brackets.getPlatformInfo()]; + } + /** * Return a new array of version information that is newer than "buildNumber". * Returns null if there is no new version information. @@ -270,9 +277,11 @@ define(function (require, exports, module) { // should get through the search quickly. var lastIndex = 0; var len = versionInfo.length; + var versionEntry; while (lastIndex < len) { - if (versionInfo[lastIndex].buildNumber <= buildNumber) { + versionEntry = versionInfo[lastIndex]; + if (versionEntry.buildNumber <= buildNumber && _checkBuildApplicability(versionEntry)) { break; } lastIndex++; From 31d48ada72843c87afd78e3c44c0cb77e953e14b Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Thu, 21 Feb 2019 11:55:09 +0530 Subject: [PATCH 2/3] Fix lint error in Global.js --- src/utils/Global.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/Global.js b/src/utils/Global.js index 48e02ec801c..69a9189799c 100644 --- a/src/utils/Global.js +++ b/src/utils/Global.js @@ -99,7 +99,7 @@ define(function (require, exports, module) { } return OS; - } + }; global.brackets.inBrowser = !global.brackets.hasOwnProperty("fs"); From ad1e5dde588dcb4e368f58dc76207c48934ecabc Mon Sep 17 00:00:00 2001 From: Swagatam Mitra Date: Thu, 21 Feb 2019 15:34:25 +0530 Subject: [PATCH 3/3] Restructure validity check and remove duplicate function definition --- src/extensions/default/AutoUpdate/main.js | 23 +---------------------- src/utils/UpdateNotification.js | 11 ++++++----- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/extensions/default/AutoUpdate/main.js b/src/extensions/default/AutoUpdate/main.js index a4fa83f1411..0f0d4f41bf7 100644 --- a/src/extensions/default/AutoUpdate/main.js +++ b/src/extensions/default/AutoUpdate/main.js @@ -329,27 +329,6 @@ define(function (require, exports, module) { } - /** - * Generates the extension for installer file, based on platform - * @returns {string} - OS - current OS } - */ - function getPlatformInfo() { - var OS = ""; - - if (/Windows|Win32|WOW64|Win64/.test(window.navigator.userAgent)) { - OS = "WIN"; - } else if (/Mac/.test(window.navigator.userAgent)) { - OS = "OSX"; - } else if (/Linux|X11/.test(window.navigator.userAgent)) { - OS = "LINUX32"; - if (/x86_64/.test(window.navigator.appVersion + window.navigator.userAgent)) { - OS = "LINUX64"; - } - } - - return OS; - } - /** * Initializes the state for AutoUpdate process * @returns {$.Deferred} - a jquery promise, @@ -466,7 +445,7 @@ define(function (require, exports, module) { console.warn("AutoUpdate : updates information not available."); return; } - var OS = getPlatformInfo(), + var OS = brackets.getPlatformInfo(), checksum, downloadURL, installerName, diff --git a/src/utils/UpdateNotification.js b/src/utils/UpdateNotification.js index 3f6ae5a96a2..cdd05f6067e 100644 --- a/src/utils/UpdateNotification.js +++ b/src/utils/UpdateNotification.js @@ -278,21 +278,22 @@ define(function (require, exports, module) { var lastIndex = 0; var len = versionInfo.length; var versionEntry; + var validBuildEntries; while (lastIndex < len) { versionEntry = versionInfo[lastIndex]; - if (versionEntry.buildNumber <= buildNumber && _checkBuildApplicability(versionEntry)) { + if (versionEntry.buildNumber <= buildNumber) { break; } lastIndex++; } if (lastIndex > 0) { - return versionInfo.slice(0, lastIndex); + // Filter recent update entries based on applicability to current platform + validBuildEntries = versionInfo.slice(0, lastIndex).filter(_checkBuildApplicability); } - // No new version info - return null; + return validBuildEntries; } /** @@ -455,7 +456,7 @@ define(function (require, exports, module) { return; } - if (allUpdates) { + if (allUpdates && allUpdates.length > 0) { // Always show the "update available" icon if any updates are available var $updateNotification = $("#update-notification");