[extensions-web] dbus.js: added support for chrome-gnome-shell.



commit 9d6f222d2638088b7df60a2b6dabae8358633177
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Sat Nov 19 11:12:33 2016 +0300

    dbus.js: added support for chrome-gnome-shell.
    
    That will allow to drop most of hacks in chrome-gnome-shell

 sweettooth/static/js/dbus.js |   59 +++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 21 deletions(-)
---
diff --git a/sweettooth/static/js/dbus.js b/sweettooth/static/js/dbus.js
index 9d1234c..4711e2f 100644
--- a/sweettooth/static/js/dbus.js
+++ b/sweettooth/static/js/dbus.js
@@ -13,9 +13,34 @@ define(['jquery'], function($) {
     var exports = {};
 
     var load = exports.load = function(name, req, onLoad, config) {
+        function processLoad()
+        {
+            if (name == "API") {
+                onLoad(window.SweetTooth);
+                return;
+            }
+
+            var apiVersion = undefined;
+
+            try {
+                if (window.SweetTooth) {
+                    apiVersion = window.SweetTooth.apiVersion;
+                }
+            } catch (e) { }
+
+            if (!apiVersion)
+                apiVersion = 'dummy';
+
+            var scriptname = './versions/' + apiVersion + '/main';
+            // requirejs caches response.
+            req([scriptname], function(module) {
+                onLoad(module);
+            });
+        }
 
         $(document).ready(function() {
             if (!('SweetTooth' in window)) {
+                // Try NPAPI plugin
                 try {
                     var MIME_TYPE = 'application/x-gnome-shell-integration';
                     var $plg = $('<embed>', { type: MIME_TYPE });
@@ -43,29 +68,21 @@ define(['jquery'], function($) {
                     // plugin to NULL
                     window.SweetTooth = null;
                 }
-            }
 
-            if (name == "API") {
-                onLoad(window.SweetTooth);
-                return;
+                processLoad();
+            }
+            else if (typeof(SweetTooth.initialize) === 'function')
+            {
+                // Browser extension
+                // SweetTooth.initialize should be Promise or jQuery.Deferred
+                SweetTooth.initialize().then(function() {
+                    processLoad();
+                })
+            }
+            else
+            {
+                processLoad();
             }
-
-            var apiVersion = undefined;
-
-            try {
-                if (window.SweetTooth) {
-                    apiVersion = window.SweetTooth.apiVersion;
-                }
-            } catch (e) { }
-
-            if (!apiVersion)
-                apiVersion = 'dummy';
-
-            var scriptname = './versions/' + apiVersion + '/main';
-            // requirejs caches response.
-            req([scriptname], function(module) {
-                onLoad(module);
-            });
         });
     };
 


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