Added support for Flatpak custom commands (#5090)

This commit is contained in:
Quinn64 2023-10-25 17:22:14 -05:00 committed by GitHub
parent b870d29241
commit c09097491f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -62,7 +62,7 @@ class flatpak(Runner):
"help": _("Arguments to be passed to the application.") "help": _("Arguments to be passed to the application.")
}, },
{ {
"option": "command", "option": "fcommand",
"type": "string", "type": "string",
"label": _("Command"), "label": _("Command"),
"help": _("The command to run instead of the one listed in the application metadata."), "help": _("The command to run instead of the one listed in the application metadata."),
@ -108,10 +108,10 @@ class flatpak(Runner):
def game_path(self): def game_path(self):
if shutil.which("flatpak-spawn"): if shutil.which("flatpak-spawn"):
return "/" return "/"
install_type, application, arch, branch = ( install_type, application, arch, fcommand, branch = (
self.game_config.get(key, "") for key in ("install_type", "appid", "arch", "branch") self.game_config.get(key, "") for key in ("install_type", "appid", "arch", "fcommand", "branch")
) )
return os.path.join(self.install_locations[install_type or "user"], application, arch, branch) return os.path.join(self.install_locations[install_type or "user"], application, arch, fcommand, branch)
def remove_game_data(self, app_id=None, game_path=None, **kwargs): def remove_game_data(self, app_id=None, game_path=None, **kwargs):
if not self.is_installed(): if not self.is_installed():
@ -129,6 +129,7 @@ class flatpak(Runner):
branch = self.game_config.get("branch", "") branch = self.game_config.get("branch", "")
args = self.game_config.get("args", "") args = self.game_config.get("args", "")
appid = self.game_config.get("appid", "") appid = self.game_config.get("appid", "")
fcommand = self.game_config.get("fcommand", "")
if not appid: if not appid:
return {"error": "CUSTOM", "text": "No application specified."} return {"error": "CUSTOM", "text": "No application specified."}
@ -140,7 +141,7 @@ class flatpak(Runner):
if any(x in appid for x in ("--", "/")): if any(x in appid for x in ("--", "/")):
return {"error": "CUSTOM", "text": "Application ID field must not contain options or arguments."} return {"error": "CUSTOM", "text": "Application ID field must not contain options or arguments."}
command = _flatpak.get_run_command(appid, arch, branch) command = _flatpak.get_run_command(appid, arch, fcommand, branch)
if args: if args:
command.extend(split_arguments(args)) command.extend(split_arguments(args))
return {"command": command} return {"command": command}

View file

@ -64,12 +64,14 @@ def is_app_installed(appid):
return False return False
def get_run_command(appid, arch=None, branch=None): def get_run_command(appid, arch=None, fcommand=None, branch=None):
"""Return command to launch a Flatpak app""" """Return command to launch a Flatpak app"""
command = get_command() command = get_command()
command.append("run") command.append("run")
if arch: if arch:
command.append(f"--arch={arch}") command.append(f"--arch={arch}")
if fcommand:
command.append(f"--command={fcommand}")
if branch: if branch:
command.append(f"--branch={branch}") command.append(f"--branch={branch}")
command.append(appid) command.append(appid)