[extensions-web] js: Add support for browser-plugin, API protocol v2
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] js: Add support for browser-plugin, API protocol v2
- Date: Sun, 18 Dec 2011 23:33:24 +0000 (UTC)
commit a2f70e7e897b229a3cd788d05ed65acafe92ee0f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sun Dec 18 04:33:25 2011 -0500
js: Add support for browser-plugin, API protocol v2
API protocol v2 adds support for a new 'onshellrestart' API, which
is triggered when the Shell completes a full restart. Use this new
API to try and update extension state information.
sweettooth/static/js/extensions.js | 9 +++
sweettooth/static/js/versions/1/main.js | 53 ++++----------------
sweettooth/static/js/versions/2/main.js | 23 +++++++++
sweettooth/static/js/versions/common/common.js | 63 ++++++++++++++++++++++++
4 files changed, 105 insertions(+), 43 deletions(-)
---
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index 74364ca..ada45e2 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -88,6 +88,15 @@ function($, messages, dbusProxy, extensionUtils) {
elems[uuid].trigger('state-changed', newState);
};
+ dbusProxy.shellRestartHandler = function() {
+ dbusProxy.ListExtensions().done(function(extensions) {
+ $.each(extensions, function(meta) {
+ if (elems[uuid] !== undefined)
+ elems[uuid].trigger('state-changed', meta.state);
+ });
+ });
+ };
+
function addExtensionSwitch(uuid, extension, $elem) {
var $switch = $elem.find('.switch');
var _state = ExtensionState.UNINSTALLED;
diff --git a/sweettooth/static/js/versions/1/main.js b/sweettooth/static/js/versions/1/main.js
index d3110b4..3bfae28 100644
--- a/sweettooth/static/js/versions/1/main.js
+++ b/sweettooth/static/js/versions/1/main.js
@@ -1,54 +1,21 @@
"use strict";
-define(['jquery', 'dbus!API'], function($, API) {
- function _makePromise(result) {
- // Make a new completed promise -- when we move the plugin
- // over to async, we can remove this.
- return (new $.Deferred()).resolve($.parseJSON(result));
- }
-
+define(['jquery', 'dbus!API', 'versions/common/common'], function($, API, common) {
var proxy = {
- ListExtensions: function() {
- return _makePromise(API.listExtensions());
- },
-
- GetExtensionInfo: function(uuid) {
- return _makePromise(API.getExtensionInfo(uuid));
- },
-
- GetErrors: function(uuid) {
- return _makePromise(API.getExtensionErrors(uuid));
- },
-
- EnableExtension: function(uuid) {
- API.setExtensionEnabled(uuid, true);
- },
+ ListExtensions: common.ListExtensions,
+ GetExtensionInfo: common.GetExtensionInfo,
+ GetErrors: common.GetErrors,
+ EnableExtension: common.EnableExtension,
+ DisableExtension: common.DisableExtension,
+ InstallExtension: common.InstallExtension,
+ UninstallExtension: common.UninstallExtension,
- DisableExtension: function(uuid) {
- API.setExtensionEnabled(uuid, false);
- },
-
- InstallExtension: function(uuid, server_uuid) {
- API.installExtension(uuid, server_uuid);
- },
-
- UninstallExtension: function(uuid) {
- return _makePromise(API.uninstallExtension(uuid));
- },
+ ShellVersion: API.shellVersion,
extensionStateChangedHandler: null,
-
- ShellVersion: API.shellVersion
};
- API.onchange = function(uuid, newState, error) {
- try {
- proxy.extensionStateChangedHandler(uuid, newState, error);
- } catch(e) {
- // There's no way to tell if a property is callable, so
- // just catch the error.
- }
- };
+ API.onchange = common.API_onchange(proxy);
return proxy;
});
diff --git a/sweettooth/static/js/versions/2/main.js b/sweettooth/static/js/versions/2/main.js
new file mode 100644
index 0000000..6b95f3b
--- /dev/null
+++ b/sweettooth/static/js/versions/2/main.js
@@ -0,0 +1,23 @@
+"use strict";
+
+define(['jquery', 'dbus!API', 'versions/common/common'], function($, API, common) {
+ var proxy = {
+ ListExtensions: common.ListExtensions,
+ GetExtensionInfo: common.GetExtensionInfo,
+ GetErrors: common.GetErrors,
+ EnableExtension: common.EnableExtension,
+ DisableExtension: common.DisableExtension,
+ InstallExtension: common.InstallExtension,
+ UninstallExtension: common.UninstallExtension,
+
+ 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
new file mode 100644
index 0000000..aeb0425
--- /dev/null
+++ b/sweettooth/static/js/versions/common/common.js
@@ -0,0 +1,63 @@
+"use strict";
+
+define(['jquery', 'dbus!API'], function($, API) {
+ function _makePromise(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 {
+ _makePromise: _makePromise,
+
+ ListExtensions: function() {
+ return _makePromise(API.listExtensions());
+ },
+
+ GetExtensionInfo: function(uuid) {
+ return _makePromise(API.getExtensionInfo(uuid));
+ },
+
+ GetErrors: function(uuid) {
+ return _makePromise(API.getExtensionErrors(uuid));
+ },
+
+ EnableExtension: function(uuid) {
+ API.setExtensionEnabled(uuid, true);
+ },
+
+ DisableExtension: function(uuid) {
+ API.setExtensionEnabled(uuid, false);
+ },
+
+ InstallExtension: function(uuid, server_uuid) {
+ API.installExtension(uuid, server_uuid);
+ },
+
+ UninstallExtension: function(uuid) {
+ return _makePromise(API.uninstallExtension(uuid));
+ },
+
+ API_onchange: function(proxy) {
+ return function(uuid, newState, error) {
+ try {
+ proxy.extensionStateChangedHandler(uuid, newState, error);
+ } catch(e) {
+ // There's no way to tell if a property is callable, so
+ // just catch the error.
+ }
+ };
+ },
+
+ API_onshellrestart: function(proxy) {
+ return function() {
+ try {
+ proxy.shellRestartHandler();
+ } catch(e) {
+ // There's no way to tell if a property is callable, so
+ // just catch the error.
+ }
+ };
+ }
+ };
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]