From e287ec1986b6964c684bab992cc47357e723e872 Mon Sep 17 00:00:00 2001 From: kramo Date: Fri, 25 Aug 2023 21:50:23 +0200 Subject: [PATCH] Desktop source cleanups --- src/importer/sources/desktop_source.py | 93 +++++++++++++------------- src/importer/sources/source.py | 1 - src/main.py | 2 +- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/importer/sources/desktop_source.py b/src/importer/sources/desktop_source.py index 618d89e..6e78b0b 100644 --- a/src/importer/sources/desktop_source.py +++ b/src/importer/sources/desktop_source.py @@ -27,7 +27,7 @@ from gi.repository import GLib, Gtk from src import shared from src.game import Game -from src.importer.sources.source import ExecutableFormatSource, SourceIterable +from src.importer.sources.source import Source, SourceIterable class DesktopSourceIterable(SourceIterable): @@ -62,20 +62,7 @@ class DesktopSourceIterable(SourceIterable): icon_theme.add_search_path(str(path)) - match shared.schema.get_enum("desktop-terminal"): - case 0: - terminal_exec = shared.schema.get_string("desktop-terminal-custom-exec") - case 1: - terminal_exec = "xdg-terminal-exec" - case 2: - terminal_exec = "kgx -e" - case 3: - terminal_exec = "gnome-terminal --" - case 4: - terminal_exec = "konsole -e" - case 5: - terminal_exec = "xterm -e" - terminal_exec += " " + terminal_exec = self.get_terminal_exec() for path in search_paths: if str(path).startswith("/app/"): @@ -149,63 +136,75 @@ class DesktopSourceIterable(SourceIterable): + sha3_256( str(entry).encode("utf-8"), usedforsecurity=False ).hexdigest(), - "executable": self.source.executable_format.format( - exec=cd_path - + ( - (terminal_exec + shlex.quote(executable)) - if terminal - else executable - ) + "executable": cd_path + + ( + (terminal_exec + shlex.quote(executable)) + if terminal + else executable ), } game = Game(values) additional_data = {} - icon_name = None try: icon_str = keyfile.get_string("Desktop Entry", "Icon") + except GLib.GError: + print("AAAAAAAAAAAAAAAAAAAAAAA") + yield game + continue + else: if "/" in icon_str: additional_data = {"local_icon_path": Path(icon_str)} - else: - icon_name = icon_str + yield (game, additional_data) + continue + + try: + if ( + icon_path := icon_theme.lookup_icon( + icon_str, + None, + 512, + 1, + shared.win.get_direction(), + 0, + ) + .get_file() + .get_path() + ): + additional_data = {"local_icon_path": Path(icon_path)} 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) + def get_terminal_exec(self) -> str: + match shared.schema.get_enum("desktop-terminal"): + case 0: + terminal_exec = shared.schema.get_string("desktop-terminal-custom-exec") + case 1: + terminal_exec = "xdg-terminal-exec" + case 2: + terminal_exec = "kgx -e" + case 3: + terminal_exec = "gnome-terminal --" + case 4: + terminal_exec = "konsole -e" + case 5: + terminal_exec = "xterm -e" + return terminal_exec + " " + class DesktopLocations(NamedTuple): pass -class DesktopSource(ExecutableFormatSource): +class DesktopSource(Source): """Generic Flatpak source""" source_id = "desktop" name = _("Desktop") iterable_class = DesktopSourceIterable - executable_format = "{exec}" available_on = {"linux"} locations: DesktopLocations diff --git a/src/importer/sources/source.py b/src/importer/sources/source.py index e19b4dd..4f6be55 100644 --- a/src/importer/sources/source.py +++ b/src/importer/sources/source.py @@ -78,7 +78,6 @@ class Source(Iterable): def is_available(self) -> bool: return sys.platform in self.available_on - @abstractmethod def make_executable(self, *args, **kwargs) -> str: """ Create a game executable command. diff --git a/src/main.py b/src/main.py index c04aae5..63aedc4 100644 --- a/src/main.py +++ b/src/main.py @@ -150,7 +150,7 @@ class CartridgesApplication(Adw.Application): self.win.present() def check_desktop_terminals(self) -> None: - """Look for an installed terminal for desktop entries""" + """Look for an installed terminal for desktop entries and set the relevant gsetting""" terminals = ("xdg-terminal-exec", "kgx", "gnome-terminal", "konsole", "xterm") for index, command in enumerate(terminals):