Spaces:
Paused
Paused
Esmaill1 commited on
Commit ·
5007a04
1
Parent(s): 680424a
feat: Add process cancellation (Stop button) and data loss warning on page refresh
Browse files- app/static/app.js +11 -0
app/static/app.js
CHANGED
|
@@ -67,6 +67,17 @@ function initApp() {
|
|
| 67 |
|
| 68 |
let isProcessingCanceled = false; // Cancellation flag
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
// Stop Button Listener
|
| 71 |
stopBtn.addEventListener('click', () => {
|
| 72 |
isProcessingCanceled = true;
|
|
|
|
| 67 |
|
| 68 |
let isProcessingCanceled = false; // Cancellation flag
|
| 69 |
|
| 70 |
+
// Warn on refresh/leave while processing
|
| 71 |
+
window.addEventListener('beforeunload', (e) => {
|
| 72 |
+
// If the loading container is visible, it means processing is active
|
| 73 |
+
if (loadingContainer.style.display !== 'none' && !isProcessingCanceled) {
|
| 74 |
+
e.preventDefault();
|
| 75 |
+
// Note: Modern browsers (Chrome/Firefox) often ignore this custom text and show a standard message,
|
| 76 |
+
// but older browsers might display it.
|
| 77 |
+
e.returnValue = 'هناك صور قيد المعالجة. إذا قمت بالتحديث الآن، فسوف تفقد تقدمك.';
|
| 78 |
+
}
|
| 79 |
+
});
|
| 80 |
+
|
| 81 |
// Stop Button Listener
|
| 82 |
stopBtn.addEventListener('click', () => {
|
| 83 |
isProcessingCanceled = true;
|