mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-06 01:53:56 -06:00
fix: preselect RetroArch in a system's install box
The box showed the first setup by name, AmberELEC on 17 system pages, under Windows tabs. It now selects RetroArch, which runs on every system the box has a tab for, else a setup the release publishes a ZIP for.
This commit is contained in:
1 parent
f1dfe39030
commit
28d310d8bc
3 files changed
+34
-6
No files matched your search
@@ -9114,6 +9114,21 @@ def _install_args(platform: str, system: str, shell: str) -> str:
|
||||
return f"--platform {platform} --system {quoted}"
|
||||
|
||||
|
||||
def _default_setup(declared: list[tuple[str, str]]) -> tuple[str, str]:
|
||||
"""The setup an install box shows before the reader picks one.
|
||||
|
||||
The first in alphabetical order was AmberELEC on 17 system pages, a
|
||||
handheld system under a Windows tab. RetroArch runs on every OS the box
|
||||
has a tab for. Without it, a setup the release publishes a ZIP for,
|
||||
the ones most people download (`release_pack`).
|
||||
"""
|
||||
for wanted in (lambda p: p == "retroarch", has_release_pack):
|
||||
chosen = next((pair for pair in declared if wanted(pair[0])), None)
|
||||
if chosen:
|
||||
return chosen
|
||||
return declared[0]
|
||||
|
||||
|
||||
def _install_picker(declared: list[tuple[str, str]]) -> list[str]:
|
||||
"""One command, for the setup the reader picks, under the OS tabs.
|
||||
|
||||
@@ -9128,15 +9143,16 @@ def _install_picker(declared: list[tuple[str, str]]) -> list[str]:
|
||||
return html.escape(text, quote=False).replace('"', """)
|
||||
|
||||
names = Counter(platform for platform, _system in declared)
|
||||
lead = _default_setup(declared)
|
||||
options = "".join(
|
||||
f'<option value="{attribute(platform)}" '
|
||||
f'data-sh="{attribute(_install_args(platform, system, "sh"))}" '
|
||||
f'<option value="{attribute(platform)}"'
|
||||
+ (" selected" if (platform, system) == lead else "")
|
||||
+ f' data-sh="{attribute(_install_args(platform, system, "sh"))}" '
|
||||
f'data-ps="{attribute(_install_args(platform, system, "powershell"))}">'
|
||||
+ html.escape(_platform_display(platform) + (f" ({system})" if names[platform] > 1 else ""),
|
||||
quote=False)
|
||||
+ "</option>"
|
||||
for platform, system in declared)
|
||||
lead = declared[0]
|
||||
args = {key: _install_args(*lead, TERMINALS[key][2]) for key in INSTALL_PICKER_OSES}
|
||||
return [
|
||||
"Each platform names the system its own way.",
|
||||
|
||||
@@ -193,11 +193,23 @@ class AnInstallBoxShowsOneCommand(unittest.TestCase):
|
||||
self.assertEqual(re.findall(r'<TabItem label="([^"]+)"', tabs),
|
||||
["Windows", "macOS", "Linux", "Steam Deck"])
|
||||
self.assertEqual(tabs.count("--platform"), 4)
|
||||
self.assertEqual(tabs.count("--platform emudeck --system sony-psp"), 4)
|
||||
# RetroArch, which runs on each tab's system, not the first by name.
|
||||
self.assertEqual(tabs.count("--platform retroarch --system"), 4)
|
||||
|
||||
def test_the_default_setup(self) -> None:
|
||||
"""AmberELEC led 17 system pages, a handheld system under the
|
||||
Windows tab, for being first in alphabetical order."""
|
||||
self.assertEqual(gs._default_setup([("amberelec", "psx"), ("retroarch", "Sony - PlayStation")]),
|
||||
("retroarch", "Sony - PlayStation"))
|
||||
self.assertEqual(gs._default_setup([("amberelec", "x"), ("batocera", "x")]), ("batocera", "x"))
|
||||
self.assertEqual(gs._default_setup([("amberelec", "x"), ("knulli", "x")]), ("amberelec", "x"))
|
||||
select = re.search(r"<select>(.*?)</select>", self.text).group(1)
|
||||
self.assertEqual(re.findall(r'<option value="([^"]+)" selected', select), ["retroarch"])
|
||||
|
||||
def test_the_setup_list_carries_every_command(self) -> None:
|
||||
select = re.search(r"<select>(.*?)</select>", self.text).group(1)
|
||||
options = re.findall(r'<option value="([^"]+)" data-sh="([^"]+)" data-ps="([^"]+)">', select)
|
||||
options = re.findall(r'<option value="([^"]+)"(?: selected)? data-sh="([^"]+)" data-ps="([^"]+)">',
|
||||
select)
|
||||
self.assertEqual([value for value, _sh, _ps in options], ["emudeck", "retroarch", "retrobat"])
|
||||
self.assertIn(("retrobat", "--platform retrobat --system 'Neo Geo'",
|
||||
"--platform retrobat --system 'Neo Geo'"), options)
|
||||
|
||||
@@ -1086,7 +1086,7 @@ const copyButtons = () => {
|
||||
};
|
||||
|
||||
// A system's install box: one command, for the setup picked in its list,
|
||||
// under the site's OS tabs. The box is built with the first setup's command;
|
||||
// under the site's OS tabs. The box is built with its selected setup's command;
|
||||
// the choice rewrites the options of each command and its copy text, and is
|
||||
// remembered for the next box and the next page. Without this script the
|
||||
// picker stays hidden and the list of every command shows instead.
|
||||
|
||||
Reference in new issue
Block a user