extensionDownloader: Move extension loading code to the install dialog

Move the part that loads the extension to the callback. This makes the
next patch a lot cleaner.

https://bugzilla.gnome.org/show_bug.cgi?id=679099
This commit is contained in:
Jasper St. Pierre 2012-07-06 19:28:00 -04:00
parent 1363d30f79
commit 539993b4f4

View File

@ -98,28 +98,9 @@ function gotExtensionZipFile(session, message, uuid, callback, errback) {
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, function(pid, status) { GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, function(pid, status) {
GLib.spawn_close_pid(pid); GLib.spawn_close_pid(pid);
if (status != 0) { if (status != 0)
errback('ExtractExtensionError'); errback('ExtractExtensionError');
return; else
}
// Add extension to 'enabled-extensions' for the user, always...
let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
if (enabledExtensions.indexOf(uuid) == -1) {
enabledExtensions.push(uuid);
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
}
let extension = ExtensionUtils.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
try {
ExtensionSystem.loadExtension(extension);
} catch(e) {
uninstallExtension(uuid);
errback('LoadExtensionError', e);
return;
}
callback(); callback();
}); });
} }
@ -167,17 +148,35 @@ const InstallExtensionDialog = new Lang.Class({
let url = REPOSITORY_URL_DOWNLOAD.format(this._uuid); let url = REPOSITORY_URL_DOWNLOAD.format(this._uuid);
let message = Soup.form_request_new_from_hash('GET', url, params); let message = Soup.form_request_new_from_hash('GET', url, params);
let uuid = this._uuid;
let invocation = this._invocation; let invocation = this._invocation;
function errback(code, message) { function errback(code, message) {
invocation.return_dbus_error('org.gnome.Shell.' + code, message ? message.toString() : ''); invocation.return_dbus_error('org.gnome.Shell.' + code, message ? message.toString() : '');
} }
function callback() { function callback() {
// Add extension to 'enabled-extensions' for the user, always...
let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
if (enabledExtensions.indexOf(uuid) == -1) {
enabledExtensions.push(uuid);
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
}
let extension = ExtensionUtils.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
try {
ExtensionSystem.loadExtension(extension);
} catch(e) {
uninstallExtension(uuid);
errback('LoadExtensionError', e);
return;
}
invocation.return_value(GLib.Variant.new('(s)', 'successful')); invocation.return_value(GLib.Variant.new('(s)', 'successful'));
} }
_httpSession.queue_message(message, Lang.bind(this, function(session, message) { _httpSession.queue_message(message, Lang.bind(this, function(session, message) {
gotExtensionZipFile(session, message, this._uuid, callback, errback); gotExtensionZipFile(session, message, uuid, callback, errback);
})); }));
this.close(global.get_current_time()); this.close(global.get_current_time());