From 20f1ce6e83fc145cf430565efc9451418c256d1d Mon Sep 17 00:00:00 2001 From: kramo Date: Mon, 21 Aug 2023 16:04:46 +0200 Subject: [PATCH] Deskop importer cleanups --- src/importer/sources/desktop_source.py | 67 ++++++++++++++++++++------ 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/importer/sources/desktop_source.py b/src/importer/sources/desktop_source.py index 6c0dbd8..32a2dab 100644 --- a/src/importer/sources/desktop_source.py +++ b/src/importer/sources/desktop_source.py @@ -83,6 +83,10 @@ class DesktopSourceIterable(SourceIterable): if entry.suffix != ".desktop": continue + # Skip Lutris games + if str(entry.name).startswith("net.lutris."): + continue + keyfile = GLib.KeyFile.new() try: @@ -94,10 +98,30 @@ class DesktopSourceIterable(SourceIterable): continue name = keyfile.get_string("Desktop Entry", "Name") - executable = keyfile.get_string("Desktop Entry", "Exec") + executable = keyfile.get_string("Desktop Entry", "Exec").split( + " %" + )[0] except GLib.GError: continue + # Skip Steam games + if "steam://rungameid/" in executable: + continue + + # Skip Heroic games + if "heroic://launch/" in executable: + continue + + # Skip Bottles games + if "bottles-cli " in executable: + continue + + try: + if keyfile.get_boolean("Desktop Entry", "NoDisplay"): + continue + except GLib.GError: + pass + try: terminal = keyfile.get_boolean("Desktop Entry", "Terminal") except GLib.GError: @@ -116,7 +140,7 @@ class DesktopSourceIterable(SourceIterable): "name": name, "game_id": "desktop_" + sha3_256( - str(path).encode("utf-8"), usedforsecurity=False + str(entry).encode("utf-8"), usedforsecurity=False ).hexdigest(), "executable": self.source.executable_format.format( exec=cd_path @@ -130,26 +154,37 @@ class DesktopSourceIterable(SourceIterable): game = Game(values) additional_data = {} + icon_name = None try: - if ( - icon_path := icon_theme.lookup_icon( - keyfile.get_string("Desktop Entry", "Icon"), - None, - 512, - 1, - shared.win.get_direction(), - 0, - ) - .get_file() - .get_path() - ): - additional_data = {"local_icon_path": Path(icon_path)} + icon_str = keyfile.get_string("Desktop Entry", "Icon") + if "/" in icon_str: + additional_data = {"local_icon_path": Path(icon_str)} else: - pass + icon_name = icon_str except GLib.GError: pass + if icon_name: + try: + if ( + icon_path := icon_theme.lookup_icon( + icon_name, + None, + 512, + 1, + shared.win.get_direction(), + 0, + ) + .get_file() + .get_path() + ): + additional_data = {"local_icon_path": Path(icon_path)} + else: + pass + except GLib.GError: + pass + yield (game, additional_data)