extensionDownloader: Fix up style

Move all remaining bits to the new coding style before making
further changes.

The let → const changes are selectively done to the bits that'll
still be around at the end of the patch series.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1940>
This commit is contained in:
Florian Müllner 2021-08-07 00:47:24 +02:00 committed by Marge Bot
parent 4bbbee4dd6
commit b3bdcbcf3f

View File

@ -17,13 +17,15 @@ var REPOSITORY_URL_UPDATE = 'https://extensions.gnome.org/update-info/';
let _httpSession; let _httpSession;
function installExtension(uuid, invocation) { function installExtension(uuid, invocation) {
let params = { uuid, const params = {
shell_version: Config.PACKAGE_VERSION }; uuid,
shell_version: Config.PACKAGE_VERSION,
};
let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params); let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params);
_httpSession.queue_message(message, () => { _httpSession.queue_message(message, () => {
if (message.status_code != Soup.KnownStatusCode.OK) { if (message.status_code !== Soup.KnownStatusCode.OK) {
Main.extensionManager.logExtensionError(uuid, 'downloading info: %d'.format(message.status_code)); Main.extensionManager.logExtensionError(uuid, 'downloading info: %d'.format(message.status_code));
invocation.return_dbus_error('org.gnome.Shell.DownloadInfoError', message.status_code.toString()); invocation.return_dbus_error('org.gnome.Shell.DownloadInfoError', message.status_code.toString());
return; return;
@ -49,7 +51,7 @@ function uninstallExtension(uuid) {
return false; return false;
// Don't try to uninstall system extensions // Don't try to uninstall system extensions
if (extension.type != ExtensionUtils.ExtensionType.PER_USER) if (extension.type !== ExtensionUtils.ExtensionType.PER_USER)
return false; return false;
if (!Main.extensionManager.unloadExtension(extension)) if (!Main.extensionManager.unloadExtension(extension))
@ -69,7 +71,7 @@ function uninstallExtension(uuid) {
} }
function gotExtensionZipFile(session, message, uuid, dir, callback, errback) { function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
if (message.status_code != Soup.KnownStatusCode.OK) { if (message.status_code !== Soup.KnownStatusCode.OK) {
errback('DownloadExtensionError', message.status_code); errback('DownloadExtensionError', message.status_code);
return; return;
} }
@ -87,10 +89,10 @@ function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
stream.output_stream.write_bytes(contents, null); stream.output_stream.write_bytes(contents, null);
stream.close(null); stream.close(null);
let [success, pid] = GLib.spawn_async(null, let [success, pid] = GLib.spawn_async(null,
['unzip', '-uod', dir.get_path(), '--', file.get_path()], ['unzip', '-uod', dir.get_path(), '--', file.get_path()],
null, null,
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
null); null);
if (!success) { if (!success) {
errback('ExtractExtensionError'); errback('ExtractExtensionError');
@ -100,7 +102,7 @@ function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, (o, status) => { GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, (o, status) => {
GLib.spawn_close_pid(pid); GLib.spawn_close_pid(pid);
if (status != 0) if (status !== 0)
errback('ExtractExtensionError'); errback('ExtractExtensionError');
else else
callback(); callback();
@ -111,10 +113,10 @@ function downloadExtensionUpdate(uuid) {
if (!Main.extensionManager.updatesSupported) if (!Main.extensionManager.updatesSupported)
return; return;
let dir = Gio.File.new_for_path( const dir = Gio.File.new_for_path(
GLib.build_filenamev([global.userdatadir, 'extension-updates', uuid])); GLib.build_filenamev([global.userdatadir, 'extension-updates', uuid]));
let params = { shell_version: Config.PACKAGE_VERSION }; const params = { shell_version: Config.PACKAGE_VERSION };
let url = REPOSITORY_URL_DOWNLOAD.format(uuid); let url = REPOSITORY_URL_DOWNLOAD.format(uuid);
let message = Soup.form_request_new_from_hash('GET', url, params); let message = Soup.form_request_new_from_hash('GET', url, params);
@ -147,9 +149,9 @@ function checkForUpdates() {
if (Object.keys(metadatas).length === 0) if (Object.keys(metadatas).length === 0)
return; // nothing to update return; // nothing to update
let versionCheck = global.settings.get_boolean( const versionCheck = global.settings.get_boolean(
'disable-extension-version-validation'); 'disable-extension-version-validation');
let params = { const params = {
shell_version: Config.PACKAGE_VERSION, shell_version: Config.PACKAGE_VERSION,
disable_version_validation: versionCheck.toString(), disable_version_validation: versionCheck.toString(),
}; };
@ -165,7 +167,7 @@ function checkForUpdates() {
); );
_httpSession.queue_message(message, () => { _httpSession.queue_message(message, () => {
if (message.status_code != Soup.KnownStatusCode.OK) if (message.status_code !== Soup.KnownStatusCode.OK)
return; return;
let operations = JSON.parse(message.response_body.data); let operations = JSON.parse(message.response_body.data);
@ -187,11 +189,11 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
this._invocation = invocation; this._invocation = invocation;
this.setButtons([{ this.setButtons([{
label: _("Cancel"), label: _('Cancel'),
action: this._onCancelButtonPressed.bind(this), action: this._onCancelButtonPressed.bind(this),
key: Clutter.KEY_Escape, key: Clutter.KEY_Escape,
}, { }, {
label: _("Install"), label: _('Install'),
action: this._onInstallButtonPressed.bind(this), action: this._onInstallButtonPressed.bind(this),
default: true, default: true,
}]); }]);
@ -210,13 +212,14 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
} }
_onInstallButtonPressed() { _onInstallButtonPressed() {
let params = { shell_version: Config.PACKAGE_VERSION }; const params = { shell_version: Config.PACKAGE_VERSION };
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);
const dir = Gio.File.new_for_path(GLib.build_filenamev(
[global.userdatadir, 'extensions', this._uuid]));
let uuid = this._uuid; let uuid = this._uuid;
let dir = Gio.File.new_for_path(GLib.build_filenamev([global.userdatadir, 'extensions', uuid]));
let invocation = this._invocation; let invocation = this._invocation;
function errback(code, msg) { function errback(code, msg) {
log('Error while installing %s: %s (%s)'.format(uuid, code, msg)); log('Error while installing %s: %s (%s)'.format(uuid, code, msg));