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

44 lines
1 KiB
JavaScript
Raw Normal View History

2021-10-03 21:51:06 +03:00
import { appRouter } from './appRouter';
2020-08-14 08:46:34 +02:00
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
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;
if (typeof text === 'string') {
options = {
title: title,
text: text
};
} else {
options = text;
}
2023-04-19 01:56:05 -04:00
await appRouter.ready();
2023-04-19 01:56:05 -04:00
if (useNativeAlert()) {
alert((options.text || '').replaceAll('<br/>', '\n'));
return Promise.resolve();
} else {
const items = [];
2023-04-19 01:56:05 -04:00
items.push({
name: globalize.translate('ButtonGotIt'),
id: 'ok',
type: 'submit'
});
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
}