fix: hold the offline choice in the screen state

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 21:42:19 +01:00
1 parent f0ab5181ab
commit 6e0b0724de
9 files changed
+74 -39

No files matched your search

+1 -1
View File
@@ -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 = "a14ac854879a2da7bb858b1a446d93175ffee13274cf09048636ce57fe4df397"
$defaultInstallSha256 = "b5dd1137457019ae36cfff7bb22c32054865bd891353786ab5ab3566d9af5980"
# 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
+16 -12
View File
@@ -14115,6 +14115,10 @@ class TuiState:
# (--add-app, the options), what putting it did (the app event),
# and the card, read once per folder.
self.add_app: bool = False
# Without the internet: read from --offline or the variable when the
# screens start, changed by the option. The 'offline' effect writes
# it for the runs, and the check is stale whenever it moves.
self.offline: bool = offline_requested()
self.app: dict | None = None
self.app_running: bool = False
self.card_for: Path | None = None
@@ -24103,10 +24107,7 @@ def tui_flags(state: TuiState) -> list[tuple[str, str | None]]:
# the runs, whose own reading of the record would narrow it again.
flags.append(("--all-files", None))
flags += [("--from", str(folder)) for folder in state.from_folders]
if (os.environ.get(OFFLINE_VARIABLE) == OFFLINE_FLAG_VALUE
and not any(flag == "--offline" for flag, _v in flags)):
# Given as --offline: said so in the command. Set as the variable,
# the runs inherit it and the words name it.
if state.offline and not any(flag == "--offline" for flag, _v in flags):
flags.append(("--offline", None))
return flags
@@ -24157,9 +24158,6 @@ def tui_hint(state: TuiState) -> Invocation:
hint.options += tui_flags(state)
if state.add_app and _tui_app_ready(state):
hint.options.append(("--add-app", None))
# The runs inherit the variable, a command shown to the user does not.
if offline_option(False) and ("--offline", None) not in hint.options:
hint.options.append(("--offline", None))
return hint
@@ -25107,6 +25105,11 @@ def _core_screen_rows(state: TuiState) -> list[TuiRow]:
return rows + _CHECKLIST_END
def _tui_offline_only(state: TuiState) -> bool:
"""Without the internet and without a pack: what is not here cannot come."""
return state.offline and LOCAL.pack is None
def _confirm_screen_rows(state: TuiState) -> list[TuiRow]:
"""The rows of the confirm screen."""
if state.running or state.dry is None:
@@ -25115,7 +25118,7 @@ def _confirm_screen_rows(state: TuiState) -> list[TuiRow]:
# Counted again, every file is in place: Install wrote nothing
# and said Done.
return [TuiRow("close", "Close"), TuiRow("back", "Back")]
if _offline_only() and not _dry_copies(state):
if _tui_offline_only(state) and not _dry_copies(state):
# The plan's rule: Install would only fail every file.
return [TuiRow("back", "Back")]
return [TuiRow("install", "Install"), TuiRow("back", "Back")]
@@ -25190,7 +25193,7 @@ def _plan_rows(state: TuiState) -> list[TuiRow]:
label = (f"{TUI_INSTALL_ROW} {format_size(size)}" if size >= CONFIRM_FROM_BYTES
else TUI_INSTALL_ROW)
rows = [TuiRow("install", label)]
if _offline_only() and not _plan_copies(state, check):
if _tui_offline_only(state) and not _plan_copies(state, check):
# Nothing here to copy, and the network refused: Install would
# only fail every file, in this folder or another.
rows = []
@@ -25440,8 +25443,8 @@ def _option_rows(state: TuiState) -> list[TuiRow]:
# and the focus stays on the row just changed.
how = [TuiRow("offline", "Without the internet: "
+ ("yes, a pack is read" if LOCAL.pack is not None
else _yes(offline_requested())), "--offline")]
if not LOCAL.offline:
else _yes(state.offline)), "--offline")]
if LOCAL.pack is None and not state.offline:
# From a pack, or offline, nothing is downloaded.
how.append(TuiRow("jobs", f"Parallel downloads: {state.jobs}", "--jobs"))
see = [TuiRow("preview", "Preview the file list", "--dry-run"),
@@ -29805,7 +29808,7 @@ def _option_flag(state: TuiState, action: str, step: int) -> bool:
def _option_offline(state: TuiState, step: int) -> list[tuple]:
"""Without the internet, turned on or off."""
on = step > 0 if step else not offline_requested()
on = step > 0 if step else not state.offline
if (on and state.target and not state.manifest_given and not state.packs
and not (state.targets_for == state.platform and state.targets)):
# The run reads the board list beside the file list it is
@@ -29816,6 +29819,7 @@ def _option_offline(state: TuiState, step: int) -> list[tuple]:
return []
# Set in this process by the effect, as --offline sets it: the
# runs started next inherit it, and their command names it.
state.offline = on
return [("offline", on)]
+1 -1
View File
@@ -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="a14ac854879a2da7bb858b1a446d93175ffee13274cf09048636ce57fe4df397"
DEFAULT_INSTALL_SHA256="b5dd1137457019ae36cfff7bb22c32054865bd891353786ab5ab3566d9af5980"
# 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
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1470139,
"sha256": "a14ac854879a2da7bb858b1a446d93175ffee13274cf09048636ce57fe4df397",
"size": 1470260,
"sha256": "b5dd1137457019ae36cfff7bb22c32054865bd891353786ab5ab3566d9af5980",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1523764,
"sha256": "feeeaa00566d25edb643e86b7882c92ceb77b963f64515991292703c87eaa91c"
"size": 1523885,
"sha256": "d79004b77c356c6493576608f7265590abdb25e9c823427676b9a492e5885e01"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1470139,
"sha256": "a14ac854879a2da7bb858b1a446d93175ffee13274cf09048636ce57fe4df397",
"size": 1470260,
"sha256": "b5dd1137457019ae36cfff7bb22c32054865bd891353786ab5ab3566d9af5980",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1470139,
"sha256": "a14ac854879a2da7bb858b1a446d93175ffee13274cf09048636ce57fe4df397",
"size": 1470260,
"sha256": "b5dd1137457019ae36cfff7bb22c32054865bd891353786ab5ab3566d9af5980",
"executable": false
},
{
+3 -2
View File
@@ -36,7 +36,7 @@ from installer.frontend_folders import _retroarch_config_at
from installer.games import games_probe
from installer.host_fs import _exists, _folder_writable, _is_dir, _nearest_folder, closed_folder
from installer.install_record import RECORD_NARROWING, _RECORD_SAID, record_options, setup_record
from installer.invocation import OFFLINE_VARIABLE, offline_requested
from installer.invocation import OFFLINE_VARIABLE
from installer.lists import local_targets
from installer.offline import LOCAL, OFFLINE_FLAG_VALUE
from installer.pack import _listed
@@ -1187,7 +1187,7 @@ def _option_flag(state: TuiState, action: str, step: int) -> bool:
def _option_offline(state: TuiState, step: int) -> list[tuple]:
"""Without the internet, turned on or off."""
on = step > 0 if step else not offline_requested()
on = step > 0 if step else not state.offline
if (on and state.target and not state.manifest_given and not state.packs
and not (state.targets_for == state.platform and state.targets)):
# The run reads the board list beside the file list it is
@@ -1198,6 +1198,7 @@ def _option_offline(state: TuiState, step: int) -> list[tuple]:
return []
# Set in this process by the effect, as --offline sets it: the
# runs started next inherit it, and their command names it.
state.offline = on
return [("offline", on)]
+3 -9
View File
@@ -11,8 +11,8 @@ from installer.choices import choosable_cores, emulator_names
from installer.handheld_app import card_app
from installer.host_fs import _is_dir
from installer.install_record import RECORD_NARROWING, record_argv, record_options
from installer.invocation import OFFLINE_VARIABLE, Invocation, offline_option
from installer.offline import LOCAL, OFFLINE_FLAG_VALUE
from installer.invocation import Invocation
from installer.offline import LOCAL
from installer.tally import leave_out_game_data
from installer.tui_routes import TUI_LIST_ENV, TUI_RECORD_ENV
@@ -78,10 +78,7 @@ def tui_flags(state: TuiState) -> list[tuple[str, str | None]]:
# the runs, whose own reading of the record would narrow it again.
flags.append(("--all-files", None))
flags += [("--from", str(folder)) for folder in state.from_folders]
if (os.environ.get(OFFLINE_VARIABLE) == OFFLINE_FLAG_VALUE
and not any(flag == "--offline" for flag, _v in flags)):
# Given as --offline: said so in the command. Set as the variable,
# the runs inherit it and the words name it.
if state.offline and not any(flag == "--offline" for flag, _v in flags):
flags.append(("--offline", None))
return flags
@@ -132,9 +129,6 @@ def tui_hint(state: TuiState) -> Invocation:
hint.options += tui_flags(state)
if state.add_app and _tui_app_ready(state):
hint.options.append(("--add-app", None))
# The runs inherit the variable, a command shown to the user does not.
if offline_option(False) and ("--offline", None) not in hint.options:
hint.options.append(("--offline", None))
return hint
+10 -6
View File
@@ -12,9 +12,8 @@ from installer.cores import CORE_PLATFORMS
from installer.destination import _card_what
from installer.handheld_app import APP_OFFER, APP_OFFER_SHORT
from installer.install_record import record_day
from installer.invocation import offline_requested
from installer.manifest import GAME_DATA
from installer.offline import LOCAL, _offline_only
from installer.offline import LOCAL
from installer.plan import CONFIRM_FROM_BYTES
from installer.plan_words import cores_words
from installer.platforms import TARGET_PLATFORMS, _tui_system_label, system_title
@@ -243,6 +242,11 @@ def _core_screen_rows(state: TuiState) -> list[TuiRow]:
return rows + _CHECKLIST_END
def _tui_offline_only(state: TuiState) -> bool:
"""Without the internet and without a pack: what is not here cannot come."""
return state.offline and LOCAL.pack is None
def _confirm_screen_rows(state: TuiState) -> list[TuiRow]:
"""The rows of the confirm screen."""
if state.running or state.dry is None:
@@ -251,7 +255,7 @@ def _confirm_screen_rows(state: TuiState) -> list[TuiRow]:
# Counted again, every file is in place: Install wrote nothing
# and said Done.
return [TuiRow("close", "Close"), TuiRow("back", "Back")]
if _offline_only() and not _dry_copies(state):
if _tui_offline_only(state) and not _dry_copies(state):
# The plan's rule: Install would only fail every file.
return [TuiRow("back", "Back")]
return [TuiRow("install", "Install"), TuiRow("back", "Back")]
@@ -326,7 +330,7 @@ def _plan_rows(state: TuiState) -> list[TuiRow]:
label = (f"{TUI_INSTALL_ROW} {format_size(size)}" if size >= CONFIRM_FROM_BYTES
else TUI_INSTALL_ROW)
rows = [TuiRow("install", label)]
if _offline_only() and not _plan_copies(state, check):
if _tui_offline_only(state) and not _plan_copies(state, check):
# Nothing here to copy, and the network refused: Install would
# only fail every file, in this folder or another.
rows = []
@@ -576,8 +580,8 @@ def _option_rows(state: TuiState) -> list[TuiRow]:
# and the focus stays on the row just changed.
how = [TuiRow("offline", "Without the internet: "
+ ("yes, a pack is read" if LOCAL.pack is not None
else _yes(offline_requested())), "--offline")]
if not LOCAL.offline:
else _yes(state.offline)), "--offline")]
if LOCAL.pack is None and not state.offline:
# From a pack, or offline, nothing is downloaded.
how.append(TuiRow("jobs", f"Parallel downloads: {state.jobs}", "--jobs"))
see = [TuiRow("preview", "Preview the file list", "--dry-run"),
+6
View File
@@ -6,6 +6,8 @@ import unicodedata
from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple
from installer.invocation import offline_requested
if TYPE_CHECKING:
from installer.handheld_app import CardApp
from installer.tui_folder_scan import FolderScan
@@ -294,6 +296,10 @@ class TuiState:
# (--add-app, the options), what putting it did (the app event),
# and the card, read once per folder.
self.add_app: bool = False
# Without the internet: read from --offline or the variable when the
# screens start, changed by the option. The 'offline' effect writes
# it for the runs, and the check is stale whenever it moves.
self.offline: bool = offline_requested()
self.app: dict | None = None
self.app_running: bool = False
self.card_for: Path | None = None
+26
View File
@@ -2976,6 +2976,7 @@ class CardsSpaceAndConfirm(unittest.TestCase):
short of space then put "Install anyway" back, a run that could
only fail every file."""
state = checked_state({"free": 1024, "writable": False, "cores": []})
state.offline = True
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}):
labels = [row.label for row in install.tui_rows(state)]
self.assertEqual(labels[0], "Choose another folder")
@@ -4305,6 +4306,23 @@ class OfflineInTheInterface(unittest.TestCase):
self.assertIn("--offline", install.tui_command(state))
class OfflineToggleStalesTheCheck(unittest.TestCase):
"""Turning the network back on changes the run, however offline was set:
the variable alone left the check current and Install skipped Confirm."""
def test_each_way_offline_was_set(self):
for value in ("1", install.OFFLINE_FLAG_VALUE):
with self.subTest(value=value), \
mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: value}):
state = install.TuiState()
state.checked_flags = install.tui_flags(state)
self.assertIn(("--offline", None), state.checked_flags)
self.assertEqual(install._option_offline(state, 0), [("offline", False)])
install.set_offline(False)
self.assertNotIn(("--offline", None), install.tui_flags(state))
self.assertEqual(install._begin_install(state), [("run", "confirm")])
class BackTicksAndSaveFolder(unittest.TestCase):
"""Going back keeps the ticks, and the save folder is said once."""
@@ -4361,6 +4379,7 @@ class BackTicksAndSaveFolder(unittest.TestCase):
state.stack.append("confirm")
state.dry = dict(CHECK)
state.dry_files = [dict(event, state="missing") for event in FILES]
state.offline = True
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}):
rows = [row.action for row in install.tui_rows(state)]
text = " ".join(" ".join(install.tui_view(state, 120, 40)).split())
@@ -6831,6 +6850,9 @@ class ConfirmRefusalsAndCardRows(unittest.TestCase):
def test_offline_with_nothing_on_hand_runs_nothing_from_the_list(self):
state = checked_state()
# Checked offline: the counts read are those of an offline run.
state.offline = True
state.checked_flags = install.tui_flags(state)
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}):
state.focus["plan"] = [row.action for row in install.tui_rows(state)].index(
"systems")
@@ -9649,6 +9671,7 @@ class PacksWordingAndDocs(unittest.TestCase):
state = checked_state()
state.stack.append("confirm")
state.dry = dict(CHECK)
state.offline = True
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}):
self.assertIn("Nothing to install", install.tui_view(state, 80, 24)[0])
@@ -10638,6 +10661,7 @@ class CardNamesAndHelp(_CardFixtures, unittest.TestCase):
state.stack.append("options")
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: ""}):
self.assertIn("jobs", [row.action for row in install.tui_rows(state)])
state.offline = True
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}):
self.assertNotIn("jobs", [row.action for row in install.tui_rows(state)])
@@ -11693,6 +11717,7 @@ class TapsGameDataAndExitCodes(_CardFixtures, unittest.TestCase):
"""Sudo resets the environment, and the root
command the screen gave fetched what the offline run left out."""
state = checked_state({"free": 50 * 1024 ** 3, "writable": False, "cores": []})
state.offline = True
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}), \
mock.patch.object(install, "_on_read_only_mount", return_value=False):
text = " ".join(" ".join(install.tui_view(state, 120, 40)).split())
@@ -14716,6 +14741,7 @@ class ProvenCardsAndCounts(unittest.TestCase):
line = install.Invocation()
line.os_type = "linux"
line.record(args)
state.offline = True
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}):
line.options.append(("--offline", None))
self.assertEqual(install.tui_command(state), line.command("retroarch", SYSTEM_DIR))