Skip to content

Commit

Permalink
jira@codeunifier/lib/jira.js: Add Soup 3 compatibility.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mtwebster committed May 19, 2023
1 parent 40cafc0 commit 1a4e833
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions jira@codeunifier/files/jira@codeunifier/lib/jira.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const Soup = imports.gi.Soup;

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() {};

Expand All @@ -19,16 +24,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);
}
});
});
}

};

0 comments on commit 1a4e833

Please sign in to comment.