diff --git a/docs/launcher.md b/docs/launcher.md index eba1e6d1..b2286527 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -43,7 +43,7 @@ Rebuild the Game, Settings); settings (update check, Hide Launcher While Playing Open Logs Folder, Uninstall, Back); uninstall (keep or remove the built game). Controls: the mouse (hover moves the cursor, a click selects); the keyboard (arrows, Enter or Space, Esc, F5 checks -for updates); an XInput gamepad (d-pad or left stick, A, B, Y). +for updates); an XInput gamepad (d-pad or left stick, A, B, Y) while the window is in front. `python -m launcher --selftest --shots DIR` draws every screen with made-up states and saves a PNG of each. diff --git a/launcher/ui/app.py b/launcher/ui/app.py index 9e6202c7..164a8084 100644 --- a/launcher/ui/app.py +++ b/launcher/ui/app.py @@ -809,7 +809,9 @@ class App: self.root.after(1000, self.watch_game) def watch_game(self): - if self.game_proc and self.game_proc.poll() is None: + # The game's own Restart ends the process started here and starts another (gfx_present.c gfx_window_closed) + gd = self.settings.get('game_dir') + if (self.game_proc and self.game_proc.poll() is None) or (gd and saves.game_running(gd)): self.root.after(1000, self.watch_game) return code = self.game_proc.returncode if self.game_proc else 0 diff --git a/tests/launcher_test.py b/tests/launcher_test.py index 11b4ba5a..37300e78 100644 --- a/tests/launcher_test.py +++ b/tests/launcher_test.py @@ -35,6 +35,7 @@ import time import unittest import zipfile from pathlib import Path +from unittest import mock ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) @@ -1708,6 +1709,25 @@ def have_display(): @unittest.skipUnless(have_display(), 'needs tkinter, numpy and a display') +class WhilePlayingTest(Tmp): + def test_the_games_restart_does_not_bring_the_launcher_back(self): + try: + from launcher.ui.app import App + except ImportError as e: + self.skipTest(f'no window toolkit: {e}') + a = mock.MagicMock() + a.settings = {'game_dir': str(self.tmp)} + a.game_proc = mock.MagicMock(returncode=0) + a.game_proc.poll.return_value = 0 # the process started here has ended + with mock.patch('launcher.ui.app.saves.game_running', return_value=True): + App.watch_game(a) # but the restarted game runs from the same exe + a.root.deiconify.assert_not_called() + a.root.after.assert_called_once() + with mock.patch('launcher.ui.app.saves.game_running', return_value=False): + App.watch_game(a) + a.root.deiconify.assert_called_once() + + class WindowTest(Tmp): def test_selftest(self): r = subprocess.run([sys.executable, '-m', 'launcher', '--root', str(self.tmp / 'w'), '--selftest'],