From 9371a8064e09885738b3f574a1b08239aeee1695 Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Fri, 19 May 2023 11:02:01 -0400 Subject: [PATCH] jira@codeunifier/lib/jira.js: Add Soup 3 compatibility. Unable to test real authentication. To test with soup 3, edit /usr/share/cinnamon/js/ui/environment.js and change the soup version from 2.4 to 3.0. Save and restart cinnamon. @codeunifier --- .../files/jira@codeunifier/lib/jira.js | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/jira@codeunifier/files/jira@codeunifier/lib/jira.js b/jira@codeunifier/files/jira@codeunifier/lib/jira.js index ebf8f5300..7dfba8d9d 100644 --- a/jira@codeunifier/files/jira@codeunifier/lib/jira.js +++ b/jira@codeunifier/files/jira@codeunifier/lib/jira.js @@ -1,7 +1,13 @@ const Soup = imports.gi.Soup; +const ByteArray = imports.byteArray; -const _httpSession = new Soup.SessionAsync(); -Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault()); +var _httpSession; +if (Soup.MAJOR_VERSION === 2) { + _httpSession = new Soup.SessionAsync(); + Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault()); +} else { + _httpSession = new Soup.Session(); +} var JiraUtility = function() {}; @@ -19,16 +25,34 @@ JiraUtility.prototype.getAssigned = function (here, callback) { _httpSession.timeout = 10; _httpSession.idle_timeout = 10; - _httpSession.queue_message(message, function (session, message) { - if (message.status_code == 200) { - try { - callback.call(here, message.response_body.data.toString()); - } catch (e) { - global.logError(IDEN + ': ERROR | ' + e.message); - callback.call(here, null); + + if (Soup.MAJOR_VERSION === 2) { + _httpSession.queue_message(message, function (session, message) { + if (message.status_code == 200) { + try { + callback.call(here, message.response_body.data.toString()); + } catch (e) { + global.logError(IDEN + ': ERROR | ' + e.message); + callback.call(here, null); + } + } else { + global.logError(IDEN + ': BAD_API | ' + message.status_code); + } + }); + } else { + _httpSession.send_and_read_async(message, 0, null, (session, res) => { + if (message.get_status() === Soup.Status.OK) { + try { + const bytes = session.send_and_read_finish(res); + const data = ByteArray.toString(bytes.get_data()); + callback.call(here, data); + } catch (e) { + global.logError(IDEN + ': ERROR | ' + e.message); + } + } else { + global.logError(IDEN + ': BAD_API | ' + message.get_status()); } - } else { - global.logError(IDEN + ': BAD_API | ' + message.status_code); - } - }); + }); + } + }; \ No newline at end of file