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

Commit 6cd2092

Browse files
swmitrashubhsnov
authored andcommitted
Update notification - based on current platform (#14655)
* Update notification - based on current platform * Fix lint error in Global.js * Restructure validity check and remove duplicate function definition
1 parent 7479c03 commit 6cd2092

3 files changed

Lines changed: 34 additions & 27 deletions

File tree

src/extensions/default/AutoUpdate/main.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -329,27 +329,6 @@ define(function (require, exports, module) {
329329
}
330330

331331

332-
/**
333-
* Generates the extension for installer file, based on platform
334-
* @returns {string} - OS - current OS }
335-
*/
336-
function getPlatformInfo() {
337-
var OS = "";
338-
339-
if (/Windows|Win32|WOW64|Win64/.test(window.navigator.userAgent)) {
340-
OS = "WIN";
341-
} else if (/Mac/.test(window.navigator.userAgent)) {
342-
OS = "OSX";
343-
} else if (/Linux|X11/.test(window.navigator.userAgent)) {
344-
OS = "LINUX32";
345-
if (/x86_64/.test(window.navigator.appVersion + window.navigator.userAgent)) {
346-
OS = "LINUX64";
347-
}
348-
}
349-
350-
return OS;
351-
}
352-
353332
/**
354333
* Initializes the state for AutoUpdate process
355334
* @returns {$.Deferred} - a jquery promise,
@@ -466,7 +445,7 @@ define(function (require, exports, module) {
466445
console.warn("AutoUpdate : updates information not available.");
467446
return;
468447
}
469-
var OS = getPlatformInfo(),
448+
var OS = brackets.getPlatformInfo(),
470449
checksum,
471450
downloadURL,
472451
installerName,

src/utils/Global.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ define(function (require, exports, module) {
8383
global.brackets.platform = "win";
8484
}
8585

86+
// Expose platform info for build applicability consumption
87+
global.brackets.getPlatformInfo = function () {
88+
var OS = "";
89+
90+
if (/Windows|Win32|WOW64|Win64/.test(window.navigator.userAgent)) {
91+
OS = "WIN";
92+
} else if (/Mac/.test(window.navigator.userAgent)) {
93+
OS = "OSX";
94+
} else if (/Linux|X11/.test(window.navigator.userAgent)) {
95+
OS = "LINUX32";
96+
if (/x86_64/.test(window.navigator.appVersion + window.navigator.userAgent)) {
97+
OS = "LINUX64";
98+
}
99+
}
100+
101+
return OS;
102+
};
103+
86104
global.brackets.inBrowser = !global.brackets.hasOwnProperty("fs");
87105

88106
// Are we in a desktop shell with a native menu bar?

src/utils/UpdateNotification.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ define(function (require, exports, module) {
261261
return result.promise();
262262
}
263263

264+
/**
265+
* Checks whether a build is applicable to the current platform.
266+
*/
267+
function _checkBuildApplicability(buildInfo) {
268+
return !buildInfo.platforms || buildInfo.platforms[brackets.getPlatformInfo()];
269+
}
270+
264271
/**
265272
* Return a new array of version information that is newer than "buildNumber".
266273
* Returns null if there is no new version information.
@@ -270,20 +277,23 @@ define(function (require, exports, module) {
270277
// should get through the search quickly.
271278
var lastIndex = 0;
272279
var len = versionInfo.length;
280+
var versionEntry;
281+
var validBuildEntries;
273282

274283
while (lastIndex < len) {
275-
if (versionInfo[lastIndex].buildNumber <= buildNumber) {
284+
versionEntry = versionInfo[lastIndex];
285+
if (versionEntry.buildNumber <= buildNumber) {
276286
break;
277287
}
278288
lastIndex++;
279289
}
280290

281291
if (lastIndex > 0) {
282-
return versionInfo.slice(0, lastIndex);
292+
// Filter recent update entries based on applicability to current platform
293+
validBuildEntries = versionInfo.slice(0, lastIndex).filter(_checkBuildApplicability);
283294
}
284295

285-
// No new version info
286-
return null;
296+
return validBuildEntries;
287297
}
288298

289299
/**
@@ -446,7 +456,7 @@ define(function (require, exports, module) {
446456
return;
447457
}
448458

449-
if (allUpdates) {
459+
if (allUpdates && allUpdates.length > 0) {
450460
// Always show the "update available" icon if any updates are available
451461
var $updateNotification = $("#update-notification");
452462

0 commit comments

Comments
 (0)