Hopefully close gracefully.

This commit is contained in:
Storm Dragon
2025-10-09 17:33:26 -04:00
parent c5b1a0af15
commit d1917ffc03

View File

@@ -941,8 +941,20 @@ class DoomLauncher(QMainWindow):
self.tobyVersion = TOBY_VERSION
self.speechHandler = SpeechHandler(self.configFile)
self.iwadSelector = IWADSelector() # Add IWAD selector
self.gameProcess = None # Track running game process
self.init_launcher_ui()
def closeEvent(self, event):
"""Handle application close event"""
# Terminate any running game process
if self.gameProcess and self.gameProcess.poll() is None:
try:
self.gameProcess.terminate()
self.gameProcess.wait(timeout=2)
except:
self.gameProcess.kill()
event.accept()
def check_and_fix_controls(self):
"""Check and fix control bindings in GZDoom configuration for all game types."""
if not self.configFile.exists():
@@ -1462,7 +1474,9 @@ class DoomLauncher(QMainWindow):
return
gameFiles.append(str(tobyMod))
# Handle map selection right after TobyAccMod if specified
selectedMapPath = None # Store map selection for later if needed
# Handle map selection - either now or store for later
if config.get('use_map_menu', False) and 'submenu' not in config:
mapFiles = ["None"] # Start with None option
mapsDir = self.gamePath / "Addons/MAPS"
@@ -1504,11 +1518,20 @@ class DoomLauncher(QMainWindow):
else:
mapPath = str(self.gamePath / "Addons/MAPS" / selectedMap)
if Path(mapPath).exists():
gameFiles.append(mapPath)
# Check if map should be added after files
if config.get('map_after_files', False):
selectedMapPath = mapPath # Store for later
else:
gameFiles.append(mapPath) # Add now (current behavior)
if selectedMap == "TobyDoomLevels.pk3":
musicRenamer = self.gamePath / "Toby-Doom-Level-Music-Renamer.pk3"
if musicRenamer.exists():
if config.get('map_after_files', False):
# Store renamer path along with map
if selectedMapPath:
selectedMapPath = [selectedMapPath, str(musicRenamer)]
else:
gameFiles.append(str(musicRenamer))
# Handle submenu if present
@@ -1564,6 +1587,13 @@ class DoomLauncher(QMainWindow):
gameFiles.append(str(optPath))
break # Only add the first optional file found
# Add map after files if specified (overrides earlier map packs)
if selectedMapPath:
if isinstance(selectedMapPath, list):
gameFiles.extend(selectedMapPath)
else:
gameFiles.append(selectedMapPath)
# Get any custom flags
gameFlags = config.get('flags', [])
@@ -2561,8 +2591,9 @@ class DoomLauncher(QMainWindow):
# Add script generation option to map selection dialog
generateScript = False
selectedMapPath = None # Store map selection for later if needed
# Handle map selection right after TobyAccMod if specified
# Handle map selection - either now or store for later
if config.get('use_map_menu', False) and 'submenu' not in config:
mapFiles = ["None"] # Start with None option
mapsDir = self.gamePath / "Addons/MAPS"
@@ -2618,11 +2649,20 @@ class DoomLauncher(QMainWindow):
else:
mapPath = str(self.gamePath / "Addons/MAPS" / selectedMap)
if Path(mapPath).exists():
gameFiles.append(mapPath)
# Check if map should be added after files
if config.get('map_after_files', False):
selectedMapPath = mapPath # Store for later
else:
gameFiles.append(mapPath) # Add now (current behavior)
if selectedMap == "TobyDoomLevels.pk3":
musicRenamer = self.gamePath / "Toby-Doom-Level-Music-Renamer.pk3"
if musicRenamer.exists():
if config.get('map_after_files', False):
# Store renamer path along with map
if selectedMapPath:
selectedMapPath = [selectedMapPath, str(musicRenamer)]
else:
gameFiles.append(str(musicRenamer))
# Handle submenu if present
@@ -2680,6 +2720,13 @@ class DoomLauncher(QMainWindow):
gameFiles.append(str(optPath))
break # Only add the first optional file found
# Add map after files if specified (overrides earlier map packs)
if selectedMapPath:
if isinstance(selectedMapPath, list):
gameFiles.extend(selectedMapPath)
else:
gameFiles.append(selectedMapPath)
# Get any custom flags
gameFlags = config.get('flags', [])
@@ -3180,6 +3227,9 @@ class DoomLauncher(QMainWindow):
env=dict(os.environ, PYTHONUNBUFFERED="1")
)
# Track the process for cleanup
self.gameProcess = process
# Start speech processing thread
speechThread = threading.Thread(
target=self.speechHandler.speak_thread,
@@ -3207,6 +3257,14 @@ if __name__ == "__main__":
# Converts version number to required format (e.g., 8.0 -> "8-0")
TOBY_VERSION: Final[str] = f"{int(TOBY_VERSION_NUMBER)}-{int(TOBY_VERSION_NUMBER * 10 % 10)}"
setproctitle("Toby Doom Launcher")
# Set up signal handling for clean shutdown
import signal
def signal_handler(sig, frame):
QApplication.quit()
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
app = QApplication(sys.argv)
window = DoomLauncher()
window.show()