Skip to content
Snippets Groups Projects
Verified Commit 4fa701c7 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

refactor: better fullscreen handling

parent cde614f3
No related branches found
No related tags found
No related merge requests found
...@@ -326,6 +326,11 @@ export const App: FC<AppProps> = ({ ...@@ -326,6 +326,11 @@ export const App: FC<AppProps> = ({
} }
}, [keyaction]); }, [keyaction]);
useEffect(() => { useEffect(() => {
const onFullChange = (event: Event) => {
if (!document.fullscreenElement) {
setFullscreenState(false);
}
};
const onKeyDown = (event: KeyboardEvent) => { const onKeyDown = (event: KeyboardEvent) => {
switch (event.key) { switch (event.key) {
case "+": case "+":
...@@ -360,10 +365,12 @@ export const App: FC<AppProps> = ({ ...@@ -360,10 +365,12 @@ export const App: FC<AppProps> = ({
) => { ) => {
showToast(params.text, params.error, params.timeout); showToast(params.text, params.error, params.timeout);
}; };
document.addEventListener("fullscreenchange", onFullChange);
document.addEventListener("keydown", onKeyDown); document.addEventListener("keydown", onKeyDown);
emulator.bind("booted", onBooted); emulator.bind("booted", onBooted);
emulator.bind("message", onMessage); emulator.bind("message", onMessage);
return () => { return () => {
document.removeEventListener("fullscreenchange", onFullChange);
document.removeEventListener("keydown", onKeyDown); document.removeEventListener("keydown", onKeyDown);
emulator.unbind("booted", onBooted); emulator.unbind("booted", onBooted);
emulator.unbind("message", onMessage); emulator.unbind("message", onMessage);
......
...@@ -97,7 +97,8 @@ export const Display: FC<DisplayProps> = ({ ...@@ -97,7 +97,8 @@ export const Display: FC<DisplayProps> = ({
// requests the browser to go fullscreen using the // requests the browser to go fullscreen using the
// body of the document as the entry HTML element // body of the document as the entry HTML element
nativeFullscreen && document.body?.requestFullscreen(); nativeFullscreen &&
document.body?.requestFullscreen().catch(() => {});
} else { } else {
setWidth(undefined); setWidth(undefined);
setHeight(undefined); setHeight(undefined);
...@@ -108,7 +109,7 @@ export const Display: FC<DisplayProps> = ({ ...@@ -108,7 +109,7 @@ export const Display: FC<DisplayProps> = ({
// restores the window mode, returning from the // restores the window mode, returning from the
// fullscreen browser // fullscreen browser
nativeFullscreen && document?.exitFullscreen(); nativeFullscreen && document?.exitFullscreen().catch(() => {});
} }
return () => { return () => {
window.removeEventListener("resize", resizeRef.current); window.removeEventListener("resize", resizeRef.current);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment