make filters async

since most of its content is async anyway
This commit is contained in:
buzzcode2007 2024-04-02 16:36:24 +08:00
parent 532295a610
commit b5c0f7ac68

View file

@ -10,7 +10,9 @@ export default class filters {
chrome.runtime.getURL("scripts/secretariat.js")
);
return ((await Promise.all([secretariat.read([`filters`], -1)]))[0])
return(secretariat.read(`filters`, -1).then((filters) => {
return(filters)
}));
})
}
@ -18,7 +20,7 @@ export default class filters {
@param {string} URL the current URL
*/
static async select(URL = window.location.href) {
async select(URL = window.location.href) {
this.one = await (async () => {
// Import the secretariat.
const secretariat = await import(
@ -40,8 +42,7 @@ export default class filters {
@param {string} URL the URL to update
@return {boolean} the state
*/
static update(URL) {
this.all = (async () => {
async update(URL) {
// Import the updater.
const secretariat = await import(
chrome.runtime.getURL("scripts/secretariat.js")
@ -113,7 +114,7 @@ export default class filters {
if (result) {
// Write the filter to storage.
secretariat.write(["filters", filter_URL], result, -1);
console.log(
alerts.log(
texts.localized(
`settings_filters_update_status_complete`,
null,
@ -125,7 +126,7 @@ export default class filters {
})
.catch((error) => {
// Inform the user of the download failure.
console.log(
alerts.error(
texts.localized(
`settings_filters_update_status_failure`,
null,
@ -140,9 +141,8 @@ export default class filters {
}
// Regardless of the download result, update will also mean setting the filters object to whatever is in storage.
return(secretariat.read(`filters`, -1).then((filters) => {
return(filters)
}));
})();
this.all = (await secretariat.read(`filters`, -1));
return(this.all);
}
}