From b387c5a79ac36dff6137e9dd2712a17c887ededb Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 7 Nov 2026 11:55:18 +0100 Subject: sonix: service fixes from review Co-Authored-By: Claude Sonnet 5.5 --- desktop/Sonix.qml | 21 +++++++++++++++------ 1 file 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; -- cgit v1.2.3