]> git.wh0rd.org Git - chrome-ext/tabs-backup.git/commitdiff
change deleteOldestBackup to promise/async
authorMike Frysinger <vapier@gentoo.org>
Sun, 10 Dec 2023 04:10:20 +0000 (21:10 -0700)
committerMike Frysinger <vapier@gentoo.org>
Sun, 10 Dec 2023 04:10:20 +0000 (21:10 -0700)
background.js

index 4274daf0d9213a3c21924d6ecbf5db4242bd787a..894baa990544db82fabd3e91a27c50280756ca4a 100644 (file)
@@ -78,38 +78,23 @@ function backupNowManual (callbackDone) {
 
 }
 
-function deleteOldestBackup () {
-       chrome.storage.local.get(function(items) {
-               if(!items.backups_list) {
-                       return;
-               }
-
-               var backupsList = items.backups_list;
-               var numItemsToDelete = backupsList.length - items.prefs_max_backup_items;
-               if (numItemsToDelete > 0) {
-                       var i = 0;
-                       var loopFunc = function () {
-                               //
-                               if (i > 0) {
-                                       var deletedBackupName = backupsList[i-1];
-                                       chrome.runtime.sendMessage({
-                                               action: 'removeBackupItemDiv',
-                                               args: [deletedBackupName],
-                                       });
-                               }
-                               //
-
-                               if (i >= numItemsToDelete) {
-                                       return;
-                               }
+async function deleteOldestBackup() {
+       const items = await chrome.storage.local.get();
+       if (!items.backups_list) {
+               return;
+       }
 
-                               deleteBackup(backupsList[i]).then(loopFunc);
-                               i++;
-                       };
+       const backupsList = items.backups_list;
+       const numItemsToDelete = backupsList.length - items.prefs_max_backup_items;
+       for (let i = 0; i < numItemsToDelete; ++i) {
+               const deletedBackupName = backupsList[i];
+               await deleteBackup(deletedBackupName);
 
-                       loopFunc ();
-               }
-       });
+               chrome.runtime.sendMessage({
+                       action: 'removeBackupItemDiv',
+                       args: [deletedBackupName],
+               });
+       }
 }
 
 //var isCreatingBackup = false;