diff --git a/s3.js b/s3.js
index 4bc5f4c..8399863 100644
--- a/s3.js
+++ b/s3.js
@@ -1,5 +1,8 @@
let backupIntervalRunning = false;
let wasImportSuccessful = false;
+let isExportInProgress = false;
+let isImportInProgress = false;
+let isSnapshotInProgress = false;
const TIME_BACKUP_INTERVAL = 15;
const TIME_BACKUP_FILE_PREFIX = `T-${TIME_BACKUP_INTERVAL}`;
@@ -101,7 +104,6 @@ cloudSyncBtn.addEventListener('click', function () {
// New Popup
let lastBackupTime = 0;
-let isExportInProgress = false;
let backupInterval;
function openSyncModal() {
@@ -379,39 +381,74 @@ function openSyncModal() {
document
.getElementById('export-to-s3-btn')
.addEventListener('click', async function () {
+ if (isExportInProgress) return;
+ const exportBtn = document.getElementById('export-to-s3-btn');
+ exportBtn.disabled = true;
+ exportBtn.style.cursor = 'not-allowed';
+ exportBtn.textContent = 'Export in progress';
isExportInProgress = true;
- await backupToS3();
- isExportInProgress = false;
+
+ try {
+ await backupToS3();
+ } finally {
+ isExportInProgress = false;
+ exportBtn.disabled = false;
+ exportBtn.style.cursor = 'pointer';
+ exportBtn.innerHTML = 'Export to S3';
+ }
});
// Import button click handler
- document
- .getElementById('import-from-s3-btn')
- .addEventListener('click', async function () {
+document
+ .getElementById('import-from-s3-btn')
+ .addEventListener('click', async function () {
+ if (isImportInProgress) return;
+ const importBtn = document.getElementById('import-from-s3-btn');
+ importBtn.disabled = true;
+ importBtn.style.cursor = 'not-allowed';
+ importBtn.textContent = 'Importing...';
+ isImportInProgress = true;
+
+ try {
await importFromS3();
- wasImportSuccessful = true;
- });
+ } finally {
+ isImportInProgress = false;
+ importBtn.disabled = false;
+ importBtn.style.cursor = 'pointer';
+ importBtn.innerHTML = 'Import from S3';
+ }
+ });
// Snapshot button click handler
- // Inside openSyncModal function
document
.getElementById('snapshot-btn')
.addEventListener('click', async function () {
- const now = new Date();
- const timestamp =
- now.getFullYear() +
- String(now.getMonth() + 1).padStart(2, '0') +
- String(now.getDate()).padStart(2, '0') +
- 'T' +
- String(now.getHours()).padStart(2, '0') +
- String(now.getMinutes()).padStart(2, '0') +
- String(now.getSeconds()).padStart(2, '0');
-
- const bucketName = localStorage.getItem('aws-bucket');
- const data = await exportBackupData();
- const dataStr = JSON.stringify(data);
+ const snapshotBtn = document.getElementById('snapshot-btn');
+
+ // If button is disabled, return early
+ if (snapshotBtn.disabled) return;
+
+ // Disable button and update UI
+ snapshotBtn.disabled = true;
+ snapshotBtn.style.cursor = 'not-allowed';
+ const originalButtonContent = snapshotBtn.innerHTML;
+ snapshotBtn.innerHTML = 'Snapshot in progress';
try {
+ const now = new Date();
+ const timestamp =
+ now.getFullYear() +
+ String(now.getMonth() + 1).padStart(2, '0') +
+ String(now.getDate()).padStart(2, '0') +
+ 'T' +
+ String(now.getHours()).padStart(2, '0') +
+ String(now.getMinutes()).padStart(2, '0') +
+ String(now.getSeconds()).padStart(2, '0');
+
+ const bucketName = localStorage.getItem('aws-bucket');
+ const data = await exportBackupData();
+ const dataStr = JSON.stringify(data);
+
// Load JSZip
const jszip = await loadJSZip();
const zip = new jszip();
@@ -449,6 +486,10 @@ function openSyncModal() {
lastSyncElement.textContent = `Last sync done at ${lastSync}`;
}
}, 3000);
+
+ // Refresh the backup files list after successful snapshot
+ await loadBackupFiles();
+
} catch (error) {
const lastSyncElement = document.getElementById('last-sync-msg');
lastSyncElement.textContent = `Error creating snapshot: ${error.message}`;
@@ -460,6 +501,11 @@ function openSyncModal() {
lastSyncElement.textContent = `Last sync done at ${lastSync}`;
}
}, 3000);
+ } finally {
+ // Re-enable button and restore original content
+ snapshotBtn.disabled = false;
+ snapshotBtn.style.cursor = 'pointer';
+ snapshotBtn.innerHTML = originalButtonContent;
}
});
}