Skip to content

Commit

Permalink
only check the config files corresponding to the currently installed …
Browse files Browse the repository at this point in the history
…version of Heroic
  • Loading branch information
Arbitrate3280 committed Jul 2, 2024
1 parent 6c2db6f commit 8e9e396
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions lutristosunshine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
COVERS_PATH = os.path.expanduser("~/.config/sunshine/covers")
DEFAULT_IMAGE = "default.png"
API_KEY_PATH = os.path.expanduser("~/.config/sunshine/steamgriddb_api_key.txt")
HEROIC_PATHS = [
# Flatpak paths
os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/legendaryConfig/legendary/installed.json"),
os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/gog_store/installed.json"),
os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/nile_config/nile/installed.json"),
os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/sideload_apps/library.json"),
# Native paths
os.path.expanduser("~/.config/heroic/legendaryConfig/legendary/installed.json"),
os.path.expanduser("~/.config/heroic/gog_store/installed.json"),
os.path.expanduser("~/.config/heroic/nile_config/nile/installed.json"),
os.path.expanduser("~/.config/heroic/sideload_apps/library.json")
]
HEROIC_PATHS = {
"flatpak": {
"legendary": os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/legendaryConfig/legendary/installed.json"),
"gog": os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/gog_store/installed.json"),
"nile": os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/nile_config/nile/installed.json"),
"sideload": os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/sideload_apps/library.json")
},
"native": {
"legendary": os.path.expanduser("~/.config/heroic/legendaryConfig/legendary/installed.json"),
"gog": os.path.expanduser("~/.config/heroic/gog_store/installed.json"),
"nile": os.path.expanduser("~/.config/heroic/nile_config/nile/installed.json"),
"sideload": os.path.expanduser("~/.config/heroic/sideload_apps/library.json")
}
}

# Ensure the covers directory exists
os.makedirs(COVERS_PATH, exist_ok=True)
Expand Down Expand Up @@ -139,12 +141,16 @@ def list_lutris_games() -> List[Tuple[str, str]]:
def list_heroic_games() -> List[Tuple[str, str, str, str]]:
"""List all games in Heroic."""
games = []
for path in HEROIC_PATHS:
heroic_cmd, installation_type = get_heroic_command()

if not heroic_cmd or not installation_type:
return games

for runner, path in HEROIC_PATHS[installation_type].items():
if os.path.exists(path):
try:
with open(path, 'r') as file:
data = json.load(file)
runner = get_runner_type(path)
if isinstance(data, dict):
if "installed" in data:
# Handling GOG games
Expand Down Expand Up @@ -293,27 +299,26 @@ def save_sunshine_apps(data: Dict) -> None:
with open(SUNSHINE_APPS_JSON_PATH, 'w') as file:
json.dump(data, file, indent=4)

def get_heroic_command(args: str = "") -> Optional[str]:
def get_heroic_command() -> Tuple[Optional[str], Optional[str]]:
"""Get the appropriate Heroic command based on installation type."""
# Check for Flatpak installation
if run_command("flatpak list | grep com.heroicgameslauncher.hgl").returncode == 0:
base_cmd = "flatpak run com.heroicgameslauncher.hgl"
return "flatpak run com.heroicgameslauncher.hgl", "flatpak"
# Check for native installation
elif run_command("which heroic").returncode == 0:
base_cmd = "heroic"
return "heroic", "native"
else:
return None

return f"{base_cmd} {args}".strip()
return None, None

return f"{base_cmd} {args}".strip(), installation_type

def add_game_to_sunshine(sunshine_data: Dict, game_id: str, game_name: str, image_path: str, runner: str) -> None:
"""Add a game to the Sunshine configuration."""
if runner == "Lutris":
lutris_cmd = get_lutris_command()
cmd = f"{lutris_cmd} lutris:rungameid/{game_id}"
else:
heroic_cmd = get_heroic_command()
heroic_cmd, _ = get_heroic_command()
cmd = f"{heroic_cmd} heroic://launch/{runner}/{game_id} --no-gui --no-sandbox"

new_app = {
Expand All @@ -330,7 +335,7 @@ def add_game_to_sunshine(sunshine_data: Dict, game_id: str, game_name: str, imag
def main():
try:
lutris_command = get_lutris_command()
heroic_command = get_heroic_command()
heroic_command, _ = get_heroic_command()

if not lutris_command and not heroic_command:
print("No Lutris or Heroic installation detected.")
Expand Down

0 comments on commit 8e9e396

Please sign in to comment.