]> git.wh0rd.org Git - chrome-ext/tabs-backup.git/commitdiff
change deleteBackup to promise/async
authorMike Frysinger <vapier@gentoo.org>
Sun, 10 Dec 2023 03:32:07 +0000 (20:32 -0700)
committerMike Frysinger <vapier@gentoo.org>
Sun, 10 Dec 2023 03:42:25 +0000 (20:42 -0700)
advanced.js
background.js

index 62f332c623f829d5e1607cc95fc0ae4a8007549a..91e4843693169a8ce6a407aa4b07b03744107a71 100644 (file)
@@ -297,29 +297,6 @@ function insertBackupItem (backupName, backupObj, insertAtBeginning, doAnimation
        //      };
        //})(backupName);
 
-       //var deleteFuncHandler = (function(backupName, elem) {
-       //      return function(event) {
-                       /*if (!confirm("Delete backup '" + backupName + "'?")) {
-                               return;
-                       }*/
-
-       //              bootbox.confirm("Delete backup '" + backupName + "'?", function(confirmed) {
-       //                      if (confirmed) {
-       //                              chrome.extension.getBackgroundPage().deleteBackup(backupName, function() {
-
-       //                              });
-
-                                       //if (elem.parentNode) {
-                                       //  elem.parentNode.removeChild(elem);
-                                       //
-       //                              removeBackupItemDiv (backupName);
-       //                      }
-       //              });
-
-
-       //      };
-       //})(backupName, elem);
-
        if (insertAtBeginning && backupsDiv.childNodes.length > 0) {
                // some items already exist
                var firstNode = backupsDiv.childNodes[0];
index da06677b5679cb582fb2c23c59d1565b4b1facbd..0add75bb216c07b4f09f6510c0ac13c940a69e0a 100644 (file)
@@ -122,20 +122,12 @@ function deleteOldestBackup () {
                                        return;
                                }
 
-                               deleteBackup (backupsList[i], loopFunc);
+                               deleteBackup(backupsList[i]).then(loopFunc);
                                i++;
                        };
 
                        loopFunc ();
                }
-
-               //for (var i = 0; i < numItemsToDelete; i++) {
-               // TODO WARNING: I'm calling deleteBackup rapidly, while deleting is async...(I should wait for each delete to complete before deleting the next)
-                       //deleteBackup (backupsList[i], function() {
-
-                       //});
-               //}
-
        });
 }
 
@@ -293,44 +285,30 @@ function updateBrowserActionIcon (status) {
        chrome.action.setIcon({path: icon});
 }
 
-function deleteBackup (backupName, callback) {
+async function deleteBackup(backupName) {
        console.log("Deleting backup " + backupName);
 
-       chrome.storage.local.remove(backupName, function() {
-               //console.log ("=> Deleted backup " + backupName);
-
-               chrome.storage.local.get("backups_list", function(items) {
-                       //console.log ("==> got backups_list " + backupName);
-
-                       if(!items.backups_list) {
-                               callback();
-                               return;
-                       }
-
-                       var backupsList = items.backups_list;
-
-                       var index = backupsList.indexOf(backupName);
-                       if (index >= 0) {
-                               backupsList.splice(index, 1);
-                       }
+       await chrome.storage.local.remove(backupName);
+       //console.log("=> Deleted backup " + backupName);
 
-                       //console.log ("===> Updating backups_list (removing " + backupName + ")");
+       const items = await chrome.storage.local.get("backups_list");
+       //console.log("==> got backups_list " + backupName);
 
-                       chrome.storage.local.set({"backups_list": backupsList}, function() {
-                               //console.log ("===> Updated backups_list (removed " + backupName + ")");
-
-                               callback();
-                       });
-
-                       //console.log ("==> EXIT got backups_list " + backupName);
-               });
+       if (!items.backups_list) {
+               return;
+       }
 
-               //console.log ("=> EXIT Deleted backup " + backupName);
-       });
+       var backupsList = items.backups_list;
 
-       //console.log("EXIT Deleting backup " + backupName);
+       var index = backupsList.indexOf(backupName);
+       if (index >= 0) {
+               backupsList.splice(index, 1);
+       }
 
+       //console.log("===> Updating backups_list (removing " + backupName + ")");
 
+       await chrome.storage.local.set({"backups_list": backupsList});
+       //console.log("===> Updated backups_list (removed " + backupName + ")");
 }
 
 function restoreNow(backupName) {
@@ -440,7 +418,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
                        break;
 
                case 'deleteBackup':
-                       deleteBackup(...request.argssendResponse);
+                       deleteBackup(...request.args).then(sendResponse);
                        asyncResponse = true;
                        break;