mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
fix: prevent typerror on fullscreen request (#461)
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
||||||
<meta name='theme-color' content='#121212' />
|
<meta name='theme-color' content='#121212' />
|
||||||
<meta name='ontime' content='ontime - event timer manager' />
|
<meta name='ontime' content='ontime - event timer manager' />
|
||||||
<meta http-equiv="Content-Security-Policy" content="fullscreen 'self';">
|
|
||||||
<link rel='apple-touch-icon' href='/logo192.png' />
|
<link rel='apple-touch-icon' href='/logo192.png' />
|
||||||
<link
|
<link
|
||||||
rel='icon'
|
rel='icon'
|
||||||
|
|||||||
@@ -34,24 +34,30 @@ export default function useFullscreen() {
|
|||||||
const toggleFullScreen = useCallback(() => {
|
const toggleFullScreen = useCallback(() => {
|
||||||
if (!document.fullscreenElement && !(document as WebkitDocument).webkitIsFullScreen) {
|
if (!document.fullscreenElement && !(document as WebkitDocument).webkitIsFullScreen) {
|
||||||
// Fullscreen mode is not active, so we can enter fullscreen mode
|
// Fullscreen mode is not active, so we can enter fullscreen mode
|
||||||
if (document.documentElement.requestFullscreen) {
|
const element = document.documentElement;
|
||||||
|
if (element.requestFullscreen) {
|
||||||
// Standard fullscreen API is supported
|
// Standard fullscreen API is supported
|
||||||
document.documentElement.requestFullscreen();
|
element.requestFullscreen().catch(() => {
|
||||||
// @ts-expect-error -- the whole casting dance is not worth it
|
/* nothing to do */
|
||||||
} else if (document.documentElement.webkitRequestFullscreen) {
|
});
|
||||||
|
} else if (element.webkitRequestFullscreen) {
|
||||||
// iOS Safari fullscreen API is supported
|
// iOS Safari fullscreen API is supported
|
||||||
// @ts-expect-error -- we know this is not undefined now
|
element.webkitRequestFullscreen().catch(() => {
|
||||||
(document.documentElement as WebkitDocument).webkitRequestFullscreen();
|
/* nothing to do */
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fullscreen mode is active, so we can exit fullscreen mode
|
// Fullscreen mode is active, so we can exit fullscreen mode
|
||||||
if (document.exitFullscreen) {
|
if (document.exitFullscreen) {
|
||||||
// Standard fullscreen API is supported
|
// Standard fullscreen API is supported
|
||||||
document.exitFullscreen();
|
document.exitFullscreen().catch((error) => {
|
||||||
|
console.error('Error while trying to exit fullscreen:', error);
|
||||||
|
});
|
||||||
} else if ((document as WebkitDocument).webkitExitFullscreen) {
|
} else if ((document as WebkitDocument).webkitExitFullscreen) {
|
||||||
// iOS Safari fullscreen API is supported
|
// iOS Safari fullscreen API is supported
|
||||||
// @ts-expect-error -- we know this is not undefined now
|
(document as WebkitDocument).webkitExitFullscreen().catch(() => {
|
||||||
(document as WebkitDocument).webkitExitFullscreen();
|
/* nothing to do */
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user