[extensions-web] Add a button that checks for updates



commit c4783560806efaa63faf2e57be34a6a6c9933b01
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Dec 18 05:53:58 2011 -0500

    Add a button that checks for updates
    
    Now users can check whether they have the latest version of an extension,
    and in the event of an old version, do an upgrade by performing an
    uninstall followed by an install.

 .../extensions/templates/extensions/detail.html    |    3 +
 sweettooth/static/js/extensions.js                 |   41 ++++++++++++++++++++
 sweettooth/static/js/main.js                       |    2 +
 3 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/sweettooth/extensions/templates/extensions/detail.html b/sweettooth/extensions/templates/extensions/detail.html
index 9504ee3..a59f948 100644
--- a/sweettooth/extensions/templates/extensions/detail.html
+++ b/sweettooth/extensions/templates/extensions/detail.html
@@ -57,6 +57,9 @@
       {% endif %}
       </dl>
 
+      <div class="upgrade-me">
+      </div>
+
       <hr style="clear: both;">
 
       {% block comments %}
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index ada45e2..d4c6c75 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -46,6 +46,47 @@ function($, messages, dbusProxy, extensionUtils) {
         });
     };
 
+    $.fn.checkForUpdates = function() {
+        return this.each(function() {
+            var $elem = $(this);
+            var svm = $elem.data('svm');
+            var uuid = $elem.data('uuid');
+            if (!svm)
+                return;
+
+            var vpk = extensionUtils.grabProperExtensionVersion(svm, dbusProxy.ShellVersion);
+
+            if (vpk === null)
+                return;
+
+            function upgrade() {
+                dbusProxy.UninstallExtension(uuid).done(function() {
+                    dbusProxy.InstallExtension(uuid, vpk.version.toString());
+                });
+            }
+
+            dbusProxy.GetExtensionInfo(uuid).done(function(meta) {
+                var extensionName = $elem.find('.extension-name').text();
+                var $upgradeMe = $elem.find('.upgrade-me');
+                if (!meta)
+                    return;
+
+                if (vpk.version > meta.version) {
+                    var msg = "You have version " + meta.version + " of";
+                    msg += "\"" + extensionName + "\"";
+                    msg += ". The latest version is version " + vpk.version;
+                    msg += ". Click here to upgrade.";
+
+                    $upgradeMe.append($('<a>', { href: '#' }).txt(msg).click(upgrade));
+                } else if (vpk.version == meta.version) {
+                    var msg = "You have the latest version of ";
+                    msg += "\"" + extensionName + "\"";
+                    $upgradeMe.text(msg);
+                }
+            });
+        });
+    };
+
     // While technically we shouldn't have mismatched API versions,
     // the plugin doesn't check whether the Shell matches, so if someone
     // is running with an old Shell version but a newer plugin, error out.
diff --git a/sweettooth/static/js/main.js b/sweettooth/static/js/main.js
index 0cac953..5e591cc 100644
--- a/sweettooth/static/js/main.js
+++ b/sweettooth/static/js/main.js
@@ -132,6 +132,8 @@ require(['jquery', 'messages', 'extensions', 'uploader',
             return false;
         });
 
+        $('div.extension').checkForUpdates();
+
         var pk = $('.extension.single-page').data('epk');
         if (pk) {
             var inlineEditURL = '/ajax/edit/' + pk;



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