EmulatorManager class handles emulator discovery, selection, and lifecycle management. It supports both RetroArch (external process) and native libretro core loading modes.
Constructor
Core management
getCoreDownloader()
Returns theCoreDownloader instance for managing libretro cores.
CoreDownloader
getCoresForSystem()
Returns information about all known cores for a system, including display name, description, and installation status.System identifier (e.g.,
'nes', 'snes', 'genesis')CoreInfo[]
Example response:
getCorePathForSystem()
Get the core path for a specific system, checking the app-managed cores directory first, then falling back to RetroArch’s directory.System identifier
string | null - Core file path, or null if no core is installed
Emulator management
getAvailableEmulators()
Get list of available emulators discovered on the system.EmulatorInfo[]
getEmulator()
Get a specific emulator by ID.Emulator identifier
EmulatorInfo | undefined
isEmulatorRunning()
Check if an emulator is currently running.boolean
getCurrentEmulatorPid()
Get the currently running emulator’s process ID (for external RetroArch processes).number | undefined
isNativeMode()
Check if the current emulator is using native libretro core loading.boolean
Game launching
launchGame()
Launch a game with the specified emulator and system. Automatically downloads missing cores.Full path to the ROM file
System identifier (e.g.,
'nes', 'snes')Emulator ID to use. If omitted, selects the best available emulator for the system.
Additional command-line arguments for external emulators
Specific core to use (e.g.,
'fceumm_libretro'). If omitted, uses the preferred core for the system.Promise<void>
Throws: Error if no emulator is found for the system or core download fails
Emits:
gameLaunched- When game starts successfullycore:downloadProgress- During core download (if needed)
If the requested core is not installed,
launchGame will automatically download it before launching.stopEmulator()
Stop the currently running emulator.Promise<void>
Emulation control
pause()
Pause the current emulator.Promise<void>
Throws: Error if no emulator is running
Emits: emulator:paused
resume()
Resume the current emulator.Promise<void>
Throws: Error if no emulator is running
Emits: emulator:resumed
reset()
Reset the current emulator (soft reset the game).Promise<void>
Throws: Error if no emulator is running
Emits: emulator:reset
setSpeed()
Set emulation speed multiplier.Speed multiplier (1 = normal, 2 = 2x, 0.5 = half speed)
void
Speed control only works in native mode (libretro-native). External RetroArch processes do not support this API.
Save states
saveState()
Save state to a specific slot.Save slot number (0-99). Slot 99 is used for autosave on game close.
Promise<void>
Throws: Error if no emulator is running or save fails
Emits: emulator:stateSaved with { slot: number }
loadState()
Load state from a specific slot.Save slot number to load from
Promise<void>
Throws: Error if no emulator is running or load fails
Emits: emulator:stateLoaded with { slot: number }
Screenshots
screenshot()
Take a screenshot of the current game.Optional output file path. If omitted, generates a timestamped filename in the screenshots directory.
Promise<string> - Path to the saved screenshot
Throws: Error if no emulator is running or screenshot fails
Emits: emulator:screenshotTaken with { path: string }
Worker client (native mode)
setWorkerClient()
Set the worker client for native mode emulation. Called internally by IPCHandlers after spawning the utility process.Worker client instance, or null to clear
void
getWorkerClient()
Get the current worker client (if in native mode).EmulationWorkerClient | null
getCurrentEmulator()
Get the current emulator instance (for native core access).EmulatorCore | null
prepareForQuit()
Synchronously mark the worker as shutting down so that a process exit during the async shutdown sequence doesn’t emit an error.void
Events
EmulatorManager extends EventEmitter and emits the following events:Emulated by the underlying EmulatorCore
Emulation paused
Emulation resumed
Emulation reset
Emulator terminated
Usage example
Error handling
All async methods throw errors that should be caught:Source reference
- Implementation:
apps/desktop/src/main/emulator/EmulatorManager.ts:16 - Usage example:
apps/desktop/src/main/ipc/handlers.ts:21