[gnome-shell] extensionUtils: Create and load the extension object when scanning



commit 86de6f5861c47791138af5092f3ca848fe5ef71a
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Jun 4 18:25:51 2012 -0400

    extensionUtils: Create and load the extension object when scanning
    
    This reduces some duplicate code when loading extensions.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677586

 js/extensionPrefs/main.js |   15 ++-------------
 js/misc/extensionUtils.js |    9 ++++++++-
 js/ui/extensionSystem.js  |   29 +++++++----------------------
 3 files changed, 17 insertions(+), 36 deletions(-)
---
diff --git a/js/extensionPrefs/main.js b/js/extensionPrefs/main.js
index 90fd9ab..690b1c0 100644
--- a/js/extensionPrefs/main.js
+++ b/js/extensionPrefs/main.js
@@ -207,20 +207,9 @@ const Application = new Lang.Class({
         finder.scanExtensions();
     },
 
-    _extensionFound: function(signals, uuid, dir, type) {
-        if (ExtensionUtils.extensions[uuid] !== undefined)
-            return;
-
-        let extension;
-        try {
-            extension = ExtensionUtils.createExtensionObject(uuid, dir, type);
-        } catch(e) {
-            logError(e, 'Could not create extensions object');
-            return;
-        }
-
+    _extensionFound: function(signals, extension) {
         let iter = this._model.append();
-        this._model.set(iter, [0, 1], [uuid, extension.metadata.name]);
+        this._model.set(iter, [0, 1], [extension.uuid, extension.metadata.name]);
         this._extensionIters[uuid] = iter;
     },
 
diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js
index 3eaa1b9..cec24ba 100644
--- a/js/misc/extensionUtils.js
+++ b/js/misc/extensionUtils.js
@@ -171,7 +171,14 @@ const ExtensionFinder = new Lang.Class({
                 continue;
             let uuid = info.get_name();
             let extensionDir = dir.get_child(uuid);
-            this.emit('extension-found', uuid, extensionDir, type);
+
+            let existing = extensions[uuid];
+            if (existing) {
+                log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, extensionDir.get_path()));
+                continue;
+            }
+            let extension = createExtensionObject(uuid, extensionDir, type);
+            this.emit('extension-found', extension);
         }
         fileEnum.close(null);
     },
diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js
index 902ecb6..6dde466 100644
--- a/js/ui/extensionSystem.js
+++ b/js/ui/extensionSystem.js
@@ -129,35 +129,21 @@ function logExtensionError(uuid, message, state) {
                                                state: state });
 }
 
-function loadExtension(dir, type, enabled) {
-    let uuid = dir.get_basename();
-    let extension;
-
-    if (ExtensionUtils.extensions[uuid] != undefined) {
-        log('Extension "%s" is already loaded'.format(uuid));
-        return;
-    }
-
-    try {
-        extension = ExtensionUtils.createExtensionObject(uuid, dir, type);
-    } catch(e) {
-        logExtensionError(uuid, e.message);
-        return;
-    }
-
+function loadExtension(extension) {
     // Default to error, we set success as the last step
     extension.state = ExtensionState.ERROR;
 
     if (ExtensionUtils.isOutOfDate(extension)) {
-        logExtensionError(uuid, 'extension is not compatible with current GNOME Shell and/or GJS version', ExtensionState.OUT_OF_DATE);
+        logExtensionError(extension.uuid, 'extension is not compatible with current GNOME Shell and/or GJS version', ExtensionState.OUT_OF_DATE);
         extension.state = ExtensionState.OUT_OF_DATE;
         return;
     }
 
+    let enabled = enabledExtensions.indexOf(extension.uuid) != -1;
     if (enabled) {
-        initExtension(uuid);
+        initExtension(extension.uuid);
         if (extension.state == ExtensionState.DISABLED)
-            enableExtension(uuid);
+            enableExtension(extension.uuid);
     } else {
         extension.state = ExtensionState.INITIALIZED;
     }
@@ -263,9 +249,8 @@ function init() {
 
 function loadExtensions() {
     let finder = new ExtensionUtils.ExtensionFinder();
-    finder.connect('extension-found', function(signals, uuid, dir, type) {
-        let enabled = enabledExtensions.indexOf(uuid) != -1;
-        loadExtension(dir, type, enabled);
+    finder.connect('extension-found', function(signals, extension) {
+        loadExtension(extension);
     });
     finder.scanExtensions();
 }



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