Skip to content

Commit e4bd066

Browse files
committed
Try using the flatpak version of Lutris if it is discovered
1 parent 8adafac commit e4bd066

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

core/lutris.gd

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ func _init() -> void:
99

1010

1111
## Returns the command string to run Lutris
12-
func get_lutris_command() -> String:
13-
return "lutris"
12+
func get_lutris_command() -> LutrisCmd:
13+
if await _valid_lutris_cmd("lutris", []):
14+
return LutrisCmd.new("lutris")
15+
if await _valid_lutris_cmd("flatpak", ["run", "net.lutris.Lutris"]):
16+
return LutrisCmd.new("flatpak", ["run", "net.lutris.Lutris"])
17+
18+
return LutrisCmd.new("lutris")
1419

1520

1621
## Returns a list of locally install Lutris games
@@ -59,9 +64,17 @@ func get_games() -> Array[LutrisApp]:
5964
return games
6065

6166

62-
## Executes flatpak with the given arguments
67+
## Executes the lutris command with the given arguments
6368
func _exec(args: PackedStringArray) -> CmdOutput:
64-
var cmd := get_lutris_command()
69+
var lutris_cmd := await get_lutris_command()
70+
var cmd := lutris_cmd.cmd
71+
var arguments := lutris_cmd.args.duplicate()
72+
arguments.append_array(args)
73+
return await _exec_cmd(cmd, arguments)
74+
75+
76+
## Execute the given command and return its output
77+
func _exec_cmd(cmd: String, args: PackedStringArray) -> CmdOutput:
6578
logger.debug("Executing command: " + cmd + " " + " ".join(args))
6679
var output := []
6780
var code := await thread_pool.exec(OS.execute.bind(cmd, args, output)) as int
@@ -74,6 +87,28 @@ func _exec(args: PackedStringArray) -> CmdOutput:
7487
return cmd_out
7588

7689

90+
## Tries to execute the given Lutris command to see if it exists. This will
91+
## append the '--version' argument to the given command to see if it
92+
## executes successfully, indiciating that this command will work.
93+
func _valid_lutris_cmd(cmd: String, args: PackedStringArray) -> bool:
94+
var cmd_args := args.duplicate()
95+
cmd_args.push_back("--version")
96+
var cmd_output := await _exec_cmd(cmd, args)
97+
logger.debug("Executing command: " + cmd + " " + " ".join(args))
98+
99+
return cmd_output.code == 0
100+
101+
102+
## Structure that defines a lutris command
103+
class LutrisCmd extends RefCounted:
104+
var cmd: String
105+
var args: PackedStringArray
106+
107+
func _init(command: String, arguments: PackedStringArray = []) -> void:
108+
self.cmd = command
109+
self.args = arguments
110+
111+
77112
## Output of a lutris command
78113
class CmdOutput extends RefCounted:
79114
var code: int

plugin.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
22
"plugin.id": "lutris",
33
"plugin.name": "Lutris",
4-
"plugin.version": "1.0.0",
4+
"plugin.version": "1.0.1",
55
"plugin.min-api-version": "1.0.0",
66
"plugin.link": "https://github.com/ShadowBlip/OpenGamepadUI-lutris",
77
"plugin.source": "https://github.com/ShadowBlip/OpenGamepadUI-lutris",
88
"plugin.description": "Lutris Library plugin for OpenGamepadUI",
9-
"store.tags": ["lutris", "library"],
9+
"store.tags": [
10+
"lutris",
11+
"library"
12+
],
1013
"store.images": [],
1114
"author.name": "William Edwards",
1215
"author.email": "[email protected]",

0 commit comments

Comments
 (0)