From 71208cf4b9376f92e2022f05f3b8566335e5fc19 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 9 Dec 2023 21:10:20 -0700 Subject: [PATCH] change deleteOldestBackup to promise/async --- background.js | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) 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; -- 2.39.5