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

Commit

Permalink
Merge pull request #7869 from adobe/rlim/update-notification-fix
Browse files Browse the repository at this point in the history
Fix update notification issue
  • Loading branch information
dangoor committed May 19, 2014
2 parents 3a14163 + 2874684 commit 76cc6f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
42 changes: 23 additions & 19 deletions src/utils/UpdateNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ define(function (require, exports, module) {

// Init default last build number
PreferencesManager.stateManager.definePreference("lastNotifiedBuildNumber", "number", 0);

// Init default last info URL fetch time
PreferencesManager.stateManager.definePreference("lastInfoURLFetchTime", "number", 0);

// Time of last registry check for update
PreferencesManager.stateManager.definePreference("lastExtensionRegistryCheckTime", "number", 0);
// Data about available updates in the registry
Expand All @@ -64,14 +68,6 @@ define(function (require, exports, module) {
"updateInfo": "user"
}, true);

// This is the last version we notified the user about. If checkForUpdate()
// is called with "false", only show the update notification dialog if there
// is an update newer than this one. This value is saved in preferences.
var _lastNotifiedBuildNumber = PreferencesManager.getViewState("lastNotifiedBuildNumber");

// Last time the versionInfoURL was fetched
var _lastInfoURLFetchTime = PreferencesManager.getViewState("lastInfoURLFetchTime");

// URL to load version info from. By default this is loaded no more than once a day. If
// you force an update check it is always loaded.

Expand Down Expand Up @@ -125,6 +121,9 @@ define(function (require, exports, module) {
* _versionInfoUrl is used for unit testing.
*/
function _getUpdateInformation(force, dontCache, _versionInfoUrl) {
// Last time the versionInfoURL was fetched
var lastInfoURLFetchTime = PreferencesManager.getViewState("lastInfoURLFetchTime");

var result = new $.Deferred();
var fetchData = false;
var data;
Expand All @@ -141,7 +140,7 @@ define(function (require, exports, module) {
}

// If more than 24 hours have passed since our last fetch, fetch again
if ((new Date()).getTime() > _lastInfoURLFetchTime + ONE_DAY) {
if ((new Date()).getTime() > lastInfoURLFetchTime + ONE_DAY) {
fetchData = true;
}

Expand Down Expand Up @@ -195,8 +194,8 @@ define(function (require, exports, module) {
cache: false
}).done(function (updateInfo, textStatus, jqXHR) {
if (!dontCache) {
_lastInfoURLFetchTime = (new Date()).getTime();
PreferencesManager.setViewState("lastInfoURLFetchTime", _lastInfoURLFetchTime);
lastInfoURLFetchTime = (new Date()).getTime();
PreferencesManager.setViewState("lastInfoURLFetchTime", lastInfoURLFetchTime);
PreferencesManager.setViewState("updateInfo", updateInfo);
}
result.resolve(updateInfo);
Expand Down Expand Up @@ -324,6 +323,11 @@ define(function (require, exports, module) {
* @return {$.Promise} jQuery Promise object that is resolved or rejected after the update check is complete.
*/
function checkForUpdate(force, _testValues) {
// This is the last version we notified the user about. If checkForUpdate()
// is called with "false", only show the update notification dialog if there
// is an update newer than this one. This value is saved in preferences.
var lastNotifiedBuildNumber = PreferencesManager.getViewState("lastNotifiedBuildNumber");

// The second param, if non-null, is an Object containing value overrides. Values
// in the object temporarily override the local values. This should *only* be used for testing.
// If any overrides are set, permanent changes are not made (including showing
Expand All @@ -342,9 +346,9 @@ define(function (require, exports, module) {
usingOverrides = true;
}

if (_testValues.hasOwnProperty("_lastNotifiedBuildNumber")) {
oldValues._lastNotifiedBuildNumber = _lastNotifiedBuildNumber;
_lastNotifiedBuildNumber = _testValues._lastNotifiedBuildNumber;
if (_testValues.hasOwnProperty("lastNotifiedBuildNumber")) {
oldValues.lastNotifiedBuildNumber = lastNotifiedBuildNumber;
lastNotifiedBuildNumber = _testValues.lastNotifiedBuildNumber;
usingOverrides = true;
}

Expand Down Expand Up @@ -382,14 +386,14 @@ define(function (require, exports, module) {

// Only show the update dialog if force = true, or if the user hasn't been
// alerted of this update
if (force || allUpdates[0].buildNumber > _lastNotifiedBuildNumber) {
if (force || allUpdates[0].buildNumber > lastNotifiedBuildNumber) {
_showUpdateNotificationDialog(allUpdates);

// Update prefs with the last notified build number
_lastNotifiedBuildNumber = allUpdates[0].buildNumber;
lastNotifiedBuildNumber = allUpdates[0].buildNumber;
// Don't save prefs is we have overridden values
if (!usingOverrides) {
PreferencesManager.setViewState("lastNotifiedBuildNumber", _lastNotifiedBuildNumber);
PreferencesManager.setViewState("lastNotifiedBuildNumber", lastNotifiedBuildNumber);
}
}
} else if (force) {
Expand All @@ -405,8 +409,8 @@ define(function (require, exports, module) {
if (oldValues.hasOwnProperty("_buildNumber")) {
_buildNumber = oldValues._buildNumber;
}
if (oldValues.hasOwnProperty("_lastNotifiedBuildNumber")) {
_lastNotifiedBuildNumber = oldValues._lastNotifiedBuildNumber;
if (oldValues.hasOwnProperty("lastNotifiedBuildNumber")) {
lastNotifiedBuildNumber = oldValues.lastNotifiedBuildNumber;
}
}
result.resolve();
Expand Down
16 changes: 8 additions & 8 deletions test/spec/UpdateNotification-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ define(function (require, exports, module) {
it("should show a notification if an update is available", function () {
var updateInfo = {
_buildNumber: 72,
_lastNotifiedBuildNumber: 0,
lastNotifiedBuildNumber: 0,
_versionInfoURL: updateInfoURL
};

Expand All @@ -81,7 +81,7 @@ define(function (require, exports, module) {
it("should show update information for all available updates", function () {
var updateInfo = {
_buildNumber: 10,
_lastNotifiedBuildNumber: 0,
lastNotifiedBuildNumber: 0,
_versionInfoURL: updateInfoURL
};

Expand All @@ -100,7 +100,7 @@ define(function (require, exports, module) {
it("should not show dialog if user has already been notified", function () {
var updateInfo = {
_buildNumber: 10,
_lastNotifiedBuildNumber: 93,
lastNotifiedBuildNumber: 93,
_versionInfoURL: updateInfoURL
};

Expand All @@ -118,7 +118,7 @@ define(function (require, exports, module) {
it("should not show dialog if app is up to date", function () {
var updateInfo = {
_buildNumber: 93,
_lastNotifiedBuildNumber: 0,
lastNotifiedBuildNumber: 0,
_versionInfoURL: updateInfoURL
};

Expand All @@ -136,7 +136,7 @@ define(function (require, exports, module) {
it("should show an 'up to date' alert if no updates are available and the user manually checks for updates", function () {
var updateInfo = {
_buildNumber: 93,
_lastNotifiedBuildNumber: 93,
lastNotifiedBuildNumber: 93,
_versionInfoURL: updateInfoURL
};

Expand All @@ -155,7 +155,7 @@ define(function (require, exports, module) {
it("should sanitize text returned from server", function () {
var updateInfo = {
_buildNumber: 72,
_lastNotifiedBuildNumber: 0,
lastNotifiedBuildNumber: 0,
_versionInfoURL: maliciousInfoURL
};

Expand All @@ -177,7 +177,7 @@ define(function (require, exports, module) {
it("should error dialog if json is broken and can not be parsed", function () {
var updateInfo = {
_buildNumber: 72,
_lastNotifiedBuildNumber: 0,
lastNotifiedBuildNumber: 0,
_versionInfoURL: brokenInfoURL
};

Expand All @@ -196,7 +196,7 @@ define(function (require, exports, module) {
describe("Locale Fallback", function () {
var updateInfo = {
_buildNumber: 72,
_lastNotifiedBuildNumber: 0,
lastNotifiedBuildNumber: 0,
_versionInfoURL: doesNotExistURL
};

Expand Down

0 comments on commit 76cc6f8

Please sign in to comment.