Refactor alert module

This commit is contained in:
Yasin Silavi 2023-07-26 10:28:14 +03:30 committed by Bill Thornton
parent 24fad10f36
commit 0a878bfbcd

View file

@ -3,43 +3,34 @@ import browser from "../scripts/browser";
import dialog from "./dialog/dialog";
import globalize from "../scripts/globalize";
function useNativeAlert() {
// webOS seems to block modals
// Tizen 2.x seems to block modals
return (
export default async function (text, title) {
// Modals seem to be blocked on Web OS and Tizen 2.x
const canUseNativeAlert = !!(
!browser.web0s &&
!(browser.tizenVersion && browser.tizenVersion < 3) &&
browser.tv &&
window.alert
);
}
export default async function (text, title) {
let options;
if (typeof text === "string") {
options = {
title: title,
text: text,
};
} else {
options = text;
}
let options = typeof text === "string" ? { title, text } : text;
await appRouter.ready();
if (useNativeAlert()) {
if (canUseNativeAlert) {
alert((options.text || "").replaceAll("<br/>", "\n"));
return Promise.resolve();
} else {
const items = [];
items.push({
return Promise.resolve();
}
const items = [
{
name: globalize.translate("ButtonGotIt"),
id: "ok",
type: "submit",
});
},
];
options.buttons = items;
return dialog.show(options);
}
options.buttons = items;
return dialog.show(options);
}