Spaces:
Running
Running
fix progress bar
Browse files- wasm-demo.js +11 -10
wasm-demo.js
CHANGED
@@ -310,14 +310,9 @@ async function pollTaskStatus(currentTaskId, currentUid) {
|
|
310 |
userMessage = 'Processing your request...';
|
311 |
showComputing = true;
|
312 |
|
313 |
-
//
|
|
|
314 |
show('progressContainer', true);
|
315 |
-
if (!window.taskStartTime) {
|
316 |
-
window.taskStartTime = performance.now(); // Set start time when processing begins
|
317 |
-
}
|
318 |
-
if (!progressTimer) {
|
319 |
-
progressTimer = setInterval(updateProgressBar, 1000);
|
320 |
-
}
|
321 |
} else if (statusData.status === 'success' || statusData.status === 'completed') {
|
322 |
userMessage = 'Processing complete!';
|
323 |
// Set progress to 100% and clear timer
|
@@ -396,7 +391,7 @@ async function getTaskResult(currentTaskId, currentUid, taskName) {
|
|
396 |
encServerResult = new Uint8Array(resultArrayBuffer);
|
397 |
|
398 |
console.log(`[Main] Received encrypted result: ${encServerResult.length} bytes`);
|
399 |
-
const duration = ((performance.now() - window.taskStartTime) / 1000).toFixed(1);
|
400 |
$('srvStatus').textContent = `✓ Complete! (${duration}s)`;
|
401 |
enable('btnDecrypt');
|
402 |
|
@@ -428,11 +423,12 @@ $('btnSend').onclick = async () => {
|
|
428 |
show('encIcon', false);
|
429 |
show('spin', true);
|
430 |
show('processingNote', true);
|
431 |
-
show('progressContainer',
|
432 |
$('progressBar').style.width = '0%'; // Reset progress bar
|
433 |
$('srvStatus').textContent = 'Sending encrypted data...';
|
434 |
$('srvComputing').hidden = true; // Ensure it's hidden initially
|
435 |
window.expectedDuration = currentTokenCount * 30 * 1000; // Convert to milliseconds
|
|
|
436 |
|
437 |
// Clear any existing progress timer
|
438 |
if (progressTimer) {
|
@@ -464,6 +460,11 @@ $('btnSend').onclick = async () => {
|
|
464 |
console.log('[Main] Task submitted to server. Task ID:', taskId);
|
465 |
$('srvStatus').textContent = 'Request submitted. Checking status...';
|
466 |
|
|
|
|
|
|
|
|
|
|
|
467 |
pollTaskStatus(taskId, sessionUid).then(finalStatus => {
|
468 |
if (finalStatus && (finalStatus.status === 'success' || finalStatus.status === 'completed')) {
|
469 |
getTaskResult(taskId, sessionUid, 'synthid');
|
@@ -471,7 +472,7 @@ $('btnSend').onclick = async () => {
|
|
471 |
});
|
472 |
|
473 |
} catch (e) {
|
474 |
-
const duration = ((performance.now() - window.taskStartTime) / 1000).toFixed(2);
|
475 |
console.error(`[Main] Task submission failed after ${duration}s:`, e);
|
476 |
$('srvStatus').textContent = 'Failed to submit request. Please try again.';
|
477 |
show('spin', false);
|
|
|
310 |
userMessage = 'Processing your request...';
|
311 |
showComputing = true;
|
312 |
|
313 |
+
// Progress bar and timer are already started in btnSend.onclick
|
314 |
+
// Just ensure they're visible
|
315 |
show('progressContainer', true);
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
} else if (statusData.status === 'success' || statusData.status === 'completed') {
|
317 |
userMessage = 'Processing complete!';
|
318 |
// Set progress to 100% and clear timer
|
|
|
391 |
encServerResult = new Uint8Array(resultArrayBuffer);
|
392 |
|
393 |
console.log(`[Main] Received encrypted result: ${encServerResult.length} bytes`);
|
394 |
+
const duration = window.taskStartTime ? ((performance.now() - window.taskStartTime) / 1000).toFixed(1) : 'N/A';
|
395 |
$('srvStatus').textContent = `✓ Complete! (${duration}s)`;
|
396 |
enable('btnDecrypt');
|
397 |
|
|
|
423 |
show('encIcon', false);
|
424 |
show('spin', true);
|
425 |
show('processingNote', true);
|
426 |
+
show('progressContainer', true); // Always show progress bar
|
427 |
$('progressBar').style.width = '0%'; // Reset progress bar
|
428 |
$('srvStatus').textContent = 'Sending encrypted data...';
|
429 |
$('srvComputing').hidden = true; // Ensure it's hidden initially
|
430 |
window.expectedDuration = currentTokenCount * 30 * 1000; // Convert to milliseconds
|
431 |
+
window.taskStartTime = performance.now(); // Set start time when task is submitted
|
432 |
|
433 |
// Clear any existing progress timer
|
434 |
if (progressTimer) {
|
|
|
460 |
console.log('[Main] Task submitted to server. Task ID:', taskId);
|
461 |
$('srvStatus').textContent = 'Request submitted. Checking status...';
|
462 |
|
463 |
+
// Start progress bar timer immediately
|
464 |
+
if (!progressTimer) {
|
465 |
+
progressTimer = setInterval(updateProgressBar, 1000);
|
466 |
+
}
|
467 |
+
|
468 |
pollTaskStatus(taskId, sessionUid).then(finalStatus => {
|
469 |
if (finalStatus && (finalStatus.status === 'success' || finalStatus.status === 'completed')) {
|
470 |
getTaskResult(taskId, sessionUid, 'synthid');
|
|
|
472 |
});
|
473 |
|
474 |
} catch (e) {
|
475 |
+
const duration = window.taskStartTime ? ((performance.now() - window.taskStartTime) / 1000).toFixed(2) : 'N/A';
|
476 |
console.error(`[Main] Task submission failed after ${duration}s:`, e);
|
477 |
$('srvStatus').textContent = 'Failed to submit request. Please try again.';
|
478 |
show('spin', false);
|