From cf48d371fc154c41b599adef0f6e6a6006188350 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 11 Sep 2026 08:39:48 -0400 Subject: [PATCH 1/3] feat(emulatorjs): set a default core per platform in config.yml Add an `emulatorjs.default_cores` block mapping a platform slug to the core the player preselects for it, so an instance can run DS software on DeSmuME and DSi software on melonDS without every user picking a core on every device. The player resolves its core from the game's remembered core, then the platform's, then the configured default, then the platform's first supported core. Each candidate is checked against the cores the platform actually supports, so an unknown platform or core falls through. Playing no longer writes the resolved core back to local storage unless the user picked a different one, so changing the configured default reaches devices that never made a choice. Closes #4434 Co-Authored-By: Claude Opus 5 (1M context) --- backend/config/config_manager.py | 14 +++++++++-- backend/endpoints/configs.py | 1 + backend/endpoints/responses/config.py | 1 + .../tests/config/fixtures/config/config.yml | 3 +++ backend/tests/config/test_config_loader.py | 23 +++++++++++++++++++ backend/tests/endpoints/test_config.py | 1 + docs/BACKEND_ARCHITECTURE.md | 2 ++ examples/config.example.yml | 3 +++ .../__generated__/models/ConfigResponse.ts | 1 + frontend/src/stores/config.ts | 4 ++++ frontend/src/v2/views/Player/EmulatorJS.vue | 12 ++++++++-- .../src/v2/views/Player/coreStorage.test.ts | 20 ++++++++++++++++ frontend/src/v2/views/Player/coreStorage.ts | 8 +++++-- 13 files changed, 87 insertions(+), 6 deletions(-) diff --git a/backend/config/config_manager.py b/backend/config/config_manager.py index a806023ee..78a44a3a8 100644 --- a/backend/config/config_manager.py +++ b/backend/config/config_manager.py @@ -476,6 +476,7 @@ class Config: EJS_ENABLE_AUTO_SAVE_SYNC: bool EJS_NETPLAY_ENABLED: bool EJS_NETPLAY_ICE_SERVERS: list[NetplayICEServer] + EJS_DEFAULT_CORES: dict[str, str] # platform_slug -> core_name EJS_SETTINGS: dict[str, EjsOption] # core_name -> EjsOption EJS_CONTROLS: dict[str, EjsControls] # core_name -> EjsControls SCAN_METADATA_PRIORITY: list[str] @@ -763,6 +764,10 @@ class ConfigManager: EJS_NETPLAY_ICE_SERVERS=pydash.get( self._raw_config, "emulatorjs.netplay.ice_servers", [] ), + EJS_DEFAULT_CORES=pydash.get( + self._raw_config, "emulatorjs.default_cores", {} + ) + or {}, EJS_SETTINGS=pydash.get(self._raw_config, "emulatorjs.settings", {}), EJS_CONTROLS=self._get_ejs_controls(), SCAN_METADATA_PRIORITY=pydash.get( @@ -895,9 +900,9 @@ class ConfigManager: return yaml_controls def _validated_platform_map(self, raw: Any, config_key: str) -> dict[str, str]: - """Check a folder name to slug mapping. + """Check a mapping of platform or folder names to non-empty strings. - Folder names are lowercased so lookups can ignore case. + Keys are lowercased so lookups can ignore case. """ if not isinstance(raw, dict): log.critical(f"Invalid config.yml: {config_key} must be a dictionary") @@ -1064,6 +1069,10 @@ class ConfigManager: ) sys.exit(3) + self.config.EJS_DEFAULT_CORES = self._validated_platform_map( + self.config.EJS_DEFAULT_CORES, "emulatorjs.default_cores" + ) + if not isinstance(self.config.EJS_SETTINGS, dict): log.critical("Invalid config.yml: emulatorjs.settings must be a dictionary") sys.exit(3) @@ -1335,6 +1344,7 @@ class ConfigManager: "enabled": self.config.EJS_NETPLAY_ENABLED, "ice_servers": self.config.EJS_NETPLAY_ICE_SERVERS, }, + "default_cores": self.config.EJS_DEFAULT_CORES, "settings": self.config.EJS_SETTINGS, "controls": self._format_ejs_controls_for_yaml(), }, diff --git a/backend/endpoints/configs.py b/backend/endpoints/configs.py index 99f3d60d6..bd081063c 100644 --- a/backend/endpoints/configs.py +++ b/backend/endpoints/configs.py @@ -154,6 +154,7 @@ def get_config(request: Request) -> ConfigResponse: cfg.EJS_NETPLAY_ICE_SERVERS if request.user.is_authenticated else [] ), EJS_CONTROLS=cfg.EJS_CONTROLS, + EJS_DEFAULT_CORES=cfg.EJS_DEFAULT_CORES, EJS_SETTINGS=cfg.EJS_SETTINGS, SCAN_METADATA_PRIORITY=cfg.SCAN_METADATA_PRIORITY, SCAN_ARTWORK_PRIORITY=cfg.SCAN_ARTWORK_PRIORITY, diff --git a/backend/endpoints/responses/config.py b/backend/endpoints/responses/config.py index 3fc0cc5b0..edba7b316 100644 --- a/backend/endpoints/responses/config.py +++ b/backend/endpoints/responses/config.py @@ -27,6 +27,7 @@ class ConfigResponse(TypedDict): EJS_ENABLE_AUTO_SAVE_SYNC: bool EJS_NETPLAY_ENABLED: bool EJS_NETPLAY_ICE_SERVERS: list[NetplayICEServer] + EJS_DEFAULT_CORES: dict[str, str] EJS_SETTINGS: dict[str, dict[str, str]] EJS_CONTROLS: dict[str, EjsControls] SCAN_METADATA_PRIORITY: list[str] diff --git a/backend/tests/config/fixtures/config/config.yml b/backend/tests/config/fixtures/config/config.yml index cd9a3047a..daee39102 100644 --- a/backend/tests/config/fixtures/config/config.yml +++ b/backend/tests/config/fixtures/config/config.yml @@ -81,6 +81,9 @@ emulatorjs: - urls: "turn:global.relay.metered.ca:80" username: "user" credential: "password" + default_cores: + nds: desmume + Nintendo-DSi: melonds settings: parallel_n64: vsync: disabled diff --git a/backend/tests/config/test_config_loader.py b/backend/tests/config/test_config_loader.py index 253dd12b9..dd519290c 100644 --- a/backend/tests/config/test_config_loader.py +++ b/backend/tests/config/test_config_loader.py @@ -69,6 +69,10 @@ def test_config_loader(): "credential": "password", }, ] + assert loader.config.EJS_DEFAULT_CORES == { + "nds": "desmume", + "nintendo-dsi": "melonds", + } assert loader.config.EJS_SETTINGS == { "parallel_n64": {"vsync": "disabled"}, "snes9x": {"snes9x_region": "ntsc"}, @@ -160,6 +164,7 @@ def test_empty_config_loader(): assert not loader.config.EJS_ENABLE_AUTO_SAVE_SYNC assert not loader.config.EJS_NETPLAY_ENABLED assert loader.config.EJS_NETPLAY_ICE_SERVERS == [] + assert loader.config.EJS_DEFAULT_CORES == {} assert loader.config.EJS_SETTINGS == {} assert loader.config.EJS_CONTROLS == {} assert loader.config.SCAN_ARTWORK_PRIORITY_OVERRIDES == {} @@ -610,6 +615,24 @@ def test_null_platforms_block_means_empty(tmp_path): assert loader.config.PLATFORMS_VERSIONS == {} +def test_null_default_cores_block_means_empty(tmp_path): + config_file = tmp_path / "config.yml" + config_file.write_text("emulatorjs:\n default_cores:\n") + + assert ConfigManager(str(config_file)).config.EJS_DEFAULT_CORES == {} + + +@pytest.mark.parametrize("value", ['""', "5", "~"]) +def test_default_core_must_be_a_non_empty_string(tmp_path, value): + config_file = tmp_path / "config.yml" + config_file.write_text(f"emulatorjs:\n default_cores:\n nds: {value}\n") + + with pytest.raises(SystemExit) as excinfo: + ConfigManager(str(config_file)) + + assert excinfo.value.code == 3 + + @pytest.mark.parametrize("value", ['""', "5", "~"]) def test_platform_binding_must_be_a_non_empty_string(tmp_path, value): with pytest.raises(SystemExit) as excinfo: diff --git a/backend/tests/endpoints/test_config.py b/backend/tests/endpoints/test_config.py index 2ff0f0a9d..e20554d90 100644 --- a/backend/tests/endpoints/test_config.py +++ b/backend/tests/endpoints/test_config.py @@ -33,6 +33,7 @@ def test_config(client): DEFAULT_EXCLUDED_MULTI_FILE_DIRS ) assert config.get("PLATFORMS_BINDING") == {} + assert config.get("EJS_DEFAULT_CORES") == {} assert not config.get("SKIP_HASH_CALCULATION") assert config.get("GAMELIST_MEDIA_THUMBNAIL") == "box2d" assert config.get("GAMELIST_MEDIA_IMAGE") == "screenshot" diff --git a/docs/BACKEND_ARCHITECTURE.md b/docs/BACKEND_ARCHITECTURE.md index 56aa302f7..9b007e6a1 100644 --- a/docs/BACKEND_ARCHITECTURE.md +++ b/docs/BACKEND_ARCHITECTURE.md @@ -1696,6 +1696,8 @@ scan: emulatorjs: debug: false + default_cores: + nds: desmume # platform slug → core preselected in the player netplay: enabled: false ice_servers: diff --git a/examples/config.example.yml b/examples/config.example.yml index 141b85ceb..c297396e5 100644 --- a/examples/config.example.yml +++ b/examples/config.example.yml @@ -182,6 +182,9 @@ # disable_batch_bootup: false # disable_auto_unload: false # auto_save_sync: false # Upload the save to the server whenever it changes, without Save & Quit +# default_cores: # Core preselected per platform, unless overridden on the device +# nds: desmume +# nintendo-dsi: melonds # settings: # parallel_n64: # Use the exact core name # vsync: disabled diff --git a/frontend/src/__generated__/models/ConfigResponse.ts b/frontend/src/__generated__/models/ConfigResponse.ts index de31d19d6..850221e01 100644 --- a/frontend/src/__generated__/models/ConfigResponse.ts +++ b/frontend/src/__generated__/models/ConfigResponse.ts @@ -29,6 +29,7 @@ export type ConfigResponse = { EJS_ENABLE_AUTO_SAVE_SYNC: boolean; EJS_NETPLAY_ENABLED: boolean; EJS_NETPLAY_ICE_SERVERS: Array; + EJS_DEFAULT_CORES: Record; EJS_SETTINGS: Record>; EJS_CONTROLS: Record; SCAN_METADATA_PRIORITY: Array; diff --git a/frontend/src/stores/config.ts b/frontend/src/stores/config.ts index 115c07837..ecb9dd307 100644 --- a/frontend/src/stores/config.ts +++ b/frontend/src/stores/config.ts @@ -32,6 +32,7 @@ const defaultConfig = { EJS_DISABLE_BATCH_BOOTUP: false, EJS_ENABLE_AUTO_SAVE_SYNC: false, EJS_NETPLAY_ICE_SERVERS: [], + EJS_DEFAULT_CORES: {}, EJS_SETTINGS: {}, EJS_CONTROLS: {}, SCAN_METADATA_PRIORITY: [], @@ -93,6 +94,9 @@ export default defineStore("config", { isExclusionType(type: string): type is ExclusionType { return Object.keys(this.config).includes(type); }, + getEJSDefaultCore(platformSlug: string): string | null { + return this.config.EJS_DEFAULT_CORES[platformSlug.toLowerCase()] ?? null; + }, getEJSCoreOptions(core: string | null): Record { const defaultOptions = this.config.EJS_SETTINGS["default"] || {}; if (!core) return defaultOptions; diff --git a/frontend/src/v2/views/Player/EmulatorJS.vue b/frontend/src/v2/views/Player/EmulatorJS.vue index d01913263..cd0980e69 100644 --- a/frontend/src/v2/views/Player/EmulatorJS.vue +++ b/frontend/src/v2/views/Player/EmulatorJS.vue @@ -118,6 +118,9 @@ const selectedDisc = ref(null); const selectedCore = ref(null); const selectedFirmware = ref(null); const supportedCores = ref([]); +// Written back only when the user deviates from it, so a later change to +// the instance default isn't shadowed by a core nobody chose. +const resolvedCore = ref(null); const gameRunning = ref(false); const removeIOSFullscreenShim = ref<(() => void) | null>(null); @@ -222,7 +225,10 @@ async function onPlay() { removeIOSFullscreenShim.value = installIOSFullscreenShim(); if (rom.value) { - rememberCore(rom.value.id, rom.value.platform_slug, selectedCore.value); + if (selectedCore.value !== resolvedCore.value) { + rememberCore(rom.value.id, rom.value.platform_slug, selectedCore.value); + resolvedCore.value = selectedCore.value; + } rememberDisc(rom.value.id, selectedDisc.value); } gameRunning.value = true; @@ -360,11 +366,13 @@ onMounted(async () => { bootableRomFiles.value, ); - selectedCore.value = resolveRememberedCore( + resolvedCore.value = resolveRememberedCore( rom.value.id, rom.value.platform_slug, supportedCores.value, + configStore.getEJSDefaultCore(rom.value.platform_slug), ); + selectedCore.value = resolvedCore.value; const coreOptions = configStore.getEJSCoreOptions(selectedCore.value); const storedBiosID = localStorage.getItem( diff --git a/frontend/src/v2/views/Player/coreStorage.test.ts b/frontend/src/v2/views/Player/coreStorage.test.ts index 4d9edc4c9..9f4d603c3 100644 --- a/frontend/src/v2/views/Player/coreStorage.test.ts +++ b/frontend/src/v2/views/Player/coreStorage.test.ts @@ -50,6 +50,26 @@ describe("coreStorage", () => { expect(resolveRememberedCore(ROM_ID, SLUG, ARCADE_CORES)).toBe("mame2003"); }); + it("uses the instance default when nothing is remembered", () => { + expect(resolveRememberedCore(ROM_ID, SLUG, ARCADE_CORES, "fbneo")).toBe( + "fbneo", + ); + }); + + it("prefers a remembered core over the instance default", () => { + rememberCore(ROM_ID, SLUG, "mame2003_plus"); + + expect(resolveRememberedCore(ROM_ID, SLUG, ARCADE_CORES, "fbneo")).toBe( + "mame2003_plus", + ); + }); + + it("ignores an instance default the platform does not support", () => { + expect(resolveRememberedCore(ROM_ID, SLUG, ARCADE_CORES, "melonds")).toBe( + "mame2003", + ); + }); + it("forgets both keys when the selection is cleared", () => { rememberCore(ROM_ID, SLUG, "mame2003_plus"); rememberCore(ROM_ID, SLUG, null); diff --git a/frontend/src/v2/views/Player/coreStorage.ts b/frontend/src/v2/views/Player/coreStorage.ts index 16c55af40..9841c1f70 100644 --- a/frontend/src/v2/views/Player/coreStorage.ts +++ b/frontend/src/v2/views/Player/coreStorage.ts @@ -4,20 +4,24 @@ const gameKey = (romId: number) => `player:${romId}:core`; const platformKey = (platformSlug: string) => `player:${platformSlug}:core`; /** - * The first remembered core the platform still supports, else its first core. + * The first remembered core the platform still supports, else the core the + * instance configures for it, else its first core. * * Each candidate is validated so a core that is no longer offered (renamed - * upstream, or gated behind netplay) falls through instead of masking the next. + * upstream, or gated behind netplay, or a typo in config.yml) falls through + * instead of masking the next. */ export function resolveRememberedCore( romId: number, platformSlug: string, supportedCores: readonly string[], + configuredCore?: string | null, ): string { return ( [ localStorage.getItem(gameKey(romId)), localStorage.getItem(platformKey(platformSlug)), + configuredCore, ].find((core): core is string => !!core && supportedCores.includes(core)) ?? supportedCores[0] ); From 93e341796555af42c52c6dc6e94453ef7e1182b8 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 11 Sep 2026 08:58:26 -0400 Subject: [PATCH 2/3] fix(player): apply code-review pass to the default-core resolution Pass the netplay flag to getSupportedEJSCores so a configured core that only the nightly build offers is not dropped, resolve the core before the save and state defaults so opening the player no longer clears a remembered state id, warn when a configured core is unsupported, and guard the store getter against a payload without the field. Drop the write-back suppression: it left a game played with an inherited core unpinned, so a later platform-level pick silently switched it. Co-Authored-By: Claude Opus 5 (1M context) --- backend/config/config_manager.py | 8 ++-- frontend/src/stores/config.ts | 4 +- frontend/src/v2/views/Player/EmulatorJS.vue | 45 +++++++++++---------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/backend/config/config_manager.py b/backend/config/config_manager.py index 78a44a3a8..ce6714425 100644 --- a/backend/config/config_manager.py +++ b/backend/config/config_manager.py @@ -909,13 +909,13 @@ class ConfigManager: sys.exit(3) normalized: dict[str, str] = {} - for fs_slug, slug in raw.items(): - if not isinstance(slug, str) or not slug: + for key, value in raw.items(): + if not isinstance(value, str) or not value: log.critical( - f"Invalid config.yml: {config_key}.{fs_slug} must be a non-empty string" + f"Invalid config.yml: {config_key}.{key} must be a non-empty string" ) sys.exit(3) - normalized[str(fs_slug).lower()] = slug + normalized[str(key).lower()] = value return normalized diff --git a/frontend/src/stores/config.ts b/frontend/src/stores/config.ts index ecb9dd307..a7f1f4300 100644 --- a/frontend/src/stores/config.ts +++ b/frontend/src/stores/config.ts @@ -95,7 +95,9 @@ export default defineStore("config", { return Object.keys(this.config).includes(type); }, getEJSDefaultCore(platformSlug: string): string | null { - return this.config.EJS_DEFAULT_CORES[platformSlug.toLowerCase()] ?? null; + return ( + this.config.EJS_DEFAULT_CORES?.[platformSlug.toLowerCase()] ?? null + ); }, getEJSCoreOptions(core: string | null): Record { const defaultOptions = this.config.EJS_SETTINGS["default"] || {}; diff --git a/frontend/src/v2/views/Player/EmulatorJS.vue b/frontend/src/v2/views/Player/EmulatorJS.vue index cd0980e69..aa2fb3100 100644 --- a/frontend/src/v2/views/Player/EmulatorJS.vue +++ b/frontend/src/v2/views/Player/EmulatorJS.vue @@ -118,9 +118,6 @@ const selectedDisc = ref(null); const selectedCore = ref(null); const selectedFirmware = ref(null); const supportedCores = ref([]); -// Written back only when the user deviates from it, so a later change to -// the instance default isn't shadowed by a core nobody chose. -const resolvedCore = ref(null); const gameRunning = ref(false); const removeIOSFullscreenShim = ref<(() => void) | null>(null); @@ -225,10 +222,7 @@ async function onPlay() { removeIOSFullscreenShim.value = installIOSFullscreenShim(); if (rom.value) { - if (selectedCore.value !== resolvedCore.value) { - rememberCore(rom.value.id, rom.value.platform_slug, selectedCore.value); - resolvedCore.value = selectedCore.value; - } + rememberCore(rom.value.id, rom.value.platform_slug, selectedCore.value); rememberDisc(rom.value.id, selectedDisc.value); } gameRunning.value = true; @@ -321,7 +315,12 @@ onMounted(async () => { }); firmwareOptions.value = firmwareResponse.data; - supportedCores.value = [...getSupportedEJSCores(rom.value.platform_slug)]; + supportedCores.value = [ + ...getSupportedEJSCores( + rom.value.platform_slug, + configStore.config.EJS_NETPLAY_ENABLED, + ), + ]; emitter?.on("saveSelected", selectSave); emitter?.on("stateSelected", selectState); @@ -339,6 +338,21 @@ onMounted(async () => { }); } + // Resolved before the save/state defaults below, which key off the core + // this game will actually boot with. + const configuredCore = configStore.getEJSDefaultCore(rom.value.platform_slug); + if (configuredCore && !supportedCores.value.includes(configuredCore)) { + console.warn( + `[Play] emulatorjs.default_cores sets ${configuredCore} for ${rom.value.platform_slug}, which does not support it`, + ); + } + selectedCore.value = resolveRememberedCore( + rom.value.id, + rom.value.platform_slug, + supportedCores.value, + configuredCore, + ); + // Default selection — save and state are independent, so both can be // armed at once. The bound save is the write-back target for "Save & // Quit" (PUT in place), so we only auto-bind it when the choice is @@ -346,13 +360,10 @@ onMounted(async () => { // there are multiple saves, since loading the state injects a different // SRAM timeline that would overwrite an arbitrary save the user never // picked. In that case the user must select the save slot explicitly. - const initiallyCompatibleStates = rom.value.user_states.filter( - (s) => !s.emulator || s.emulator === supportedCores.value[0], - ); - const hasCompatibleState = initiallyCompatibleStates.length > 0; + const hasCompatibleState = compatibleStates.value.length > 0; if (hasCompatibleState) { - selectedState.value = initiallyCompatibleStates[0]; + selectedState.value = compatibleStates.value[0]; } const safeToBindSave = rom.value.user_saves.length === 1 || !hasCompatibleState; @@ -366,14 +377,6 @@ onMounted(async () => { bootableRomFiles.value, ); - resolvedCore.value = resolveRememberedCore( - rom.value.id, - rom.value.platform_slug, - supportedCores.value, - configStore.getEJSDefaultCore(rom.value.platform_slug), - ); - selectedCore.value = resolvedCore.value; - const coreOptions = configStore.getEJSCoreOptions(selectedCore.value); const storedBiosID = localStorage.getItem( `player:${rom.value.platform_slug}:bios_id`, From 5d683c72c0e22df10698d05f7e8eea17b90d70f4 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 11 Sep 2026 09:03:42 -0400 Subject: [PATCH 3/3] refactor(player): apply simplify pass to the default-core resolution Drop the console.warn for an unsupported configured core: it re-derived the check the resolver already makes, and fired on the player's device rather than where the admin would see it. The example config now points at the exact core name instead. Hoist the platform slug in onMounted, name the comment's dependency rather than its placement, drop a redundant optional chain, and put the new config tests on a helper matching their neighbours. Co-Authored-By: Claude Opus 5 (1M context) --- backend/tests/config/test_config_loader.py | 38 +++++++++++---------- examples/config.example.yml | 1 + frontend/src/stores/config.ts | 4 +-- frontend/src/v2/views/Player/EmulatorJS.vue | 20 ++++------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/backend/tests/config/test_config_loader.py b/backend/tests/config/test_config_loader.py index dd519290c..b5030c55a 100644 --- a/backend/tests/config/test_config_loader.py +++ b/backend/tests/config/test_config_loader.py @@ -615,24 +615,6 @@ def test_null_platforms_block_means_empty(tmp_path): assert loader.config.PLATFORMS_VERSIONS == {} -def test_null_default_cores_block_means_empty(tmp_path): - config_file = tmp_path / "config.yml" - config_file.write_text("emulatorjs:\n default_cores:\n") - - assert ConfigManager(str(config_file)).config.EJS_DEFAULT_CORES == {} - - -@pytest.mark.parametrize("value", ['""', "5", "~"]) -def test_default_core_must_be_a_non_empty_string(tmp_path, value): - config_file = tmp_path / "config.yml" - config_file.write_text(f"emulatorjs:\n default_cores:\n nds: {value}\n") - - with pytest.raises(SystemExit) as excinfo: - ConfigManager(str(config_file)) - - assert excinfo.value.code == 3 - - @pytest.mark.parametrize("value", ['""', "5", "~"]) def test_platform_binding_must_be_a_non_empty_string(tmp_path, value): with pytest.raises(SystemExit) as excinfo: @@ -648,6 +630,26 @@ def test_platform_binding_lookup_ignores_case(tmp_path): assert loader.config.PLATFORMS_BINDING == {} +def _write_emulatorjs_config(tmp_path: Path, emulatorjs_block: str) -> ConfigManager: + config_file = tmp_path / "config.yml" + config_file.write_text(f"emulatorjs:\n{emulatorjs_block}") + return ConfigManager(str(config_file)) + + +def test_null_default_cores_block_means_empty(tmp_path): + loader = _write_emulatorjs_config(tmp_path, " default_cores:\n") + + assert loader.config.EJS_DEFAULT_CORES == {} + + +@pytest.mark.parametrize("value", ['""', "5", "~"]) +def test_default_core_must_be_a_non_empty_string(tmp_path, value): + with pytest.raises(SystemExit) as excinfo: + _write_emulatorjs_config(tmp_path, f" default_cores:\n nds: {value}\n") + + assert excinfo.value.code == 3 + + @pytest.fixture def critical(mocker): """The last message the config manager logged before exiting.""" diff --git a/examples/config.example.yml b/examples/config.example.yml index c297396e5..d7577a750 100644 --- a/examples/config.example.yml +++ b/examples/config.example.yml @@ -183,6 +183,7 @@ # disable_auto_unload: false # auto_save_sync: false # Upload the save to the server whenever it changes, without Save & Quit # default_cores: # Core preselected per platform, unless overridden on the device +# # Use the exact core name, as listed for the platform in the docs # nds: desmume # nintendo-dsi: melonds # settings: diff --git a/frontend/src/stores/config.ts b/frontend/src/stores/config.ts index a7f1f4300..ecb9dd307 100644 --- a/frontend/src/stores/config.ts +++ b/frontend/src/stores/config.ts @@ -95,9 +95,7 @@ export default defineStore("config", { return Object.keys(this.config).includes(type); }, getEJSDefaultCore(platformSlug: string): string | null { - return ( - this.config.EJS_DEFAULT_CORES?.[platformSlug.toLowerCase()] ?? null - ); + return this.config.EJS_DEFAULT_CORES[platformSlug.toLowerCase()] ?? null; }, getEJSCoreOptions(core: string | null): Record { const defaultOptions = this.config.EJS_SETTINGS["default"] || {}; diff --git a/frontend/src/v2/views/Player/EmulatorJS.vue b/frontend/src/v2/views/Player/EmulatorJS.vue index aa2fb3100..274963f19 100644 --- a/frontend/src/v2/views/Player/EmulatorJS.vue +++ b/frontend/src/v2/views/Player/EmulatorJS.vue @@ -315,9 +315,10 @@ onMounted(async () => { }); firmwareOptions.value = firmwareResponse.data; + const platformSlug = rom.value.platform_slug; supportedCores.value = [ ...getSupportedEJSCores( - rom.value.platform_slug, + platformSlug, configStore.config.EJS_NETPLAY_ENABLED, ), ]; @@ -338,19 +339,12 @@ onMounted(async () => { }); } - // Resolved before the save/state defaults below, which key off the core - // this game will actually boot with. - const configuredCore = configStore.getEJSDefaultCore(rom.value.platform_slug); - if (configuredCore && !supportedCores.value.includes(configuredCore)) { - console.warn( - `[Play] emulatorjs.default_cores sets ${configuredCore} for ${rom.value.platform_slug}, which does not support it`, - ); - } + // compatibleStates filters on selectedCore, so resolve the core first. selectedCore.value = resolveRememberedCore( rom.value.id, - rom.value.platform_slug, + platformSlug, supportedCores.value, - configuredCore, + configStore.getEJSDefaultCore(platformSlug), ); // Default selection — save and state are independent, so both can be @@ -378,9 +372,7 @@ onMounted(async () => { ); const coreOptions = configStore.getEJSCoreOptions(selectedCore.value); - const storedBiosID = localStorage.getItem( - `player:${rom.value.platform_slug}:bios_id`, - ); + const storedBiosID = localStorage.getItem(`player:${platformSlug}:bios_id`); selectedFirmware.value = resolveInitialFirmware({ options: firmwareOptions.value,