Skip to content

Commit

Permalink
refactor: bind audio resume to resume
Browse files Browse the repository at this point in the history
  • Loading branch information
thenick775 committed Dec 1, 2024
1 parent 2f6721c commit b691210
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
15 changes: 6 additions & 9 deletions gbajs3/src/emulator/mgba/mgba-emulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export type GBAEmulator = {
quitEmulator: () => void;
quitGame: () => void;
remapKeyBindings: (keyBindings: KeyBinding[]) => void;
resume: () => void;
resumeAudio: () => void;
resume: () => Promise<void>;
run: (romPath: string) => boolean;
screenshot: (fileName?: string) => boolean;
setCurrentGameName: (gameName: string | undefined) => void;
Expand Down Expand Up @@ -223,12 +222,7 @@ export const mGBAEmulator = (mGBA: mGBAEmulatorTypeDef): GBAEmulator => {
loadSaveState: mGBA.loadState,
listSaveStates: () => mGBA.FS.readdir(paths.saveStatePath),
listRoms: mGBA.listRoms,
setVolume: async (volumePercent) => {
await resumeAudio();

mGBA.setVolume(volumePercent);
},
resumeAudio: resumeAudio,
setVolume: mGBA.setVolume,
getVolume: mGBA.getVolume,
enableKeyboardInput: () => mGBA.toggleInput(true),
disableKeyboardInput: () => mGBA.toggleInput(false),
Expand Down Expand Up @@ -257,7 +251,10 @@ export const mGBAEmulator = (mGBA: mGBAEmulatorTypeDef): GBAEmulator => {
},
deleteFile: mGBA.FS.unlink,
pause: mGBA.pauseGame,
resume: mGBA.resumeGame,
resume: async () => {
await resumeAudio();
mGBA.resumeGame();
},
quitGame: mGBA.quitGame,
quitEmulator: mGBA.quitMgba,
quickReload: mGBA.quickReload,
Expand Down
5 changes: 1 addition & 4 deletions gbajs3/src/hooks/emulator/use-background-emulator.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ describe('useBackgroundEmulator hook', () => {
it('pauses emulator when entering background if running and not paused', () => {
const emulatorPauseSpy: () => void = vi.fn();
const emulatorResumeSpy: () => void = vi.fn();
const emulatorResumeAudioSpy: () => void = vi.fn();

vi.spyOn(contextHooks, 'useEmulatorContext').mockImplementation(() => ({
setCanvas: vi.fn(),
canvas: null,
emulator: {
pause: emulatorPauseSpy,
resume: emulatorResumeSpy,
resumeAudio: emulatorResumeAudioSpy
resume: emulatorResumeSpy
} as GBAEmulator
}));

Expand All @@ -50,6 +48,5 @@ describe('useBackgroundEmulator hook', () => {

// resumes emulator when coming back from background
expect(emulatorResumeSpy).toHaveBeenCalledOnce();
expect(emulatorResumeAudioSpy).toHaveBeenCalledOnce();
});
});
1 change: 0 additions & 1 deletion gbajs3/src/hooks/emulator/use-background-emulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const useBackgroundEmulator = ({
setPausedForBackground(true);
} else if (isDocumentVisible && pausedForBackground) {
emulator?.resume();
emulator?.resumeAudio();
setPausedForBackground(false);
}
}
Expand Down

0 comments on commit b691210

Please sign in to comment.