diff --git a/RA3MP3Playback.py b/RA3MP3Playback.py index 9b1070b..9c27785 100644 --- a/RA3MP3Playback.py +++ b/RA3MP3Playback.py @@ -712,7 +712,35 @@ def main(): pass pygame.mixer.quit() +def has_terminal(): + return sys.stdout.isatty() and sys.stdin.isatty() + +def relaunch_in_terminal(): + # Detect the current folder and script/binary path + script = os.path.abspath(sys.argv[0]) + + # Choose a terminal emulator (Konsole, GNOME Terminal, xterm) + terminals = [ + ["konsole", "--hold", "-e"], + ["gnome-terminal", "--", "bash", "-c"], + ["xterm", "-hold", "-e"] + ] + + for term in terminals: + try: + subprocess.Popen(term + [script] + sys.argv[1:]) + sys.exit(0) # exit the current GUI-launched process + except FileNotFoundError: + continue + + # If no terminal found, just print a warning + print("No terminal emulator found. Please run from a terminal.") + if __name__ == "__main__": + if (os.name != "nt"): + if not has_terminal(): + relaunch_in_terminal() + lock_fd, lock_path = acquire_single_instance("q3a_launcher.lock") if lock_fd is None: print("Another instance is already running.")