Experimental support for launching from gui linux

This commit is contained in:
edschuy95 2026-01-22 01:39:51 -05:00
parent 55a5e6b9b3
commit 92cce93edd

View file

@ -712,7 +712,35 @@ def main():
pass pass
pygame.mixer.quit() 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 __name__ == "__main__":
if (os.name != "nt"):
if not has_terminal():
relaunch_in_terminal()
lock_fd, lock_path = acquire_single_instance("q3a_launcher.lock") lock_fd, lock_path = acquire_single_instance("q3a_launcher.lock")
if lock_fd is None: if lock_fd is None:
print("Another instance is already running.") print("Another instance is already running.")