feat: add support for Flatpak launcher.ini paths and introduce is_interactive helper to handle non-interactive environments correctly

This commit is contained in:
CPTN Cosmo 2026-04-18 16:04:44 +02:00
parent 5ea9f38a12
commit 7f4654f96e

View file

@ -138,18 +138,25 @@ def send_otp(secret):
print("Timed out waiting for XIVLauncher OTP prompt.") print("Timed out waiting for XIVLauncher OTP prompt.")
def check_and_update_launcher_ini(): def check_and_update_launcher_ini():
"""Checks ~/.xlcore/launcher.ini for IsOtpServer setting. """Checks launcher.ini for IsOtpServer setting.
If file is missing: prompts user to enable it manually in launcher. If file is missing: prompts user to enable it manually in launcher.
If file exists but setting is off: prompts user to auto-enable it. If file exists but setting is off: prompts user to auto-enable it.
""" """
ini_path = os.path.expanduser("~/.xlcore/launcher.ini") native_ini = os.path.expanduser("~/.xlcore/launcher.ini")
flatpak_ini = os.path.expanduser("~/.var/app/dev.goats.xivlauncher/data/xivlauncher/launcher.ini")
if not os.path.exists(ini_path): ini_path = None
print(f"\nConfiguration Check: '{ini_path}' not found.") if os.path.exists(native_ini):
ini_path = native_ini
elif os.path.exists(flatpak_ini):
ini_path = flatpak_ini
if not ini_path:
print(f"\nConfiguration Check: Could not find launcher.ini (checked ~/.xlcore and flatpak paths).")
print("Please open XIVLauncher, go to Settings, and enable 'Start internal OTP server'.") print("Please open XIVLauncher, go to Settings, and enable 'Start internal OTP server'.")
print("This is required for the wrapper to function.") print("This is required for the wrapper to function.")
if sys.stdin.isatty(): if is_interactive():
try: try:
input("Press Enter to continue once you have done this (or to try anyway)...") input("Press Enter to continue once you have done this (or to try anyway)...")
except EOFError: except EOFError:
@ -179,7 +186,7 @@ def check_and_update_launcher_ini():
print("XIVLauncher requires 'IsOtpServer' to be enabled to accept OTP codes from this wrapper.") print("XIVLauncher requires 'IsOtpServer' to be enabled to accept OTP codes from this wrapper.")
choice = 'n' choice = 'n'
if sys.stdin.isatty(): if is_interactive():
try: try:
choice = input("Enable 'IsOtpServer' now? [Y/n]: ").strip().lower() choice = input("Enable 'IsOtpServer' now? [Y/n]: ").strip().lower()
except EOFError: except EOFError:
@ -247,6 +254,10 @@ def is_steam_env():
return True return True
return False return False
def is_interactive():
"""Checks if we are in a truly interactive terminal session (not running under Steam)."""
return sys.stdin.isatty() and not is_steam_env()
def get_secret(config, config_path, allow_prompt=True): def get_secret(config, config_path, allow_prompt=True):
""" """
Retrieves the OTP secret in the following priority: Retrieves the OTP secret in the following priority:
@ -306,7 +317,7 @@ def get_secret(config, config_path, allow_prompt=True):
if not secret_input: if not secret_input:
print("GUI prompt unavailable or cancelled. Falling back to CLI.") print("GUI prompt unavailable or cancelled. Falling back to CLI.")
if not sys.stdin.isatty(): if not is_interactive():
print("Error: No interactive terminal available and GUI prompt failed. Cannot prompt for secret.") print("Error: No interactive terminal available and GUI prompt failed. Cannot prompt for secret.")
return None return None
@ -482,7 +493,7 @@ def main():
print(f"\n'{gamemode_cmd}' was detected on your system.") print(f"\n'{gamemode_cmd}' was detected on your system.")
print("Would you like to enable it for XIVLauncher? This can improve game performance.") print("Would you like to enable it for XIVLauncher? This can improve game performance.")
try: try:
if sys.stdin.isatty(): if is_interactive():
choice = input(f"Enable {gamemode_cmd}? [Y/n]: ").strip().lower() choice = input(f"Enable {gamemode_cmd}? [Y/n]: ").strip().lower()
else: else:
choice = 'y' # auto-enable if not interactive choice = 'y' # auto-enable if not interactive