From 539993b4f4b76b0e5681d7cd16ef3cb293db7eaf Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 6 Jul 2012 19:28:00 -0400 Subject: [PATCH] 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 --- js/ui/extensionDownloader.js | 45 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/js/ui/extensionDownloader.js b/js/ui/extensionDownloader.js index d7940852a..4dd683d89 100644 --- a/js/ui/extensionDownloader.js +++ b/js/ui/extensionDownloader.js @@ -98,29 +98,10 @@ function gotExtensionZipFile(session, message, uuid, callback, errback) { GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, function(pid, status) { GLib.spawn_close_pid(pid); - if (status != 0) { + if (status != 0) errback('ExtractExtensionError'); - return; - } - - // 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(); + else + callback(); }); } @@ -167,17 +148,35 @@ const InstallExtensionDialog = new Lang.Class({ let url = REPOSITORY_URL_DOWNLOAD.format(this._uuid); let message = Soup.form_request_new_from_hash('GET', url, params); + let uuid = this._uuid; let invocation = this._invocation; function errback(code, message) { invocation.return_dbus_error('org.gnome.Shell.' + code, message ? message.toString() : ''); } 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')); } _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());