Repository: lutris/lutris

Issue:
Regression of #3305? Or new issue/same behavior
### Bug description

[This issue](https://github.com/lutris/lutris/issues/3305) appears to have returned in 5.10.  Had 5.9 installed through manjaro pamac.  Removed and installed 5.10 through AUR script.  Launching Lutris shows all the new option of 5.10, but regardless of view (tree or icon), non of my games installed from 5.9 will bring up the context menu.  Even games I add as manual after install of 5.10 won't call up the context menu.  This even prevents removing/deleting from Lutris.





### How to Reproduce

Steps to reproduce the behavior:
Have 5.9 installed
Remove 5.9
Install 5.10 for AUR
Start Lutris
Click on any preinstalled game
Context menu does not appear


### Expected behavior

Context menu should appear.

### Log output

```shell
> INFO     2022-04-05 20:39:22,054 [startup.init_lutris:173]:Starting Lutris 0.5.10
> WARNING  2022-04-05 20:39:22,119 [libretro.get_libretro_cores:24]:No folder at /home/crono141/.local/share/lutris/runners/retroarch/
> DEBUG    2022-04-05 20:39:22,133 [xrandr._get_vidmodes:15]:Retrieving video modes from XrandR
> INFO     2022-04-05 20:39:22,177 [startup.check_driver:65]:Running AMD Mesa driver 21.3.7 on AMD Radeon RX 550 / 550 Series (POLARIS12, DRM 3.42.0, 5.15.28-1-MANJARO, LLVM 13.0.1) (0x699f)
> INFO     2022-04-05 20:39:22,177 [startup.check_driver:77]:GPU: 1002:699F 1028:1712 (amdgpu drivers)
> INFO     2022-04-05 20:39:22,242 [startup.update_runtime:213]:Startup complete
> DEBUG    2022-04-05 20:39:22,385 [lutriswindow.update_store:437]:Showing 8 games
> Traceback (most recent call last):
>   File "/usr/lib/python3.10/site-packages/lutris/gui/lutriswindow.py", line 399, in update_revealer
>     self.game_bar = GameBar(game, self.game_actions, self.application)
>   File "/usr/lib/python3.10/site-packages/lutris/gui/widgets/game_bar.py", line 61, in __init__
>     self.update_view()
>   File "/usr/lib/python3.10/site-packages/lutris/gui/widgets/game_bar.py", line 86, in update_view
>     self.play_button = self.get_play_button()
>   File "/usr/lib/python3.10/site-packages/lutris/gui/widgets/game_bar.py", line 226, in get_play_button
>     popover = self.get_popover(self.get_game_buttons(), popover_button)
>   File "/usr/lib/python3.10/site-packages/lutris/gui/widgets/game_bar.py", line 233, in get_game_buttons
>     displayed = self.game_actions.get_displayed_entries()
>   File "/usr/lib/python3.10/site-packages/lutris/game_actions.py", line 141, in get_displayed_entries
>     and not steam_shortcut.all_shortcuts_set(self.game)
>   File "/usr/lib/python3.10/site-packages/lutris/util/steam/shortcut.py", line 48, in all_shortcuts_set
>     shortcut_found = [
>   File "/usr/lib/python3.10/site-packages/lutris/util/steam/shortcut.py", line 50, in <listcomp>
>     if game.name in s['AppName']
> KeyError: 'AppName'
```


### System Information

```shell
> [System]
> OS:              Manjaro Linux 21.2.5 Qonos
> Arch:            x86_64
> Kernel:          5.15.28-1-MANJARO
> Desktop:         KDE
> Display Server:  x11
> 
> [CPU]
> Vendor:          GenuineIntel
> Model:           Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz
> Physical cores:  2
> Logical cores:   4
> 
> [Memory]
> RAM:             7.7 GB
> Swap:            0.5 GB
> 
> [Graphics]
> Vendor:          AMD
> OpenGL Renderer: AMD Radeon RX 550 / 550 Series (POLARIS12, DRM 3.42.0, 5.15.28-1-MANJARO, LLVM 13.0.1)
> OpenGL Version:  4.6 (Compatibility Profile) Mesa 21.3.7
> OpenGL Core:     4.6 (Core Profile) Mesa 21.3.7
> OpenGL ES:       OpenGL ES 3.2 Mesa 21.3.7
> Vulkan:          Supported
```


### Media (optional)

_No response_

### Checklist:

- [X] I'm not asking for support with a game or the wine runner.
- [X] I have followed the above mentioned guides and have all the graphics and wine dependencies installed.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.


Discussion:

Resolving patch:
diff --git a/lutris/util/steam/shortcut.py b/lutris/util/steam/shortcut.py
--- a/lutris/util/steam/shortcut.py
+++ b/lutris/util/steam/shortcut.py
@@ -32,7 +32,7 @@ def shortcut_exists(game, shortcut_path):
         shortcuts = vdf.binary_loads(shortcut_file.read())['shortcuts'].values()
     shortcut_found = [
         s for s in shortcuts
-        if game.name in s['AppName']
+        if matches_appname(s, game)
     ]
     if not shortcut_found:
         return False
@@ -47,7 +47,7 @@ def all_shortcuts_set(game):
             shortcuts = vdf.binary_loads(shortcut_file.read())['shortcuts'].values()
         shortcut_found = [
             s for s in shortcuts
-            if game.name in s['AppName']
+            if matches_appname(s, game)
         ]
         shortcuts_found += len(shortcut_found)
 
@@ -97,7 +97,7 @@ def remove_shortcut(game, shortcut_path):
         shortcuts = vdf.binary_loads(shortcut_file.read())['shortcuts'].values()
     shortcut_found = [
         s for s in shortcuts
-        if game.name in s['AppName']
+        if matches_appname(s, game)
     ]
 
     if not shortcut_found:
@@ -105,7 +105,7 @@ def remove_shortcut(game, shortcut_path):
 
     other_shortcuts = [
         s for s in shortcuts
-        if game.name not in s['AppName']
+        if not matches_appname(s, game)
     ]
     updated_shortcuts = {
         'shortcuts': {
@@ -145,6 +145,12 @@ def generate_shortcut(game):
     }
 
 
+def matches_appname(shortcut, game):
+    """Test if the game seems to be the one a shortcut refers to."""
+    appname = shortcut.get('AppName') or shortcut.get('appname')
+    return appname and game.name in appname
+
+
 def get_steam_shortcut_id(game):
     lutris_binary = shutil.which("lutris")
     exe = f'"{lutris_binary}"'


Test patch: