diff --git a/src/import/RomImporter.lua b/src/import/RomImporter.lua index 51d83c71..cd6b231c 100644 --- a/src/import/RomImporter.lua +++ b/src/import/RomImporter.lua @@ -1,6 +1,7 @@ local GameVersion = require("src.core.GameVersion") local Strings = require("src.core.Strings") local HostShell = require("src.core.HostShell") +local Platform = require("src.core.Platform") local SafeArea = require("src.core.SafeArea") local RomImporter = {} @@ -317,6 +318,7 @@ local function releasePointerGrab() end local function commandOutput(command) + if not Platform.canSpawnProcess() then return nil end releasePointerGrab() local pipe = HostShell.popen(command) if not pipe then return nil end @@ -1154,6 +1156,14 @@ end function RomImporter:choose(version) if self.workState == "working" then return end self.chooseVersion = version or "red" + if Platform.isNX() then + self.notice = { + version = self.chooseVersion, + status = "Copy your .gb/.gbc into:", + detail = love.filesystem.getSaveDirectory() .. "/imports/", + } + return + end if self.android then -- Prefer a not-yet-imported .gb/.gbc already in the save dir (USB copy, or -- a fresh SAF pick). Never reuse an already-imported cart's file -- that diff --git a/tests/platform_nx_shell_gate_test.lua b/tests/platform_nx_shell_gate_test.lua new file mode 100644 index 00000000..740afc58 --- /dev/null +++ b/tests/platform_nx_shell_gate_test.lua @@ -0,0 +1,55 @@ +-- NX must not invoke HostShell / desktop file pickers (SWNX-04). +package.path = "./?.lua;./?/init.lua;" .. package.path +if not _G.love then _G.love = require("tests.love_stub") end +love.system = love.system or {} +love.filesystem = love.filesystem or {} + +local S = require("tests.harness").suite("platform NX shell gate") +local check = S.check +local eq = S.eq + +local popenCalls = 0 +local realHostShell = package.loaded["src.core.HostShell"] +package.loaded["src.core.HostShell"] = { + envPrefix = function() return "" end, + popen = function() + popenCalls = popenCalls + 1 + return nil + end, + restart = function() end, +} + +love.system.getOS = function() return "NX" end +love.filesystem.getSaveDirectory = function() return "/save/pokemon-love2d" end + +package.loaded["src.core.Platform"] = nil +package.loaded["src.import.RomImporter"] = nil +local RomImporter = require("src.import.RomImporter") + +local ri = RomImporter.new(function() end, { launcher = true }) +ri.ready = { red = false, blue = false, yellow = false } + +popenCalls = 0 +ri:choose("red") +eq(popenCalls, 0, "choose on NX does not call HostShell.popen") +check(ri.notice ~= nil, "NX choose sets a save-directory notice") +check(ri.notice.detail:find("imports", 1, true) ~= nil, + "notice mentions imports inbox path") + +-- Desktop path still reaches the shell when a picker exists. +love.system.getOS = function() return "Linux" end +package.loaded["src.core.Platform"] = nil +package.loaded["src.import.RomImporter"] = nil +RomImporter = require("src.import.RomImporter") +ri = RomImporter.new(function() end, { launcher = true }) +ri.ready = { red = false, blue = false, yellow = false } +popenCalls = 0 +ri:choose("red") +check(popenCalls >= 1 or ri.notice ~= nil, + "Linux choose still attempts shell picker or falls back with notice") + +package.loaded["src.core.HostShell"] = realHostShell +package.loaded["src.core.Platform"] = nil +package.loaded["src.import.RomImporter"] = nil + +S.finish() diff --git a/tests/run_tests.lua b/tests/run_tests.lua index eb7fbf31..0043a164 100644 --- a/tests/run_tests.lua +++ b/tests/run_tests.lua @@ -3371,6 +3371,7 @@ runSuites({ "tests/rom_importer_no_picker_test.lua" }) runSuites({ "tests/rom_importer_double_pick_test.lua" }) -- ---------------------------------------------- Switch platform capabilities runSuites({ "tests/platform_nx_test.lua" }) +runSuites({ "tests/platform_nx_shell_gate_test.lua" }) -- ---------------------------------------------- parity workstream tests -- Each tests/parity_*.lua is a self-contained file (own bootstrap + check, -- error()s if any assertion fails). Globbed, so dropping a new parity