Add error alerts
This commit is contained in:
parent
3d63163ab9
commit
42d2278e6c
1 changed files with 61 additions and 27 deletions
|
@ -3,35 +3,69 @@ Alert management system.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default class alerts {
|
export default class alerts {
|
||||||
static confirm_action() {
|
static confirm_action() {
|
||||||
let user_response = false;
|
let user_response = false;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Import the module.
|
// Import the module.
|
||||||
let reader = (await import(chrome.runtime.getURL("gui/scripts/read.js")))[
|
let reader = (await import(chrome.runtime.getURL("gui/scripts/read.js")))[
|
||||||
`texts`
|
`texts`
|
||||||
];
|
];
|
||||||
|
|
||||||
// Get the user response.
|
// Get the user response.
|
||||||
user_response = confirm(
|
user_response = confirm(
|
||||||
reader.localized(`GUI_alert_confirm_action_text`),
|
reader.localized(`GUI_alert_confirm_action_text`),
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
// Return the user response.
|
// Return the user response.
|
||||||
return user_response;
|
return user_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static log(message) {
|
static log(message) {
|
||||||
console.log(message);
|
console.log(message);
|
||||||
try {
|
try {
|
||||||
M.toast({ text: message });
|
M.toast({ text: message });
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
static warn(message) {
|
/*
|
||||||
console.warn(message);
|
Raise a warning.
|
||||||
try {
|
|
||||||
M.toast({ text: message });
|
@param {boolean} message the message
|
||||||
} catch (err) {}
|
@param {boolean} critical the critical nature
|
||||||
}
|
*/
|
||||||
|
static warn(message, critical = false) {
|
||||||
|
console.warn(message);
|
||||||
|
if (critical) {
|
||||||
|
alert(message);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
M.toast({ text: message });
|
||||||
|
} catch (err) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Raise an error message.
|
||||||
|
|
||||||
|
@param {number} ERROR_CODE the error code
|
||||||
|
@param {number} ERROR_MESSAGE the custom error message
|
||||||
|
@param {boolean} critical the critical nature
|
||||||
|
*/
|
||||||
|
static error(ERROR_CODE, ERROR_MESSAGE, critical = true) {
|
||||||
|
(async () => {
|
||||||
|
// Import the templating.
|
||||||
|
const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js"))).default;
|
||||||
|
|
||||||
|
// Display the error message.
|
||||||
|
console.error(texts.localized(`error_msg`, null, [ERROR_CODE, ERROR_MESSAGE]));
|
||||||
|
if (critical) {
|
||||||
|
alert(texts.localized(`error_msg_GUI`, null, [String(ERROR_CODE)]));
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
M.toast({ text: message });
|
||||||
|
} catch (err) {}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue