Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Update notification - based on current platform (#14655)
Browse files Browse the repository at this point in the history
* Update notification - based on current platform

* Fix lint error in Global.js

* Restructure validity check and remove duplicate function definition
  • Loading branch information
swmitra authored and shubhsnov committed Mar 5, 2019
1 parent 7479c03 commit 6cd2092
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
23 changes: 1 addition & 22 deletions src/extensions/default/AutoUpdate/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/utils/Global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
20 changes: 15 additions & 5 deletions src/utils/UpdateNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -270,20 +277,23 @@ define(function (require, exports, module) {
// should get through the search quickly.
var lastIndex = 0;
var len = versionInfo.length;
var versionEntry;
var validBuildEntries;

while (lastIndex < len) {
if (versionInfo[lastIndex].buildNumber <= buildNumber) {
versionEntry = versionInfo[lastIndex];
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;
}

/**
Expand Down Expand Up @@ -446,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");

Expand Down

0 comments on commit 6cd2092

Please sign in to comment.