Repository: lutris/lutris

Issue:
Lutris can not launch a game through a .desktop file
Hello, first of all thank you for the amazing work you have done in the linux gaming scene.

When Lutris imports a game from the local source (a desktop file in .local/share/applications), it can not be launched.
I am using ULWGL for launching the game through the desktop file.

[Desktop Entry]
Type=Application
Categories=Game
Name=Grim Dawn
Icon=/usr/share/icons/Papirus-Dark/16x16/places/folder-games.svg
Path=/HDD/GranAlmacen/Juegos/Grim Dawn
Exec=env GAMEID="" WINEPREFIX="/HDD/GranAlmacen/Juegos/Grim Dawn/wine" ulwgl-run-cli "x64/Grim Dawn.exe"

Cheers !


Discussion:
> first of all thank you for the amazing work you have done in the linux gaming scene.

Thanks!

> When Lutris imports a game from the local source (a desktop file in .local/share/applications), it can not be launched.

Why? What happens when you try to run the game? Have you tried disabling the Lutris runtime in the game's system options? 

>  I am using ULWGL for launching the game through the desktop file.

That's not really how we plan to support ULWGL, you can setup your game in Lutris by having ULWGL in the correct location (~/.local/share/lutris/runtime/ulwgl but this is temporary, we're not going to ship ulwgl in the lutris runtime and will be distributed independently.) Once you have ULWGL, you need to select Proton-GE in the game's option and it will use ULWGL automatically.
Alright, I got the bug. Lutris misses the variable `Path` from the desktop file, that is why it does not launch. If I manually set the "Working directory" in Lutris game config, it works. It would be nice if it automatically set the working directory from the desktop file's Path variable.

Yeah, I know that I am not using ULWGL in Lutris in a formal way, but when I copy entire games folders from one computer to another, to be able to install them it is easier for me to just change the paths from the desktop files using repgrep, drop them in ~/.local/share/applications, and import them in Lutris from the local source.

Thank you very much for everything. Nice interview you had with Brodie, very interesting !
Have a nice day.
> Lutris misses the variable Path from the desktop file

I see, that is probably something we should support. 
> Thank you very much for everything. Nice interview you had with Brodie, very interesting !

I enjoyed doing this interview :D
That's not a bug and not a lutris desktop launcher, but incorrect wine launcher.
A proper lutris desktop launcher looks like this and is working on my machine:
```shell
[Desktop Entry]
Type=Application
Name=Grim Dawn
Icon=/home/fendrick/pictures/Icons/grimdawn_gray_256.png
Exec=env LUTRIS_SKIP_INIT=1 lutris lutris:rungameid/11
Categories=Game
``` 
It is about adding a game through the "local source" from Lutris.
Just as a heads up. I'm giving up on this ticket. I don't use the Local Source service, and I don't want to create a weird looking desktop shortcut to repro the issue. Simple workaround is to put absolute paths in your .desktop file.

I hate the Gio API too much to be working on this. Anyone else is welcome to provide a patch.

Resolving patch:
diff --git a/lutris/services/xdg.py b/lutris/services/xdg.py
--- a/lutris/services/xdg.py
+++ b/lutris/services/xdg.py
@@ -115,6 +115,7 @@ def generate_installer(self, db_game):
                 "game": {
                     "exe": details["exe"],
                     "args": details["args"],
+                    "working_dir": details["path"],
                 },
                 "system": {"disable_runtime": True},
             },
@@ -152,14 +153,27 @@ def new_from_xdg_app(cls, xdg_app):
         service_game.appid = get_appid(xdg_app)
         service_game.slug = cls.get_slug(xdg_app)
         exe, args = cls.get_command_args(xdg_app)
+        path = cls.get_desktop_entry_path(xdg_app)
         service_game.details = json.dumps(
             {
                 "exe": exe,
                 "args": args,
+                "path": path,
             }
         )
         return service_game
 
+    @staticmethod
+    def get_desktop_entry_path(xdg_app):
+        """Retrieve the Path variable from the .desktop file"""
+        desktop_entry = xdg_app.get_filename()
+        with open(desktop_entry, 'r') as f:
+            contents = f.read()
+            match = re.search(r'^Path=(.*)$', contents, re.MULTILINE)
+            if match:
+                return match.group(1)
+        return None
+
     @staticmethod
     def get_command_args(app):
         """Return a tuple with absolute command path and an argument string"""


Test patch: