init: working version
This commit is contained in:
commit
7d8d7dacae
109 changed files with 15066 additions and 0 deletions
36
services/Requests.qml
Normal file
36
services/Requests.qml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
pragma Singleton
|
||||
|
||||
import qs.config
|
||||
import qs.util
|
||||
import Quickshell
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
function get(url: string, callback: var): void {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
const cleanup = () => {
|
||||
xhr.abort();
|
||||
xhr.onreadystatechange = null;
|
||||
xhr.onerror = null;
|
||||
};
|
||||
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
if (xhr.status === 200)
|
||||
callback(xhr.responseText);
|
||||
else
|
||||
console.warn(`[REQUESTS] GET request to ${url} failed with status ${xhr.status}`);
|
||||
cleanup();
|
||||
}
|
||||
};
|
||||
xhr.onerror = () => {
|
||||
console.warn(`[REQUESTS] GET request to ${url} failed`);
|
||||
cleanup();
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue