[extensions-web] js: Support async installation



commit b90057fe168943a6959e8cdef11bca6482cb6905
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Jun 25 14:48:11 2012 -0400

    js: Support async installation
    
    Yeah. I need to clean this up.

 sweettooth/static/js/extensions.js             |   17 ++++++++++++--
 sweettooth/static/js/versions/5/main.js        |   28 ++++++++++++++++++++++++
 sweettooth/static/js/versions/common/common.js |   16 ++++++++++++-
 3 files changed, 56 insertions(+), 5 deletions(-)
---
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index 1091ee1..07eaa38 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -99,7 +99,13 @@ function($, messages, dbusProxy, extensionUtils, templates) {
                 if (!result)
                     return;
 
-                dbusProxy.InstallExtension(uuid);
+                dbusProxy.InstallExtension(uuid).done(function(result) {
+                    if (result === 'cancelled') {
+                        // WELP. We can't really do anything except leave the
+                        // thing uninstalled.
+                        $switch.switchify('activate', false);
+                    }
+                });
             });
         });
 
@@ -128,8 +134,13 @@ function($, messages, dbusProxy, extensionUtils, templates) {
                 if (oldState == ExtensionState.UNINSTALLED) {
                     // If the extension is uninstalled and we
                     // flick the switch on, install.
-                    dbusProxy.InstallExtension(uuid);
-                    sendPopularity('enable');
+                    dbusProxy.InstallExtension(uuid).done(function(result) {
+                        if (result === 'succeeded') {
+                            sendPopularity('enable');
+                        } else if (result === 'cancelled') {
+                            $switch.switchify('activate', false);
+                        }
+                    });
                 } else if (oldState == ExtensionState.DISABLED ||
                            oldState == ExtensionState.INITIALIZED) {
                     dbusProxy.EnableExtension(uuid);
diff --git a/sweettooth/static/js/versions/5/main.js b/sweettooth/static/js/versions/5/main.js
new file mode 100644
index 0000000..0ee6763
--- /dev/null
+++ b/sweettooth/static/js/versions/5/main.js
@@ -0,0 +1,28 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+define(['jquery', 'dbus!API', 'versions/common/common'], function($, API, common) {
+    "use strict";
+
+    var proxy = {
+        IsDummy: false,
+
+        ListExtensions: common.ListExtensions,
+        GetExtensionInfo: common.GetExtensionInfo,
+        GetErrors: common.GetErrors,
+        EnableExtension: common.EnableExtension,
+        DisableExtension: common.DisableExtension,
+        InstallExtension: common.InstallExtensionAsync,
+        UninstallExtension: common.UninstallExtension,
+        LaunchExtensionPrefs: common.LaunchExtensionPrefs,
+
+        ShellVersion: API.shellVersion,
+
+        extensionStateChangedHandler: null,
+        shellRestartHandler: null
+    };
+
+    API.onchange = common.API_onchange(proxy);
+    API.onshellrestart = common.API_onshellrestart(proxy);
+
+    return proxy;
+});
diff --git a/sweettooth/static/js/versions/common/common.js b/sweettooth/static/js/versions/common/common.js
index c5b6a9d..db7faca 100644
--- a/sweettooth/static/js/versions/common/common.js
+++ b/sweettooth/static/js/versions/common/common.js
@@ -3,10 +3,14 @@
 define(['jquery', 'dbus!API'], function($, API) {
     "use strict";
 
-    function _makePromise(result) {
+    function _makeRawPromise(result) {
         // Make a new completed promise -- when we move the plugin
         // over to async, we can remove this.
-        return (new $.Deferred()).resolve($.parseJSON(result));
+        return (new $.Deferred()).resolve(result);
+    }
+
+    function _makePromise(result) {
+        return _makeRawPromise(JSON.parse(result));
     }
 
     return {
@@ -40,10 +44,18 @@ define(['jquery', 'dbus!API'], function($, API) {
 
         InstallExtensionOne: function(uuid) {
             API.installExtension(uuid);
+            return _makeRawPromise('succeeded');
         },
 
         InstallExtensionTwo: function(uuid) {
             API.installExtension(uuid, "");
+            return _makeRawPromise('succeeded');
+        },
+
+        InstallExtensionAsync: function(uuid) {
+            var d = new $.Deferred();
+            API.installExtension(uuid, d.done.bind(d), d.fail.bind(d));
+            return d;
         },
 
         UninstallExtension: function(uuid) {



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