diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-07 11:55:18 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-07 11:55:18 +0100 |
| commit | b387c5a79ac36dff6137e9dd2712a17c887ededb (patch) | |
| tree | 36ce42002ceebc4d0826a538e173e3e920eecfcf /desktop | |
| parent | 9559ad71d6f66ccfb681deace80cd17d0029def1 (diff) | |
| download | quickshell-b387c5a79ac36dff6137e9dd2712a17c887ededb.tar.gz quickshell-b387c5a79ac36dff6137e9dd2712a17c887ededb.zip | |
sonix: service fixes from review
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop')
| -rw-r--r-- | desktop/Sonix.qml | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/desktop/Sonix.qml b/desktop/Sonix.qml index f3e0de5..d279dc6 100644 --- a/desktop/Sonix.qml +++ b/desktop/Sonix.qml @@ -38,10 +38,9 @@ Singleton { property int holds: 0 function hold() { root.holds++; } function release() { - root.holds = Math.max(0, root.holds - 1); // The player counts a client as present for 20s after its last // request; saying goodbye ends that at once. - if (root.holds === 0) root.request("GET", "/api/bye", null, () => {}); + if (root.holds > 0 && --root.holds === 0) root.request("GET", "/api/bye", null, () => {}); } Process { @@ -94,7 +93,7 @@ Singleton { t.destroy(); cb(ok, data, err); }; - t.triggered.connect(() => { xhr.abort(); finish(false, null, "timed out"); }); + t.triggered.connect(() => { finish(false, null, "timed out"); xhr.abort(); }); xhr.onreadystatechange = () => { if (xhr.readyState !== XMLHttpRequest.DONE) return; if (xhr.status === 200) { @@ -125,19 +124,29 @@ Singleton { h=$1 f=$2 d=$3 curl -s -m 3 -o /dev/null "http://$h/" || exit 3 curl -s -m 10 -o /dev/null --data-urlencode "path=$d" "http://$h/create" - code=$(curl -s -m 120 -o /dev/null -w '%{http_code}' -F "path=$d/" -F "files[]=@$f" "http://$h/upload") \ + code=$(curl -s -m 120 -o /dev/null -w '%{http_code}' --form-string "path=$d/" -F "files[]=@\"$f\"" "http://$h/upload") \ || { echo "curl failed"; exit 1; } [ "$code" = 200 ] || { echo "HTTP $code"; exit 1; } ` Process { id: up property var cb: null - stdout: StdioCollector { id: upOut } - onExited: code => { const cb = up.cb; up.cb = null; if (cb) cb(code, upOut.text.trim()); } + property int code: -1 + property bool streamed: false + stdout: StdioCollector { id: upOut; onStreamFinished: { up.streamed = true; up.deliver(); } } + onExited: code => { up.code = code; up.deliver(); } + function deliver() { + if (up.code < 0 || !up.streamed || !up.cb) return; + const cb = up.cb; + up.cb = null; + cb(up.code, upOut.text.trim()); + } } function upload(file, cardDir, cb) { if (up.running) { cb(1, "an upload is already running"); return; } up.cb = cb; + up.code = -1; + up.streamed = false; up.command = ["sh", "-c", root.uploadScript, "sh", root.host, file, cardDir]; up.running = false; up.running = true; |
