From: Mike Frysinger Date: Sun, 10 Dec 2023 04:10:20 +0000 (-0700) Subject: change deleteOldestBackup to promise/async X-Git-Tag: v1.0~1 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=71208cf4b9376f92e2022f05f3b8566335e5fc19;p=chrome-ext%2Ftabs-backup.git change deleteOldestBackup to promise/async --- diff --git a/background.js b/background.js index 4274daf..894baa9 100644 --- a/background.js +++ b/background.js @@ -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;