From f7c624483ec2e034055c33f8fad04453f9234568 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 22 Nov 2023 22:44:23 -0600 Subject: [PATCH] Gameboy: improve remounting --- src/components/gameboy.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/gameboy.tsx b/src/components/gameboy.tsx index c3a67b3d4..7c9773fc5 100644 --- a/src/components/gameboy.tsx +++ b/src/components/gameboy.tsx @@ -16,7 +16,9 @@ const Gameboy: React.FC = ({ src, onFocus, onBlur, ...rest }) => { await WasmBoy.loadROM(src); await WasmBoy.play(); - if (document.activeElement !== canvas.current) { + if (document.activeElement === canvas.current) { + await WasmBoy.enableDefaultJoypad(); + } else { await WasmBoy.disableDefaultJoypad(); } } @@ -31,6 +33,11 @@ const Gameboy: React.FC = ({ src, onFocus, onBlur, ...rest }) => { useEffect(() => { init(); + + return () => { + WasmBoy.pause(); + WasmBoy.disableDefaultJoypad(); + }; }, []); return (