Refactor forget function to use async/await

This commit is contained in:
buzzcode2007 2024-04-08 20:28:27 +08:00
parent 921dae135b
commit 6a5efb219d

View file

@ -305,28 +305,25 @@ export async function write(PATH, DATA, CLOUD = -1) {
@param {int} CLOUD the storage of the data @param {int} CLOUD the storage of the data
@return {boolean} the user's confirmation @return {boolean} the user's confirmation
*/ */
export function forget(preference, subpreference, CLOUD = 0) { export async function forget(preference, subpreference, CLOUD = 0) {
let forget_action = false;
(async () => {
// Import alerts module. // Import alerts module.
let alerts = (await import(chrome.runtime.getURL(`gui/scripts/alerts.js`)))[ let alerts = (await import(chrome.runtime.getURL(`gui/scripts/alerts.js`))).default;
`alerts`
];
// Confirm the action. // Confirm the action.
let forget_action = alerts.confirm_action(); let forget_action = await alerts.confirm();
if (forget_action) { if (forget_action) {
if (preference) { if (preference) {
if (subpreference) { if (subpreference) {
// Get the data. // Get the data.
data = read(preference, CLOUD); let DATA = await read(preference, CLOUD);
// Should only run when existent // Should only run when existent
if (data[subpreference]) { if (DATA[subpreference]) {
delete data[subpreference]; delete DATA[subpreference];
write([preference, subpreference], data, CLOUD); console.log(preference, DATA, CLOUD);
write(preference, DATA, CLOUD);
} }
} else { } else {
// Remove that particular data. // Remove that particular data.
@ -355,7 +352,6 @@ export function forget(preference, subpreference, CLOUD = 0) {
} }
} }
} }
})();
return forget_action; return forget_action;
} }