-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ const PopupMenu = imports.ui.popupMenu; | |
const St = imports.gi.St; | ||
const Gtk = imports.gi.Gtk; | ||
const Soup = imports.gi.Soup; | ||
const ByteArray = imports.byteArray; | ||
|
||
const GLib = imports.gi.GLib; | ||
const Gio = imports.gi.Gio; | ||
|
@@ -13,8 +14,13 @@ const UUID = '[email protected]'; | |
const QUtils = require('./js/QUtils.js'); | ||
const QPopupSwitch = QUtils.QPopupSwitch; | ||
|
||
const soupASyncSession = new Soup.SessionAsync(); | ||
Soup.Session.prototype.add_feature.call(soupASyncSession, new Soup.ProxyResolverDefault()); | ||
let soupASyncSession; | ||
if (Soup.MAJOR_VERSION == 2) { | ||
soupASyncSession = new Soup.SessionAsync(); | ||
Soup.Session.prototype.add_feature.call(soupASyncSession, new Soup.ProxyResolverDefault()); | ||
} else if (Soup.MAJOR_VERSION == 3) { | ||
soupASyncSession = new Soup.Session(); | ||
} | ||
|
||
function MyApplet(orientation, panelHeight, instanceId) { | ||
this._init(orientation, panelHeight, instanceId); | ||
|
@@ -79,18 +85,34 @@ MyApplet.prototype = { | |
|
||
getVerse: function (testament, callback) { | ||
let request = Soup.Message.new('GET', "https://devotionalium.com/api/v2?lang=en"); | ||
soupASyncSession.queue_message(request, function(soupASyncSession, message) { | ||
if (message.status_code !== 200) { | ||
var return_message = "Connection error."; | ||
callback(return_message); | ||
return; | ||
} | ||
|
||
var responseParsed = JSON.parse(request.response_body.data); | ||
var verse = responseParsed[testament].text; | ||
|
||
callback(verse); | ||
}); | ||
if (Soup.MAJOR_VERSION === 2) { | ||
soupASyncSession.queue_message(request, (soupASyncSession, response) => { | ||
if (response.status_code !== 200) { | ||
var return_message = "Connection error."; | ||
callback(return_message); | ||
return; | ||
} | ||
|
||
var responseParsed = JSON.parse(response.response_body.data); | ||
var verse = responseParsed[testament].text; | ||
|
||
callback(verse); | ||
}); | ||
} else { //version 3 | ||
soupASyncSession.send_and_read_async(request, Soup.MessagePriority.NORMAL, null, (soupASyncSession, response) => { | ||
if (request.get_status() !== 200) { | ||
var return_message = "Connection error."; | ||
callback(return_message); | ||
return; | ||
} | ||
|
||
const bytes = soupASyncSession.send_and_read_finish(response); | ||
var responseParsed = JSON.parse(ByteArray.toString(bytes.get_data())); | ||
var verse = responseParsed[testament].text; | ||
|
||
callback(verse); | ||
}); | ||
} | ||
}, | ||
|
||
displayVerse: function(verseReturned) { | ||
|