Gameboy: improve remounting

This commit is contained in:
Alex Gleason 2023-11-22 22:44:23 -06:00
parent 2e7b773bb5
commit f7c624483e
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -16,7 +16,9 @@ const Gameboy: React.FC<IGameboy> = ({ 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<IGameboy> = ({ src, onFocus, onBlur, ...rest }) => {
useEffect(() => {
init();
return () => {
WasmBoy.pause();
WasmBoy.disableDefaultJoypad();
};
}, []);
return (