environment: Fallback to Soup 2.4
We cannot assume yet that Soup3 is available everywhere. Until that is the case, allow falling back to Soup 2.4 by imitating the bits of the Soup3 API we use with monkey-patching. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1940>
This commit is contained in:
parent
ae90b50dc7
commit
d562c70f4e
@ -11,6 +11,14 @@ imports.gi.versions.Soup = '3.0';
|
||||
imports.gi.versions.TelepathyGLib = '0.12';
|
||||
imports.gi.versions.TelepathyLogger = '0.2';
|
||||
|
||||
try {
|
||||
const Soup_ = imports.gi.Soup;
|
||||
} catch (e) {
|
||||
imports.gi.versions.Soup = '2.4';
|
||||
const { Soup } = imports.gi;
|
||||
_injectSoup3Compat(Soup);
|
||||
}
|
||||
|
||||
const { Clutter, Gio, GLib, GObject, Meta, Polkit, Shell, St } = imports.gi;
|
||||
const Gettext = imports.gettext;
|
||||
const System = imports.system;
|
||||
@ -69,6 +77,44 @@ function _patchLayoutClass(layoutClass, styleProps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mimick the Soup 3 APIs we use when falling back to Soup 2.4
|
||||
*
|
||||
* @param {object} Soup 2.4 namespace
|
||||
* @returns {void}
|
||||
*/
|
||||
function _injectSoup3Compat(Soup) {
|
||||
const ByteArray = imports.byteArray;
|
||||
|
||||
Soup.StatusCode = Soup.KnownStatusCode;
|
||||
|
||||
Soup.Message.new_from_encoded_form =
|
||||
function (method, uri, form) {
|
||||
const soupUri = new Soup.URI(uri);
|
||||
soupUri.set_query(form);
|
||||
return Soup.Message.new_from_uri(method, soupUri);
|
||||
};
|
||||
Soup.Message.prototype.set_request_body_from_bytes =
|
||||
function (contentType, bytes) {
|
||||
this.set_request(
|
||||
contentType,
|
||||
Soup.MemoryUse.COPY,
|
||||
ByteArray.toString(bytes.get_data()));
|
||||
};
|
||||
|
||||
Soup.Session.prototype.send_and_read_async =
|
||||
function (message, prio, cancellable, callback) {
|
||||
this.queue_message(message, () => callback(this, message));
|
||||
};
|
||||
Soup.Session.prototype.send_and_read_finish =
|
||||
function (message) {
|
||||
if (message.status_code !== Soup.KnownStatusCode.OK)
|
||||
return null;
|
||||
|
||||
return message.response_body.flatten().get_as_bytes();
|
||||
};
|
||||
}
|
||||
|
||||
function _makeEaseCallback(params, cleanup) {
|
||||
let onComplete = params.onComplete;
|
||||
delete params.onComplete;
|
||||
|
Loading…
Reference in New Issue
Block a user