Merge pull request #8 from swwilshub/claude/websocket-upload-GwiXb

Fix exit button responsiveness and progress bar accuracy
This commit is contained in:
swwilshub 2026-01-13 23:13:50 +00:00 committed by GitHub
commit 6dfc89b625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View File

@ -322,19 +322,24 @@ void CrossPointWebServerActivity::loop() {
constexpr int MAX_ITERATIONS = 500;
for (int i = 0; i < MAX_ITERATIONS && webServer->isRunning(); i++) {
webServer->handleClient();
// Reset watchdog every 32 iterations, yield every 64
// Tight loop with minimal yielding for maximum speed
// Reset watchdog every 32 iterations
if ((i & 0x1F) == 0x1F) {
esp_task_wdt_reset();
}
// Yield and check for exit button every 64 iterations
if ((i & 0x3F) == 0x3F) {
yield();
// Check for exit button inside loop for responsiveness
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
onGoBack();
return;
}
}
}
lastHandleClientTime = millis();
}
// Handle exit on Back button
// Handle exit on Back button (also check outside loop)
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
onGoBack();
return;

View File

@ -874,8 +874,12 @@ function uploadFileWebSocket(file, onProgress, onComplete, onError) {
ws.send(buffer);
offset += chunkSize;
// Update local progress
if (onProgress) onProgress(offset, totalSize);
// Update local progress - cap at 95% since server still needs to write
// Final 100% shown when server confirms DONE
if (onProgress) {
const cappedOffset = Math.min(offset, Math.floor(totalSize * 0.95));
onProgress(cappedOffset, totalSize);
}
}
sendingChunks = false;
@ -891,6 +895,8 @@ function uploadFileWebSocket(file, onProgress, onComplete, onError) {
// (local progress is smoother, server progress causes jumping)
console.log('[WS] Server progress:', msg);
} else if (msg === 'DONE') {
// Show 100% when server confirms completion
if (onProgress) onProgress(file.size, file.size);
ws.close();
if (onComplete) onComplete();
resolve();