diff --git a/rockethype/local/bin/menugames b/rockethype/local/bin/menugames index d4ce398..11d63b8 100755 --- a/rockethype/local/bin/menugames +++ b/rockethype/local/bin/menugames @@ -1,21 +1,37 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import json import os import subprocess +import sys -tmp = os.popen("lutris -ojl").read() -games = json.loads(tmp) - -gameslist = "" -concat = "" -for item in games: - gameslist = gameslist + concat + item["name"] - concat = "\n" - -tmp = subprocess.getoutput("echo \"" + gameslist + "\" | wofi -n -d -p \"Select Game:\"") - -for item in games: - if item["name"] == tmp: - subprocess.Popen(["lutris","lutris:rungameid/" + str(item["id"])]) - break +try: + # Получаем список игр + result = subprocess.run(["lutris", "-ojl"], capture_output=True, text=True) + games = json.loads(result.stdout) + + # Формируем список названий + game_names = [game["name"] for game in games] + games_list = "\n".join(game_names) + + # Выбор игры через wofi + wofi_process = subprocess.Popen( + ["wofi", "-n", "-d", "-p", "Select Game:"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + text=True + ) + selected_game, _ = wofi_process.communicate(input=games_list) + selected_game = selected_game.strip() + + if not selected_game: + sys.exit(0) + + # Запускаем выбранную игру + for game in games: + if game["name"] == selected_game: + subprocess.Popen(["lutris", f"lutris:rungameid/{game['id']}"]) + break +except Exception as e: + print(f"Error: {e}", file=sys.stderr) + sys.exit(1)