[extensions-web] When an extension is out of date, tell the user what to do



commit e9e281d2175c9cc1e099faebaf2ba91328a36ba0
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Dec 5 21:22:04 2011 -0500

    When an extension is out of date, tell the user what to do
    
    Tell the user to upgrade to the next highest release of GNOME in the case
    that the extension is out of date.

 sweettooth/static/js/extensionUtils.js  |   24 ++++++++++++++++++++++++
 sweettooth/static/js/extensions.js      |    4 +++-
 sweettooth/static/js/test/extensions.js |    9 +++++++++
 3 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/sweettooth/static/js/extensionUtils.js b/sweettooth/static/js/extensionUtils.js
index 8aecad8..2c85edf 100644
--- a/sweettooth/static/js/extensionUtils.js
+++ b/sweettooth/static/js/extensionUtils.js
@@ -67,6 +67,30 @@ define([], function() {
         }
     };
 
+    module.findNextHighestVersion = function(map, current) {
+        function saneParseInt(p) {
+            return parseInt(p, 10);
+        }
+
+        var currentParts = current.split('.').map(saneParseInt);
+        var nextHighestParts = [Infinity, Infinity, Infinity];
+
+        $.each(map, function(key) {
+            var parts = key.split('.').map(saneParseInt);
+
+            if (parts[0] >= currentParts[0] &&
+                parts[1] >= currentParts[1] &&
+                ((parts[2] !== undefined && currentParts[2] !== undefined && parts[2] >= currentParts[2])
+                 || parts[2] === undefined || currentParts[2] === undefined) &&
+                parts[0] < nextHighestParts[0] &&
+                parts[1] < nextHighestParts[1] &&
+                ((parts[2] !== undefined && parts[2] < nextHighestParts[2]) || parts[2] === undefined))
+                nextHighestParts = parts;
+        });
+
+        return nextHighestParts.join('.');
+    };
+
     return module;
 
 });
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index 4135af6..956ce66 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -279,7 +279,9 @@ function($, messages, dbusProxy, extensionUtils) {
             var uuid = $extension.data('uuid');
 
             $extension.bind('out-of-date', function() {
-                messages.addError("This extension is incompatible with your version of GNOME.");
+                var svm = $extension.data('svm');
+                var nextHighestVersion = extensionUtils.findNextHighestVersion(svm, dbusProxy.ShellVersion);
+                messages.addError("This extension is incompatible with your version of GNOME. Please upgrade to GNOME " + nextHighestVersion);
             });
 
             dbusProxy.GetExtensionInfo(uuid).done(function(meta) {
diff --git a/sweettooth/static/js/test/extensions.js b/sweettooth/static/js/test/extensions.js
index 4b66aa4..eebf8b3 100644
--- a/sweettooth/static/js/test/extensions.js
+++ b/sweettooth/static/js/test/extensions.js
@@ -29,4 +29,13 @@ require(['extensionUtils', 'jquery', 'test/qunit'], function(extensionUtils) {
         equal(grabProperExtensionVersion(map, "3.3.0"), null, "stable release checking");
         equal(grabProperExtensionVersion(map, "3.3.1").version, 6);
     });
+
+    var findNextHighestVersion = extensionUtils.findNextHighestVersion;
+    test("findNextHighestVersion", function() {
+        equal(findNextHighestVersion({ "3.2": true }, "3.0"), "3.2");
+        equal(findNextHighestVersion({ "3.2.1": true }, "3.0"), "3.2.1");
+        equal(findNextHighestVersion({ "3.2.1": true, "3.0": true }, "3.2"), "3.2.1");
+        equal(findNextHighestVersion({ "3.3": true, "3.0": true }, "3.2"), "3.3");
+        equal(findNextHighestVersion({ "3.2.1": true, "3.0": true, "3.3.1": true }, "3.2"), "3.2.1");
+    });
 });



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]