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();
|
finder.scanExtensions();
|
||||||
},
|
},
|
||||||
|
|
||||||
_extensionFound: function(signals, uuid, dir, type) {
|
_extensionFound: function(signals, extension) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
let iter = this._model.append();
|
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;
|
this._extensionIters[uuid] = iter;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -171,7 +171,14 @@ const ExtensionFinder = new Lang.Class({
|
|||||||
continue;
|
continue;
|
||||||
let uuid = info.get_name();
|
let uuid = info.get_name();
|
||||||
let extensionDir = dir.get_child(uuid);
|
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);
|
fileEnum.close(null);
|
||||||
},
|
},
|
||||||
|
@ -129,35 +129,21 @@ function logExtensionError(uuid, message, state) {
|
|||||||
state: state });
|
state: state });
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadExtension(dir, type, enabled) {
|
function loadExtension(extension) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to error, we set success as the last step
|
// Default to error, we set success as the last step
|
||||||
extension.state = ExtensionState.ERROR;
|
extension.state = ExtensionState.ERROR;
|
||||||
|
|
||||||
if (ExtensionUtils.isOutOfDate(extension)) {
|
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;
|
extension.state = ExtensionState.OUT_OF_DATE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let enabled = enabledExtensions.indexOf(extension.uuid) != -1;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
initExtension(uuid);
|
initExtension(extension.uuid);
|
||||||
if (extension.state == ExtensionState.DISABLED)
|
if (extension.state == ExtensionState.DISABLED)
|
||||||
enableExtension(uuid);
|
enableExtension(extension.uuid);
|
||||||
} else {
|
} else {
|
||||||
extension.state = ExtensionState.INITIALIZED;
|
extension.state = ExtensionState.INITIALIZED;
|
||||||
}
|
}
|
||||||
@ -263,9 +249,8 @@ function init() {
|
|||||||
|
|
||||||
function loadExtensions() {
|
function loadExtensions() {
|
||||||
let finder = new ExtensionUtils.ExtensionFinder();
|
let finder = new ExtensionUtils.ExtensionFinder();
|
||||||
finder.connect('extension-found', function(signals, uuid, dir, type) {
|
finder.connect('extension-found', function(signals, extension) {
|
||||||
let enabled = enabledExtensions.indexOf(uuid) != -1;
|
loadExtension(extension);
|
||||||
loadExtension(dir, type, enabled);
|
|
||||||
});
|
});
|
||||||
finder.scanExtensions();
|
finder.scanExtensions();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user