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 file, info;
try {
fileEnum = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NONE, null);
} catch(e) {
if (e.domain != Gio.io_error_quark() || e.code != Gio.IOErrorEnum.NOT_FOUND)
logError(e, 'Could not enumerate extensions directory');
return;
}
while ((info = fileEnum.next_file(null)) != null) {
let fileType = info.get_file_type(); let fileType = info.get_file_type();
if (fileType != Gio.FileType.DIRECTORY) if (fileType != Gio.FileType.DIRECTORY)
continue; return;
let uuid = info.get_name(); let uuid = info.get_name();
let extensionDir = dir.get_child(uuid);
let existing = extensions[uuid]; let existing = extensions[uuid];
if (existing) { if (existing) {
log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, extensionDir.get_path())); log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, extensionDir.get_path()));
continue; return;
} }
let extension; let extension;
let type = extensionDir.has_prefix(perUserDir) ? ExtensionType.PER_USER
: ExtensionType.SYSTEM;
try { try {
extension = createExtensionObject(uuid, extensionDir, type); extension = createExtensionObject(uuid, extensionDir, type);
} catch(e) { } catch(e) {
logError(e, 'Could not load extension %s'.format(uuid)); logError(e, 'Could not load extension %s'.format(uuid));
continue; return;
} }
this.emit('extension-found', extension); this.emit('extension-found', extension);
}
fileEnum.close(null);
}, },
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);