extensionUtils: Load extensions asynchronously

Use the new collectFromDatadirsAsync() function for extension
loading as well.

https://bugzilla.gnome.org/show_bug.cgi?id=689304
This commit is contained in:
Florian Müllner 2012-11-30 18:06:11 +01:00
parent c528401b62
commit 6b40c3974d

View File

@ -11,6 +11,7 @@ const Gio = imports.gi.Gio;
const ShellJS = imports.gi.ShellJS; const ShellJS = imports.gi.ShellJS;
const Config = imports.misc.config; const Config = imports.misc.config;
const FileUtils = imports.misc.fileUtils;
const ExtensionType = { const ExtensionType = {
SYSTEM: 1, SYSTEM: 1,
@ -150,53 +151,35 @@ function installImporter(extension) {
const ExtensionFinder = new Lang.Class({ const ExtensionFinder = new Lang.Class({
Name: 'ExtensionFinder', Name: 'ExtensionFinder',
_scanExtensionsInDirectory: function(dir, type) { _loadExtension: function(extensionDir, info, perUserDir) {
let fileEnum; let fileType = info.get_file_type();
let file, info; if (fileType != Gio.FileType.DIRECTORY)
try { return;
fileEnum = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NONE, null); let uuid = info.get_name();
} catch(e) { let existing = extensions[uuid];
if (e.domain != Gio.io_error_quark() || e.code != Gio.IOErrorEnum.NOT_FOUND) if (existing) {
logError(e, 'Could not enumerate extensions directory'); log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, extensionDir.get_path()));
return; return;
} }
while ((info = fileEnum.next_file(null)) != null) { let extension;
let fileType = info.get_file_type(); let type = extensionDir.has_prefix(perUserDir) ? ExtensionType.PER_USER
if (fileType != Gio.FileType.DIRECTORY) : ExtensionType.SYSTEM;
continue; try {
let uuid = info.get_name(); extension = createExtensionObject(uuid, extensionDir, type);
let extensionDir = dir.get_child(uuid); } catch(e) {
logError(e, 'Could not load extension %s'.format(uuid));
let existing = extensions[uuid]; return;
if (existing) {
log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, extensionDir.get_path()));
continue;
}
let extension;
try {
extension = createExtensionObject(uuid, extensionDir, type);
} catch(e) {
logError(e, 'Could not load extension %s'.format(uuid));
continue;
}
this.emit('extension-found', extension);
} }
fileEnum.close(null); this.emit('extension-found', extension);
}, },
scanExtensions: function() { scanExtensions: function() {
let userExtensionsDir = Gio.File.new_for_path(GLib.build_filenamev([global.userdatadir, 'extensions'])); let perUserDir = Gio.File.new_for_path(global.userdatadir);
this._scanExtensionsInDirectory(userExtensionsDir, ExtensionType.PER_USER); FileUtils.collectFromDatadirsAsync('extensions',
{ processFile: Lang.bind(this, this._loadExtension),
let systemDataDirs = GLib.get_system_data_dirs(); includeUserDir: true,
for (let i = 0; i < systemDataDirs.length; i++) { data: perUserDir });
let dirPath = GLib.build_filenamev([systemDataDirs[i], 'gnome-shell', 'extensions']);
let dir = Gio.file_new_for_path(dirPath);
if (dir.query_exists(null))
this._scanExtensionsInDirectory(dir, ExtensionType.SYSTEM);
}
} }
}); });
Signals.addSignalMethods(ExtensionFinder.prototype); Signals.addSignalMethods(ExtensionFinder.prototype);