nosignal-shell/services/Requests.qml
2 * r + 2 * t 0d7804f677 weather: use xmlhttprequest
Remove curl dependency

Also add buffer period so it doesnt spam api requests
2025-06-29 21:00:24 +10:00

36 lines
907 B
QML

pragma Singleton
import "root:/config"
import "root:/utils"
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();
}
}