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
This commit is contained in:
parent
498b023989
commit
86de6f5861
@ -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;
|
||||
},
|
||||
|
||||
|
@ -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);
|
||||
},
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user