From 0e2be04f9c7458c350abd22fb8d4c827b54c2ef3 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 16:11:56 +0100 Subject: [PATCH] fix: read the folder screen drives once --- install.ps1 | 2 +- install.py | 108 +++++++++++++++++++++++------------ install.sh | 2 +- install/launchers/index.json | 16 +++--- installer/tui_actions.py | 15 ++--- installer/tui_folder_scan.py | 67 ++++++++++++++++++++++ installer/tui_rows.py | 45 ++++++--------- installer/tui_screens.py | 4 +- installer/tui_state.py | 6 +- tests/test_install_tui.py | 28 ++++++++- wiki/architecture.md | 2 +- 11 files changed, 206 insertions(+), 89 deletions(-) create mode 100644 installer/tui_folder_scan.py diff --git a/install.ps1 b/install.ps1 index 4856c2836..e74cb728c 100644 --- a/install.ps1 +++ b/install.ps1 @@ -16,7 +16,7 @@ # and Invoke-WebRequest throws on a cut transfer before the hash is read: # the site's build rewrites this line there (scripts/sitebootstrap.py). $mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." - $defaultInstallSha256 = "9a5c17126ec0a23a3733bfa94cf96d260b562552a0a1014116c4ff305e8a7b0b" + $defaultInstallSha256 = "c71894b367adea17ac830c508aa2d7b7ff7fbfb1d0a8f7246b6a1a74a20af6f9" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. $maximumInstallerBytes = 8MB diff --git a/install.py b/install.py index faf5b1eb5..60bd4a152 100644 --- a/install.py +++ b/install.py @@ -13620,8 +13620,9 @@ class TuiState: # help and the bar say how to tap only then. self.mouse: bool = False self.list_top: dict = {} - # The mounted cards of that system, as last looked for. - self.cards: list | None = None + # The drives the folder screen lists, as last looked for: read when + # it opens and on Look again, never by a frame. + self.folder_scan: FolderScan | None = None # (width and text, lines) of the last pager wrapped. self.pager_cache: tuple | None = None self.path_text: str = "" @@ -24526,6 +24527,55 @@ def tui_removal_systems(state: TuiState) -> list[tuple[str, int, int]]: for system in sorted(held, key=titles.__getitem__)] +# --- installer/tui_folder_scan.py -------------------------------------------- + +class FolderScan(NamedTuple): + """What the mounted drives said when the folder screen last looked.""" + + # (mount, what its own files say) of the cards that run the system. + cards: tuple = () + # (mount, the systems it could be) of the drives two systems fit. + doubtful: tuple = () + # (mount, what it is) of the drives no system claims. + blank: tuple = () + # (row label, bios folder) of each share drive. + shares: tuple = () + # (row label, folder) of each drive, its label saying a missing folder. + drives: tuple = () + # The notes under the rows: drives left out, drives nothing proves. + notes: tuple = () + + +def scan_folder(state: TuiState) -> FolderScan: + """The mounted drives the folder screen lists, read once: a frame that + read them moved the rows under the focus when a stick was inserted, and + Enter acted on a row nobody chose.""" + bound = _tui_card_bound(state) + if bound: + mounts = mounted_cards_of(bound[0], state.platform) + doubtful = [mount for mount in doubt_cards(state.platform) if mount not in mounts] + taken = [*mounts, *doubtful] + return FolderScan( + cards=tuple((mount, _card_what(mount)) for mount in mounts), + doubtful=tuple((mount, _doubt_kinds(share_doubt(mount)[0])) for mount in doubtful), + blank=tuple((mount, _card_what(mount)) + for mount in blank_cards_of(bound[0], state.platform) + if mount not in taken)) + if state.folder_kind == "share": + return FolderScan(shares=tuple(share_targets(state.platform))) + drives = tuple((label if _is_dir(folder) else _said_with(label, "does not exist yet"), + folder) + for label, folder in folder_drives(state.os_type, state.platform, + state.folder_kind == "usual")) + notes = tuple(note for note in (drives_left_out(state.platform), unproven_words()) if note) + return FolderScan(drives=drives, notes=notes) + + +def card_mounts(scan: FolderScan) -> list[Path]: + """The mounts of the cards found running the system.""" + return [mount for mount, _what in scan.cards] + + # --- installer/tui_rows.py --------------------------------------------------- # The plan's two rows a beginner reads first: the README and the site name @@ -24573,27 +24623,20 @@ def _setup_screen_rows(state: TuiState) -> list[TuiRow]: return rows + [TuiRow("another", "Another setup or folder")] -def _card_screen_rows(state: TuiState, rows: list[TuiRow], - bound: tuple[str, str]) -> list[TuiRow]: +def _card_screen_rows(state: TuiState, rows: list[TuiRow], scan: FolderScan) -> list[TuiRow]: """The folder rows of a setup that runs from a card.""" # Only the cards whose own files say they run the system: A on the # first mount wrote Onion's layout on a muOS card. - mounts = (state.cards if state.cards is not None - else mounted_cards_of(bound[0], state.platform)) - cards = [TuiRow("card", f"{_mount_name(mount)} ({_card_what(mount)})", value=mount) - for mount in mounts] + cards = [TuiRow("card", f"{_mount_name(mount)} ({what})", value=mount) + for mount, what in scan.cards] # A drive this system and another both fit is its card, as --dest # takes it: "No KNULLI card is mounted" sat beside it. - doubtful = [mount for mount in doubt_cards(state.platform) if mount not in mounts] - cards += [TuiRow("card", f"{_mount_name(mount)} (could be " - f"{_doubt_kinds(share_doubt(mount)[0])})", value=mount) - for mount in doubtful] - mounts = [*mounts, *doubtful] + cards += [TuiRow("card", f"{_mount_name(mount)} (could be {kinds})", value=mount) + for mount, kinds in scan.doubtful] # On the device itself its folder is found, and no card is looked for. here = state.folder_default is not None and state.folder_kind == "found" - blank = [] if here else [ - TuiRow("card", f"{_mount_name(mount)} ({_card_what(mount)})", value=mount) - for mount in blank_cards_of(bound[0], state.platform) if mount not in mounts] + blank = [] if here else [TuiRow("card", f"{_mount_name(mount)} ({what})", value=mount) + for mount, what in scan.blank] rescan = [] if cards or here else [TuiRow("rescan", "Look again")] if blank: # A blank drive is listed for a system that fills its card when @@ -24605,15 +24648,14 @@ def _card_screen_rows(state: TuiState, rows: list[TuiRow], def _folder_screen_rows(state: TuiState) -> list[TuiRow]: - """The rows of the BIOS folder question.""" + """The rows of the BIOS folder question, from the drives last looked for.""" rows = [TuiRow("default", "Use this folder")] if state.folder_default else [] - bound = _tui_card_bound(state) + scan = state.folder_scan or FolderScan() if state.folder_kind == "share": # The drives mounted here first, each one's bios folder: the # share drive of a Batocera card or disk in a reader. - rows += [TuiRow("share", label, value=folder) - for label, folder in share_targets(state.platform)] - if not bound: + rows += [TuiRow("share", label, value=folder) for label, folder in scan.shares] + if not _tui_card_bound(state): # The drives mounted here, as line mode numbers them at the same # question, each by the BIOS folder its system reads, after the # Windows side's usual folder under WSL. @@ -24622,14 +24664,10 @@ def _folder_screen_rows(state: TuiState) -> list[TuiRow]: # Every row whose folder is missing says so, in both modes: the # Windows row alone did. drives = [] if state.folder_kind == "share" else [ - TuiRow("drive", label if _is_dir(folder) else _said_with(label, - "does not exist yet"), - value=folder) - for label, folder in folder_drives(state.os_type, state.platform, - state.folder_kind == "usual")] + TuiRow("drive", label, value=folder) for label, folder in scan.drives] return rows + [TuiRow("browse", "Browse for a folder"), TuiRow("type", "Type a path")] + drives - return _card_screen_rows(state, rows, bound) + return _card_screen_rows(state, rows, scan) def _browse_screen_rows(state: TuiState) -> list[TuiRow]: @@ -27462,7 +27500,7 @@ def _view_folder(state: TuiState, width: int, height: int) -> tuple: before = [f"No usual {name} folder here: browse for it or type it."] notes: list = [] if not bound and state.folder_kind != "share": - notes = [note for note in (drives_left_out(state.platform), unproven_words()) if note] + notes = list(state.folder_scan.notes) if state.folder_scan else [] body = _fitted_compose(state, width, height, before, notes, tui_rows(state), _status_after(state), state.refused) return (title, body, ("A/Enter Choose", "B/Esc Back", "? Help")) @@ -28743,6 +28781,7 @@ def _choose(state: TuiState, plat: str, dest: Path, proposed: bool = False) -> l # default beside it is one it does not, offered as "reads its BIOS # files from" and filled with Enter. state.folder_default, state.folder_kind = None, "closed" + state.folder_scan = scan_folder(state) return _push(state, "folder") card = card_system(dest) if card and card[0] == plat and card[1] != dest: @@ -28853,6 +28892,7 @@ def _choose_card(state: TuiState, folder: Path) -> list[tuple]: if state.stack and state.screen in ("folder", "browse", "path"): return [] state.folder_default, state.folder_kind = None, "usual" + state.folder_scan = scan_folder(state) return _push(state, "folder") return _take_card(state, choice, folder) @@ -28910,12 +28950,9 @@ def _open_folder_screen(state: TuiState, default: Path | None, else "") if system and not state.card_bound and card_bound(system, state.platform): state.card_bound = card_bound(system, state.platform) - # The cards are looked for when the screen opens and on Look again: a + # The drives are looked for when the screen opens and on Look again: a # card inserted meanwhile moved the rows under the focus. - state.cards = None - bound = _tui_card_bound(state) - if bound: - state.cards = mounted_cards_of(bound[0], state.platform) + state.folder_scan = scan_folder(state) refused = kind == "chosen" and (state.facts.get("writable") is False or _short_of_space(state, state.check or {})) # A folder just refused as full or read-only: Browse, not Use this @@ -29007,9 +29044,10 @@ def _rescan_cards(state: TuiState) -> list[tuple]: """Look again for the cards of the setup chosen.""" bound = _tui_card_bound(state) assert bound is not None - state.cards = mounted_cards_of(bound[0], state.platform) + state.folder_scan = scan_folder(state) + mounts = card_mounts(state.folder_scan) cards = [index for index, item in enumerate(tui_rows(state)) - if item.action == "card" and item.value in state.cards] + if item.action == "card" and item.value in mounts] state.focus["folder"] = cards[0] if cards else state.focus.get("folder", 0) state.status = ("" if cards else f"Still no {bound[0]} card " "is mounted.") diff --git a/install.sh b/install.sh index d78a960b7..25c917f46 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins # curl or wget stop on a cut transfer before the hash is read: the site's # build rewrites this line there (scripts/sitebootstrap.py). MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." -DEFAULT_INSTALL_SHA256="9a5c17126ec0a23a3733bfa94cf96d260b562552a0a1014116c4ff305e8a7b0b" +DEFAULT_INSTALL_SHA256="c71894b367adea17ac830c508aa2d7b7ff7fbfb1d0a8f7246b6a1a74a20af6f9" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. MAX_INSTALLER_BYTES=8388608 diff --git a/install/launchers/index.json b/install/launchers/index.json index cde2121bb..ec1d9d34e 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1448904, - "sha256": "9a5c17126ec0a23a3733bfa94cf96d260b562552a0a1014116c4ff305e8a7b0b", + "size": 1450660, + "sha256": "c71894b367adea17ac830c508aa2d7b7ff7fbfb1d0a8f7246b6a1a74a20af6f9", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1502529, - "sha256": "f5e68d76e05ceb75c2603a3bf502a0dc2ddeecf9afa6a8be342c651529e238aa" + "size": 1504285, + "sha256": "7d917bbb0d44d98fd2a21944e4bf475cf65a4c221fc975c656b5f21e17fe8798" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1448904, - "sha256": "9a5c17126ec0a23a3733bfa94cf96d260b562552a0a1014116c4ff305e8a7b0b", + "size": 1450660, + "sha256": "c71894b367adea17ac830c508aa2d7b7ff7fbfb1d0a8f7246b6a1a74a20af6f9", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1448904, - "sha256": "9a5c17126ec0a23a3733bfa94cf96d260b562552a0a1014116c4ff305e8a7b0b", + "size": 1450660, + "sha256": "c71894b367adea17ac830c508aa2d7b7ff7fbfb1d0a8f7246b6a1a74a20af6f9", "executable": false }, { diff --git a/installer/tui_actions.py b/installer/tui_actions.py index 7b0106634..f08949317 100644 --- a/installer/tui_actions.py +++ b/installer/tui_actions.py @@ -62,6 +62,7 @@ from installer.tui_choice import ( tui_choices, ) from installer.tui_commands import _tui_card, tui_flags, tui_pack_dir, tui_record_kept +from installer.tui_folder_scan import card_mounts, scan_folder from installer.tui_paint import _CHECK_FIELDS, _short_path, _styled from installer.tui_rows import ( TUI_TICK_ROWS, @@ -546,6 +547,7 @@ def _choose(state: TuiState, plat: str, dest: Path, proposed: bool = False) -> l # default beside it is one it does not, offered as "reads its BIOS # files from" and filled with Enter. state.folder_default, state.folder_kind = None, "closed" + state.folder_scan = scan_folder(state) return _push(state, "folder") card = card_system(dest) if card and card[0] == plat and card[1] != dest: @@ -656,6 +658,7 @@ def _choose_card(state: TuiState, folder: Path) -> list[tuple]: if state.stack and state.screen in ("folder", "browse", "path"): return [] state.folder_default, state.folder_kind = None, "usual" + state.folder_scan = scan_folder(state) return _push(state, "folder") return _take_card(state, choice, folder) @@ -713,12 +716,9 @@ def _open_folder_screen(state: TuiState, default: Path | None, else "") if system and not state.card_bound and card_bound(system, state.platform): state.card_bound = card_bound(system, state.platform) - # The cards are looked for when the screen opens and on Look again: a + # The drives are looked for when the screen opens and on Look again: a # card inserted meanwhile moved the rows under the focus. - state.cards = None - bound = _tui_card_bound(state) - if bound: - state.cards = mounted_cards_of(bound[0], state.platform) + state.folder_scan = scan_folder(state) refused = kind == "chosen" and (state.facts.get("writable") is False or _short_of_space(state, state.check or {})) # A folder just refused as full or read-only: Browse, not Use this @@ -810,9 +810,10 @@ def _rescan_cards(state: TuiState) -> list[tuple]: """Look again for the cards of the setup chosen.""" bound = _tui_card_bound(state) assert bound is not None - state.cards = mounted_cards_of(bound[0], state.platform) + state.folder_scan = scan_folder(state) + mounts = card_mounts(state.folder_scan) cards = [index for index, item in enumerate(tui_rows(state)) - if item.action == "card" and item.value in state.cards] + if item.action == "card" and item.value in mounts] state.focus["folder"] = cards[0] if cards else state.focus.get("folder", 0) state.status = ("" if cards else f"Still no {bound[0]} card " "is mounted.") diff --git a/installer/tui_folder_scan.py b/installer/tui_folder_scan.py new file mode 100644 index 000000000..881be1b8f --- /dev/null +++ b/installer/tui_folder_scan.py @@ -0,0 +1,67 @@ +"""The drives the folder screen offers, read when it opens and on Look again.""" +from __future__ import annotations + +from pathlib import Path +from typing import TYPE_CHECKING, NamedTuple + +from installer.cards import _doubt_kinds, share_doubt +from installer.destination import _card_what, blank_cards_of, doubt_cards, mounted_cards_of +from installer.host_fs import _is_dir +from installer.line_folder import ( + _said_with, + drives_left_out, + folder_drives, + share_targets, + unproven_words, +) +from installer.tui_choice import _tui_card_bound + +if TYPE_CHECKING: + from installer.tui_state import TuiState + + +class FolderScan(NamedTuple): + """What the mounted drives said when the folder screen last looked.""" + + # (mount, what its own files say) of the cards that run the system. + cards: tuple = () + # (mount, the systems it could be) of the drives two systems fit. + doubtful: tuple = () + # (mount, what it is) of the drives no system claims. + blank: tuple = () + # (row label, bios folder) of each share drive. + shares: tuple = () + # (row label, folder) of each drive, its label saying a missing folder. + drives: tuple = () + # The notes under the rows: drives left out, drives nothing proves. + notes: tuple = () + + +def scan_folder(state: TuiState) -> FolderScan: + """The mounted drives the folder screen lists, read once: a frame that + read them moved the rows under the focus when a stick was inserted, and + Enter acted on a row nobody chose.""" + bound = _tui_card_bound(state) + if bound: + mounts = mounted_cards_of(bound[0], state.platform) + doubtful = [mount for mount in doubt_cards(state.platform) if mount not in mounts] + taken = [*mounts, *doubtful] + return FolderScan( + cards=tuple((mount, _card_what(mount)) for mount in mounts), + doubtful=tuple((mount, _doubt_kinds(share_doubt(mount)[0])) for mount in doubtful), + blank=tuple((mount, _card_what(mount)) + for mount in blank_cards_of(bound[0], state.platform) + if mount not in taken)) + if state.folder_kind == "share": + return FolderScan(shares=tuple(share_targets(state.platform))) + drives = tuple((label if _is_dir(folder) else _said_with(label, "does not exist yet"), + folder) + for label, folder in folder_drives(state.os_type, state.platform, + state.folder_kind == "usual")) + notes = tuple(note for note in (drives_left_out(state.platform), unproven_words()) if note) + return FolderScan(drives=drives, notes=notes) + + +def card_mounts(scan: FolderScan) -> list[Path]: + """The mounts of the cards found running the system.""" + return [mount for mount, _what in scan.cards] diff --git a/installer/tui_rows.py b/installer/tui_rows.py index 4ece29124..304948a22 100644 --- a/installer/tui_rows.py +++ b/installer/tui_rows.py @@ -6,15 +6,13 @@ from collections.abc import Callable from pathlib import Path from typing import TYPE_CHECKING -from installer.cards import _doubt_kinds, _mount_name, _mounted_cards, share_doubt +from installer.cards import _doubt_kinds, _mount_name, _mounted_cards from installer.choices import recorded_axes from installer.cores import CORE_PLATFORMS -from installer.destination import _card_what, blank_cards_of, doubt_cards, mounted_cards_of +from installer.destination import _card_what from installer.handheld_app import APP_OFFER, APP_OFFER_SHORT -from installer.host_fs import _is_dir from installer.install_record import record_day from installer.invocation import offline_requested -from installer.line_folder import _said_with, folder_drives, share_targets from installer.manifest import GAME_DATA from installer.offline import LOCAL, _offline_only from installer.plan import CONFIRM_FROM_BYTES @@ -75,6 +73,7 @@ from installer.tui_commands import ( tui_flags, tui_record_kept, ) +from installer.tui_folder_scan import FolderScan from installer.tui_paint import _short_path from installer.tui_state import TUI_MAX_WIDTH, TuiRow, _matches @@ -126,27 +125,20 @@ def _setup_screen_rows(state: TuiState) -> list[TuiRow]: return rows + [TuiRow("another", "Another setup or folder")] -def _card_screen_rows(state: TuiState, rows: list[TuiRow], - bound: tuple[str, str]) -> list[TuiRow]: +def _card_screen_rows(state: TuiState, rows: list[TuiRow], scan: FolderScan) -> list[TuiRow]: """The folder rows of a setup that runs from a card.""" # Only the cards whose own files say they run the system: A on the # first mount wrote Onion's layout on a muOS card. - mounts = (state.cards if state.cards is not None - else mounted_cards_of(bound[0], state.platform)) - cards = [TuiRow("card", f"{_mount_name(mount)} ({_card_what(mount)})", value=mount) - for mount in mounts] + cards = [TuiRow("card", f"{_mount_name(mount)} ({what})", value=mount) + for mount, what in scan.cards] # A drive this system and another both fit is its card, as --dest # takes it: "No KNULLI card is mounted" sat beside it. - doubtful = [mount for mount in doubt_cards(state.platform) if mount not in mounts] - cards += [TuiRow("card", f"{_mount_name(mount)} (could be " - f"{_doubt_kinds(share_doubt(mount)[0])})", value=mount) - for mount in doubtful] - mounts = [*mounts, *doubtful] + cards += [TuiRow("card", f"{_mount_name(mount)} (could be {kinds})", value=mount) + for mount, kinds in scan.doubtful] # On the device itself its folder is found, and no card is looked for. here = state.folder_default is not None and state.folder_kind == "found" - blank = [] if here else [ - TuiRow("card", f"{_mount_name(mount)} ({_card_what(mount)})", value=mount) - for mount in blank_cards_of(bound[0], state.platform) if mount not in mounts] + blank = [] if here else [TuiRow("card", f"{_mount_name(mount)} ({what})", value=mount) + for mount, what in scan.blank] rescan = [] if cards or here else [TuiRow("rescan", "Look again")] if blank: # A blank drive is listed for a system that fills its card when @@ -158,15 +150,14 @@ def _card_screen_rows(state: TuiState, rows: list[TuiRow], def _folder_screen_rows(state: TuiState) -> list[TuiRow]: - """The rows of the BIOS folder question.""" + """The rows of the BIOS folder question, from the drives last looked for.""" rows = [TuiRow("default", "Use this folder")] if state.folder_default else [] - bound = _tui_card_bound(state) + scan = state.folder_scan or FolderScan() if state.folder_kind == "share": # The drives mounted here first, each one's bios folder: the # share drive of a Batocera card or disk in a reader. - rows += [TuiRow("share", label, value=folder) - for label, folder in share_targets(state.platform)] - if not bound: + rows += [TuiRow("share", label, value=folder) for label, folder in scan.shares] + if not _tui_card_bound(state): # The drives mounted here, as line mode numbers them at the same # question, each by the BIOS folder its system reads, after the # Windows side's usual folder under WSL. @@ -175,14 +166,10 @@ def _folder_screen_rows(state: TuiState) -> list[TuiRow]: # Every row whose folder is missing says so, in both modes: the # Windows row alone did. drives = [] if state.folder_kind == "share" else [ - TuiRow("drive", label if _is_dir(folder) else _said_with(label, - "does not exist yet"), - value=folder) - for label, folder in folder_drives(state.os_type, state.platform, - state.folder_kind == "usual")] + TuiRow("drive", label, value=folder) for label, folder in scan.drives] return rows + [TuiRow("browse", "Browse for a folder"), TuiRow("type", "Type a path")] + drives - return _card_screen_rows(state, rows, bound) + return _card_screen_rows(state, rows, scan) def _browse_screen_rows(state: TuiState) -> list[TuiRow]: diff --git a/installer/tui_screens.py b/installer/tui_screens.py index 4e360d2cd..cf0adca15 100644 --- a/installer/tui_screens.py +++ b/installer/tui_screens.py @@ -10,7 +10,7 @@ from installer.cards import _GAMES_PART_CARDS, card_setup, setup_bios_folder from installer.destination import card_where from installer.detect_os import detected_shown from installer.embedded import CARD_PLATFORMS, _a -from installer.line_folder import drives_left_out, share_words, side_name, unproven_words +from installer.line_folder import share_words, side_name from installer.manifest import OTHER_SYSTEMS from installer.offline import LOCAL from installer.outcome import _SHORT_DEFINITIONS @@ -208,7 +208,7 @@ def _view_folder(state: TuiState, width: int, height: int) -> tuple: before = [f"No usual {name} folder here: browse for it or type it."] notes: list = [] if not bound and state.folder_kind != "share": - notes = [note for note in (drives_left_out(state.platform), unproven_words()) if note] + notes = list(state.folder_scan.notes) if state.folder_scan else [] body = _fitted_compose(state, width, height, before, notes, tui_rows(state), _status_after(state), state.refused) return (title, body, ("A/Enter Choose", "B/Esc Back", "? Help")) diff --git a/installer/tui_state.py b/installer/tui_state.py index 293774290..3ab3af152 100644 --- a/installer/tui_state.py +++ b/installer/tui_state.py @@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, NamedTuple if TYPE_CHECKING: from installer.handheld_app import CardApp + from installer.tui_folder_scan import FolderScan from installer.tui_input import TuiHits @@ -128,8 +129,9 @@ class TuiState: # help and the bar say how to tap only then. self.mouse: bool = False self.list_top: dict = {} - # The mounted cards of that system, as last looked for. - self.cards: list | None = None + # The drives the folder screen lists, as last looked for: read when + # it opens and on Look again, never by a frame. + self.folder_scan: FolderScan | None = None # (width and text, lines) of the last pager wrapped. self.pager_cache: tuple | None = None self.path_text: str = "" diff --git a/tests/test_install_tui.py b/tests/test_install_tui.py index da4b79ddb..3b1a46304 100644 --- a/tests/test_install_tui.py +++ b/tests/test_install_tui.py @@ -3819,6 +3819,24 @@ class ACardSystemNamedOnAComputer(unittest.TestCase): self.assertEqual(effects, [("fetch", "retroarch")]) self.assertEqual(state.dest, device) + def test_a_stick_inserted_moves_no_row_until_look_again(self): + """A blank stick mounted while the folder screen was open moved the + rows on the next frame, and Enter on Look again opened the browser.""" + stick = self.card({"README.txt": ""}) + state = install.TuiState(os_type="linux", home=HOME) + state.platform, state.card_bound = "knulli", ("KNULLI", "bios") + with mock.patch.object(install, "_mounted_cards", return_value=[]): + install._open_folder_screen(state, None) + before = [row.label for row in install.tui_rows(state)] + state.focus["folder"] = before.index("Look again") + with mock.patch.object(install, "_mounted_cards", return_value=[stick]) as scan: + install.tui_view(state, 80, 24) + self.assertEqual([row.label for row in install.tui_rows(state)], before) + self.assertEqual(scan.call_count, 0) + install.tui_update(state, Key("enter")) + self.assertEqual(state.screen, "folder") + self.assertIn(stick, [row.value for row in install.tui_rows(state)]) + class TheSetupFilterKnowsDevices(unittest.TestCase): """The filter found nothing for steam deck, r36s, @@ -8151,6 +8169,7 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings, state.folder_default, state.folder_kind = SYSTEM_DIR, "usual" with mock.patch.object(install, "_mounted_cards", return_value=mounts), \ mock.patch.object(install, "_mount_points", return_value=frozenset()): + state.folder_scan = install.scan_folder(state) rows = install.tui_rows(state) screen = " ".join(install.tui_view(state, 120, 40)) state.focus["folder"] = next(index for index, row in enumerate(rows) @@ -8862,7 +8881,8 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings, state.platform, state.stack = "retroarch", ["folder"] state.folder_default, state.folder_kind = SYSTEM_DIR, "usual" with mock.patch.object(install, "_mounted_cards", return_value=mounts): - rows = install.tui_rows(state) + state.folder_scan = install.scan_folder(state) + rows = install.tui_rows(state) self.assertEqual([row.value for row in rows if row.action == "drive"], [stick / "bios"]) @@ -11772,7 +11792,8 @@ class TapsGameDataAndExitCodes(_CardFixtures, unittest.TestCase): state.platform, state.stack = "retroarch", ["folder"] state.folder_default, state.folder_kind = SYSTEM_DIR, "usual" with mock.patch.object(install, "_mounted_cards", return_value=[]): - rows = install.tui_rows(state) + state.folder_scan = install.scan_folder(state) + rows = install.tui_rows(state) self.assertIn(sides[0][1], [row.value for row in rows if row.action == "drive"]) @in_full @@ -12386,7 +12407,8 @@ class OneChoicePerRun(unittest.TestCase): state.folder_default, state.folder_kind = SYSTEM_DIR, "usual" with mock.patch.object(install, "_mounted_cards", return_value=[]), \ mock.patch.object(install, "_is_dir", return_value=False): - text = "\n".join(install.tui_view(state, 100, 30)) + state.folder_scan = install.scan_folder(state) + text = "\n".join(install.tui_view(state, 100, 30)) self.assertIn("Linux RetroArch usually reads its BIOS files from:", text) self.assertIn("(does not exist yet)", text) diff --git a/wiki/architecture.md b/wiki/architecture.md index ee1ab8f1e..ebed28cab 100644 --- a/wiki/architecture.md +++ b/wiki/architecture.md @@ -505,7 +505,7 @@ those it imports: | What a run keeps | `narrowing`, `choices`, `romm`, `install_record`, `game_files`, `games`, `tally` | | Line mode | `destination`, `line_folder`, `line_menu`, `plan_words`, `plan`, `outcome` | | Runs and actions | `arguments`, `run_setups`, `run_files`, `run`, `pack`, `removal`, `handheld_app`, `cli` | -| Full screen | `tui_state`, `tui_routes`, `tui_commands`, `tui_keys`, `tui_paint`, `tui_choice`, `tui_rows`, `tui_frame`, `tui_plan_view`, `tui_outcome`, `tui_screens`, `tui_actions`, `tui_input`, `tui_receive`, `tui_engine`, `tui_session` | +| Full screen | `tui_state`, `tui_routes`, `tui_commands`, `tui_keys`, `tui_paint`, `tui_choice`, `tui_folder_scan`, `tui_rows`, `tui_frame`, `tui_plan_view`, `tui_outcome`, `tui_screens`, `tui_actions`, `tui_input`, `tui_receive`, `tui_engine`, `tui_session` | ## Tests