Merge remote-tracking branch 'refs/remotes/origin/development-storage' into development-GUI

This commit is contained in:
buzz-lightsnack-2007 2024-05-06 09:52:53 +08:00
commit 3fe8f632e4
3 changed files with 15 additions and 13 deletions

View file

@ -53,15 +53,15 @@ export default class filters {
@param {string} URL the URL to update @param {string} URL the URL to update
@return {boolean} the state @return {boolean} the state
*/ */
async update(URL) { async update(location) {
// Create a queue of the filters. // Create a queue of the filters.
let filters = new Queue(); let filters = new Queue();
if (URL) { if (location) {
// Check if the URL is in a valid protocol // Check if the URL is in a valid protocol
if (URL.includes(`://`)) { if (location.includes(`://`)) {
// Append that to the queue. // Append that to the queue.
filters.enqueue(URL); filters.enqueue(new URL(location));
} }
} else { } else {
// Add every item to the queue based on what was loaded first. // Add every item to the queue based on what was loaded first.
@ -81,7 +81,7 @@ export default class filters {
let filter_URL = filters.dequeue(); let filter_URL = filters.dequeue();
// Inform the user of download state. // Inform the user of download state.
new logging (texts.localized(`settings_filters_update_status`, null, [filter_URL])); new logging (texts.localized(`settings_filters_update_status`), filter_URL);
// Create promise of downloading. // Create promise of downloading.
let filter_download = net.download(filter_URL, `JSON`, false, true); let filter_download = net.download(filter_URL, `JSON`, false, true);
@ -91,15 +91,17 @@ export default class filters {
if (result) { if (result) {
// Write the filter to storage. // Write the filter to storage.
await global.write(["filters", filter_URL], result, -1, {"silent": true}); await global.write(["filters", filter_URL], result, -1, {"silent": true});
new logging(texts.localized(`settings_filters_update_status_complete`,null,[filter_URL]));
// Add the filter to the sync list. // Add the filter to the sync list.
if ((await global.read(["settings", `filters`])) ? !((Object.keys(await global.read(["settings", `filters`]))).includes(filter_URL)) : true) { if ((await global.read(["settings", `filters`])) ? !((Object.keys(await global.read(["settings", `filters`]))).includes(filter_URL)) : true) {
global.write(["settings", `filters`, filter_URL], true, 1, {"silent": true}); global.write(["settings", `filters`, filter_URL], true, 1, {"silent": true});
} };
// Notify that the update is completed.
new logging(texts.localized(`settings_filters_update_status_complete`),filter_URL);
} }
}) })
.catch(async function(error) { .catch((error) => {
// Inform the user of the download failure. // Inform the user of the download failure.
logging.error(error.name, texts.localized(`settings_filters_update_status_failure`, null, [error.name, filter_URL]), error.stack); logging.error(error.name, texts.localized(`settings_filters_update_status_failure`, null, [error.name, filter_URL]), error.stack);
}); });

View file

@ -72,7 +72,7 @@ export default class logging {
*/ */
static async error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) { static async error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) {
// Display the error message. // Display the error message.
console.error('%c%s%c%s%c%s%c\n%s%c', `font-weight: bold;`, ERROR_CODE, ``, `:`, ``, ERROR_MESSAGE, `font-family: monospace;`, ERROR_STACK, ``); console.error('%c%s%c%s%c%s%c\n%s%c', `font-weight: bold;`, ERROR_CODE, ``, `: `, ``, ERROR_MESSAGE, `font-family: monospace;`, ERROR_STACK, ``);
try { try {
(critical) ? alert(texts.localized(`error_msg_GUI`, false, [String(ERROR_CODE), ERROR_MESSAGE])) : M.toast({ text: ERROR_MESSAGE }); (critical) ? alert(texts.localized(`error_msg_GUI`, false, [String(ERROR_CODE), ERROR_MESSAGE])) : M.toast({ text: ERROR_MESSAGE });

View file

@ -167,7 +167,7 @@ class global {
DATA_CHECK[`state`] = await compare([...NAME], DATA); DATA_CHECK[`state`] = await compare([...NAME], DATA);
(!DATA_CHECK[`state`]) (!DATA_CHECK[`state`])
? logging.error((new texts(`error_msg_save_failed`)).localized, NAME.join(``), JSON.stringify(DATA)) ? logging.error((new texts(`error_msg_save_failed`)).localized, NAME.join(``), JSON.stringify(DATA))
: ((((typeof OPTIONS).includes(`obj`) && OPTIONS != null) ? (!(!!OPTIONS[`silent`])) : true) : ((((typeof OPTIONS).includes(`obj`) && OPTIONS != null) ? (!(!!OPTIONS[`silent`])) : true)
? new logging (new texts(`saving_done`).localized) ? new logging (new texts(`saving_done`).localized)
: false); : false);
@ -203,7 +203,7 @@ class global {
// Write! // Write!
chrome.storage[(CLOUD > 0) ? `sync` : `local`].set(DATA_INJECTED); chrome.storage[(CLOUD > 0) ? `sync` : `local`].set(DATA_INJECTED);
return (verify(DATA_NAME, data)); return ((OPTIONS[`verify`] != null ? (OPTIONS[`verify`]) : true) ? verify(DATA_NAME, data) : true);
} }
/* /*
@ -239,7 +239,7 @@ class global {
return(global.read([...PATH], cloud).then(async (DATA) => { return(global.read([...PATH], cloud).then(async (DATA) => {
return((DATA != null) return((DATA != null)
// Then erase the data. // Then erase the data.
? await global.write(PATH, null, cloud, {"strict": true}) ? await global.write(PATH, null, cloud, {"strict": true, "verify": false})
: true); : true);
})); }));
}; };