1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/alert.js

46 lines
1 KiB
JavaScript
Raw Normal View History

2023-07-26 10:27:40 +03:30
import { appRouter } from "./router/appRouter";
import browser from "../scripts/browser";
import dialog from "./dialog/dialog";
import globalize from "../scripts/globalize";
2020-07-15 14:46:56 +01:00
2023-04-19 01:56:05 -04:00
function useNativeAlert() {
// webOS seems to block modals
// Tizen 2.x seems to block modals
2023-07-26 10:27:40 +03:30
return (
!browser.web0s &&
!(browser.tizenVersion && browser.tizenVersion < 3) &&
browser.tv &&
window.alert
);
2023-04-19 01:56:05 -04:00
}
export default async function (text, title) {
let options;
2023-07-26 10:27:40 +03:30
if (typeof text === "string") {
2023-04-19 01:56:05 -04:00
options = {
title: title,
2023-07-26 10:27:40 +03:30
text: text,
2023-04-19 01:56:05 -04:00
};
} else {
options = text;
}
2023-04-19 01:56:05 -04:00
await appRouter.ready();
2023-04-19 01:56:05 -04:00
if (useNativeAlert()) {
2023-07-26 10:27:40 +03:30
alert((options.text || "").replaceAll("<br/>", "\n"));
2023-04-19 01:56:05 -04:00
return Promise.resolve();
} else {
const items = [];
2023-04-19 01:56:05 -04:00
items.push({
2023-07-26 10:27:40 +03:30
name: globalize.translate("ButtonGotIt"),
id: "ok",
type: "submit",
2023-04-19 01:56:05 -04:00
});
2023-04-19 01:56:05 -04:00
options.buttons = items;
return dialog.show(options);
2020-07-15 14:46:56 +01:00
}
2023-04-19 01:56:05 -04:00
}