import { contextBridge, ipcRenderer } from 'electron'; import type { EmulatorConfig, EmulatorState, GameEntry, SystemInfo, AppSettings, InstallProgress, ConfigPreset, } from '../shared/types'; const api = { system: { info: (): Promise => ipcRenderer.invoke('system:info'), platformName: (): Promise => ipcRenderer.invoke('system:platform-name'), }, emulators: { list: (): Promise => ipcRenderer.invoke('emulators:list'), systemAssignments: (): Promise> => ipcRenderer.invoke('emulators:system-assignments'), states: (): Promise => ipcRenderer.invoke('emulators:states'), check: (id: string): Promise => ipcRenderer.invoke('emulators:check', id), /** Download + install emulator directly. Returns final EmulatorState */ install: (id: string): Promise => ipcRenderer.invoke('emulators:install', id), /** Launch emulator standalone (no ROM) */ launch: (id: string): Promise => ipcRenderer.invoke('emulators:launch', id), /** Uninstall an emulator */ uninstall: (id: string): Promise<{ removed: boolean; state: EmulatorState }> => ipcRenderer.invoke('emulators:uninstall', id), /** Apply recommended config preset to an installed emulator */ configure: (id: string, installPath: string): Promise<{ success: boolean; state: EmulatorState }> => ipcRenderer.invoke('emulators:configure', id, installPath), /** Get available config presets for an emulator */ presets: (id: string): Promise => ipcRenderer.invoke('emulators:presets', id), /** Check if an emulator has been configured */ configured: (id: string, installPath?: string): Promise => ipcRenderer.invoke('emulators:configured', id, installPath), /** Open the emulator's website in browser (fallback) */ openWebsite: (id: string): Promise => ipcRenderer.invoke('emulators:open-website', id), /** Apply controller config to an installed emulator */ updateControllerConfig: (id: string, installPath: string, controllerName?: string): Promise => ipcRenderer.invoke('emulators:update-controller-config', id, installPath, controllerName), /** Listen for install progress updates */ onInstallProgress: (cb: (progress: InstallProgress) => void) => { const handler = (_event: Electron.IpcRendererEvent, p: InstallProgress) => cb(p); ipcRenderer.on('emulators:install-progress', handler); return () => ipcRenderer.removeListener('emulators:install-progress', handler); }, }, roms: { scan: (directory?: string): Promise => ipcRenderer.invoke('roms:scan', directory), selectDirectory: (): Promise => ipcRenderer.invoke('roms:select-directory'), }, game: { launch: (emulatorId: string, romPath: string): Promise => ipcRenderer.invoke('game:launch', emulatorId, romPath), recent: (): Promise => ipcRenderer.invoke('games:recent'), clearRecent: (): Promise => ipcRenderer.invoke('games:clear-recent'), scrapeArt: (title: string, platform: string): Promise => ipcRenderer.invoke('games:scrape-art', title, platform), cacheCovers: (entries: { romPath: string; coverUrl: string }[]): Promise => ipcRenderer.invoke('games:cache-covers', entries), }, bios: { listKnown: (): Promise => ipcRenderer.invoke('bios:list-known'), scan: (directory?: string): Promise => ipcRenderer.invoke('bios:scan', directory), selectDirectory: (): Promise => ipcRenderer.invoke('bios:select-directory'), configureRetroArch: (configDir: string, biosDir: string): Promise => ipcRenderer.invoke('bios:configure-retroarch', configDir, biosDir), }, settings: { get: (): Promise => ipcRenderer.invoke('settings:get'), save: (s: Partial): Promise => ipcRenderer.invoke('settings:save', s), reset: (): Promise => ipcRenderer.invoke('settings:reset'), }, paths: { romsDirectory: (): Promise => ipcRenderer.invoke('paths:roms-directory'), emulatorsDirectory: (): Promise => ipcRenderer.invoke('paths:emulators-directory'), }, utilities: { regenerateRomsStructure: (): Promise => ipcRenderer.invoke('utilities:regenerate-roms-structure'), }, updates: { check: (): Promise => ipcRenderer.invoke('updates:check'), download: (): Promise => ipcRenderer.invoke('updates:download'), quitAndInstall: (): Promise => ipcRenderer.invoke('updates:quit-and-install'), onStatus: (cb: (status: Record) => void) => { const handler = (_event: Electron.IpcRendererEvent, s: Record) => cb(s); ipcRenderer.on('updates:status', handler); return () => ipcRenderer.removeListener('updates:status', handler); }, onDownloadProgress: (cb: (progress: Record) => void) => { const handler = (_event: Electron.IpcRendererEvent, p: Record) => cb(p); ipcRenderer.on('updates:download-progress', handler); return () => ipcRenderer.removeListener('updates:download-progress', handler); }, }, }; contextBridge.exposeInMainWorld('omni', api); export type OmniApi = typeof api;