diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-29 21:00:24 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-29 21:00:24 +1000 |
| commit | 0d7804f67723107f4e78beca8229d2fbb82ce4a3 (patch) | |
| tree | 6fc32ab28b0e8316030a826948a17eb23c4936de /services/Requests.qml | |
| parent | icons: add keyboard bluetooth device (diff) | |
| download | caelestia-shell-0d7804f67723107f4e78beca8229d2fbb82ce4a3.tar.gz caelestia-shell-0d7804f67723107f4e78beca8229d2fbb82ce4a3.tar.bz2 caelestia-shell-0d7804f67723107f4e78beca8229d2fbb82ce4a3.zip | |
weather: use xmlhttprequest
Remove curl dependency
Also add buffer period so it doesnt spam api requests
Diffstat (limited to 'services/Requests.qml')
| -rw-r--r-- | services/Requests.qml | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/services/Requests.qml b/services/Requests.qml new file mode 100644 index 0000000..36e9120 --- /dev/null +++ b/services/Requests.qml @@ -0,0 +1,36 @@ +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(); + } +} |