Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Windows: a missing optional tool no longer greys the build button, and a grey button says why
LNPANDYd9258df6e5eb
diff --git a/frontend-qt/nspb_qt/model.py b/frontend-qt/nspb_qt/model.pyindex 67c621a4..542f80d8 100644--- a/frontend-qt/nspb_qt/model.py+++ b/frontend-qt/nspb_qt/model.py@@ -401,7 +401,10 @@ class Model(QObject):"""if not self.deps_checked or not self.deps:return False- return all(d.ok for d in self.deps)+ # Required rows only. An optional one (spirv-cross and glslangValidator, which only an OpenGL game+ # uses) never stops a build: counting it kept the button grey on a machine whose panel said+ # "everything required is installed", with nothing on screen to say why.+ return all(d.ok for d in self.deps if d.required)# ---- Windows toolchain rowsdiff --git a/frontend-qt/nspb_qt/ui.py b/frontend-qt/nspb_qt/ui.pyindex e9de6db7..39813f17 100644--- a/frontend-qt/nspb_qt/ui.py+++ b/frontend-qt/nspb_qt/ui.py@@ -610,20 +610,17 @@ class MainWindow(QMainWindow):self.deps_summary.setText('⚠ ' + self.m.t('dep.checkFailed'))self.deps_summary.setStyleSheet(f'color: {RED}; font-weight: 600;')elif self.m.all_deps_ok:- self.deps_summary.setText('● ' + self.m.t('dep.allReady'))+ # Every required row passed, so the build may start. An optional tool that is not installed+ # (glslangValidator for OpenGL games, spirv-cross) is said, but it is not a problem.+ optional = sum(1 for d in self.m.deps if not d.ok and not d.required)+ self.deps_summary.setText(self.m.t('dep.onlyOptional', optional) if optional+ else '● ' + self.m.t('dep.allReady'))self.deps_summary.setStyleSheet(f'color: {GREEN}; font-weight: 600;')else:- # Required only: an optional tool (glslangValidator for OpenGL games) or one that- # only some titles need (spirv-cross) was counted here, so a machine that could- # build the game in front of it read "缺 3 项" and looked broken.- n = sum(1 for d in self.m.deps if not d.ok and getattr(d, 'required', True))- optional = sum(1 for d in self.m.deps if not d.ok and not getattr(d, 'required', True))- if n == 0 and optional:- # nothing is actually blocking: saying "缺 0 项(另有 2 项可选)" reads like a- # problem where there is none- self.deps_summary.setText(self.m.t('dep.onlyOptional', optional))- self.deps_summary.setStyleSheet(f'color: {GREEN}; font-weight: 600;')- return+ # Required only: an optional tool or one that only some titles need was counted here, so a+ # machine that could build the game in front of it read "缺 3 项" and looked broken.+ n = sum(1 for d in self.m.deps if not d.ok and d.required)+ optional = sum(1 for d in self.m.deps if not d.ok and not d.required)self.deps_summary.setText(self.m.t('dep.missingOptional', n, optional) if optionalelse self.m.t('dep.missing', n))self.deps_summary.setStyleSheet(f'color: {RED}; font-weight: 600;')@@ -687,12 +684,18 @@ class MainWindow(QMainWindow):elif getattr(self, '_failed', False):pass # a failure message stays until the next build: it was being replaced by# the input reminder on the refresh that follows the failure (issue #52)- elif not self.m.base_path:- self.footer.setText(self.m.t('status.needInputs'))+ elif not self.m.deps_checked:+ self.footer.setText(self.m.t('status.checkingDeps'))+ elif not self.m.all_deps_ok:+ self.footer.setText(self.m.t('status.installFirst'))elif not self.m.repo_ok:self.footer.setText(self.m.t('status.chooseRepo'))+ elif not (self.m.game_folder is not None or (self.m.base_path and self.m.keys_path)):+ # what can_build asks for: a game folder, or the base package and the keys+ self.footer.setText(self.m.t('status.needInputs'))elif not self.footer.text() or self.footer.text() in (- self.m.t('status.needInputs'), self.m.t('status.chooseRepo')):+ self.m.t('status.needInputs'), self.m.t('status.chooseRepo'),+ self.m.t('status.checkingDeps'), self.m.t('status.installFirst')):self.footer.setText('')def _append_log(self, s: str) -> None:diff --git a/frontend-qt/tests/test_build_button.py b/frontend-qt/tests/test_build_button.pynew file mode 100644index 00000000..3de546f6--- /dev/null+++ b/frontend-qt/tests/test_build_button.py@@ -0,0 +1,115 @@+"""The Windows window's build button, and the line that says why it is grey.++The report: the panel said "everything required is installed (2 optional missing)", the game files+and the keys were chosen, and the build button stayed grey with nothing on the screen to say why. The+two optional rows (spirv-cross and glslangValidator, only an OpenGL game uses them) were counted by+`all_deps_ok`, so `can_build` was false. The same four conditions of `can_build` now each have a line.++Needs PySide6 and runs offscreen, skipped when PySide6 is absent.++ QT_QPA_PLATFORM=offscreen python3 -m unittest frontend-qt/tests/test_build_button.py -v+"""+from __future__ import annotations++import os+import sys+import unittest+from pathlib import Path+from unittest import mock++ROOT = Path(__file__).resolve().parents[2]+sys.path.insert(0, str(ROOT / 'frontend-qt'))+os.environ.setdefault('QT_QPA_PLATFORM', 'offscreen')++try:+ from PySide6.QtCore import QEvent+ from PySide6.QtWidgets import QApplication+except ImportError: # the packaged app always has it, a bare python3 may not+ QApplication = None++[email protected](QApplication is None, 'PySide6 is not installed')+class BuildButton(unittest.TestCase):+ @classmethod+ def setUpClass(cls):+ cls.app = QApplication.instance() or QApplication([])++ def _delete(self, m, w):+ w.close()+ w.deleteLater()+ m.deleteLater()+ self.app.sendPostedEvents(None, QEvent.DeferredDelete)+ self.app.processEvents()++ def _window(self, *, deps, checked=True, repo=True, base='a.nsp', keys='prod.keys'):+ from nspb_qt.i18n import Lang+ from nspb_qt.model import Model+ from nspb_qt.ui import MainWindow+ patches = [mock.patch.object(Model, 'check_deps', lambda self: None), # no probe thread: the rows are the test's+ mock.patch.object(Model, 'repo_ok', new_callable=mock.PropertyMock, return_value=repo)]+ for p in patches:+ p.start()+ self.addCleanup(p.stop)+ m = Model()+ m.lang = Lang('en') # these assertions read English whatever the device language is+ m.deps, m.deps_checked = deps, checked+ m.base_path, m.keys_path = base, keys+ w = MainWindow(m)+ self.addCleanup(self._delete, m, w)+ w.show()+ for _ in range(3):+ self.app.processEvents()+ w._refresh_deps()+ return m, w++ @staticmethod+ def _rows(*, required_missing=False, optional_missing=0):+ from nspb_qt.model import Dep, DepState+ rows = [Dep('python', 'dep.python', 'dep.python.hint', DepState.OK, 'python.exe'),+ Dep('zstd', 'dep.zstd.win', 'dep.zstd.hint.win', DepState.MISSING if required_missing else DepState.OK, '')]+ for pid in ('spirv-cross', 'glslangValidator')[:optional_missing]:+ rows.append(Dep(pid, 'dep.spirv.win', 'dep.spirv.hint.win', DepState.MISSING, '', required=False))+ return rows++ def test_the_button_is_on_when_only_optional_tools_are_missing(self):+ m, w = self._window(deps=self._rows(optional_missing=2))+ self.assertTrue(m.can_build)+ self.assertTrue(w.build_btn.isEnabled())+ self.assertIn('everything required is installed', w.deps_summary.text())+ self.assertIn('2 optional missing', w.deps_summary.text())++ def test_all_ready_when_nothing_is_missing(self):+ m, w = self._window(deps=self._rows())+ self.assertTrue(w.build_btn.isEnabled())+ self.assertIn('All ready', w.deps_summary.text())++ def test_a_missing_required_tool_greys_the_button_and_says_so(self):+ m, w = self._window(deps=self._rows(required_missing=True, optional_missing=2))+ self.assertFalse(w.build_btn.isEnabled())+ self.assertEqual(w.footer.text(), m.t('status.installFirst'))+ self.assertIn('1 missing', w.deps_summary.text())++ def test_checking_says_so(self):+ m, w = self._window(deps=[], checked=False)+ self.assertFalse(w.build_btn.isEnabled())+ self.assertEqual(w.footer.text(), m.t('status.checkingDeps'))++ def test_every_other_grey_button_has_a_line_too(self):+ m, w = self._window(deps=self._rows(), repo=False)+ self.assertFalse(w.build_btn.isEnabled())+ self.assertEqual(w.footer.text(), m.t('status.chooseRepo'))+ m, w = self._window(deps=self._rows(), keys='') # the base game is chosen, the keys are not+ self.assertFalse(w.build_btn.isEnabled())+ self.assertEqual(w.footer.text(), m.t('status.needInputs'))++ def test_the_line_goes_when_the_reason_does(self):+ m, w = self._window(deps=self._rows(required_missing=True))+ self.assertEqual(w.footer.text(), m.t('status.installFirst'))+ m.deps = self._rows()+ w._refresh_deps()+ self.assertTrue(w.build_btn.isEnabled())+ self.assertEqual(w.footer.text(), '', 'a line about a dependency does not stay once the dependency is there')+++if __name__ == '__main__':+ unittest.main()diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.pyindex 2c5ef500..a1a402d7 100644--- a/frontend-qt/tests/test_win.py+++ b/frontend-qt/tests/test_win.py@@ -1178,6 +1178,24 @@ class ToolchainProbeRobustnessTest(unittest.TestCase):self.assertTrue(self._all_deps_ok(good, True))self.assertFalse(self._all_deps_ok([Dep('a', 'k', 'h', DepState.MISSING, '')], True))+ def test_a_missing_optional_row_does_not_stop_the_build(self) -> None:+ """spirv-cross and glslangValidator are optional (only an OpenGL game uses them). With them missing and+ every required row present the panel says "everything required is installed", and the build button+ must be on: all_deps_ok counted them once, and the button stayed grey with no reason on the screen."""+ try:+ from nspb_qt.model import Dep, DepState+ except ModuleNotFoundError as e:+ if 'PySide6' in str(e):+ self.skipTest('PySide6 is not installed')+ raise+ good = Dep('python', 'k', 'h', DepState.OK, '')+ optional = [Dep('spirv-cross', 'k', 'h', DepState.MISSING, '', required=False),+ Dep('glslangValidator', 'k', 'h', DepState.MISSING, '', required=False)]+ self.assertTrue(self._all_deps_ok([good] + optional, True))+ self.assertFalse(self._all_deps_ok([good, Dep('zstd', 'k', 'h', DepState.MISSING, '')] + optional, True),+ 'a required row that is missing still stops it')+ self.assertFalse(self._all_deps_ok([good] + optional, False), 'unchecked is not ready')+class SdkCleanupTest(unittest.TestCase):"""A retry must start from an empty directory, even with git's read-only pack files.