mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 23:57:39 +03:00
Fix exit button responsiveness and progress bar accuracy
Exit button: - Check for Back button inside handleClient loop (every 64 iterations) - Makes exit much more responsive during uploads Progress bar: - Cap local progress at 95% while sending chunks - Show 100% only when server confirms DONE - Prevents progress sitting at 100% while server still writing
This commit is contained in:
parent
2d5b112eee
commit
c796487758
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user