Desktop source cleanups
This commit is contained in:
@@ -27,7 +27,7 @@ from gi.repository import GLib, Gtk
|
|||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
from src.game import Game
|
from src.game import Game
|
||||||
from src.importer.sources.source import ExecutableFormatSource, SourceIterable
|
from src.importer.sources.source import Source, SourceIterable
|
||||||
|
|
||||||
|
|
||||||
class DesktopSourceIterable(SourceIterable):
|
class DesktopSourceIterable(SourceIterable):
|
||||||
@@ -62,20 +62,7 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
icon_theme.add_search_path(str(path))
|
icon_theme.add_search_path(str(path))
|
||||||
|
|
||||||
match shared.schema.get_enum("desktop-terminal"):
|
terminal_exec = self.get_terminal_exec()
|
||||||
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 += " "
|
|
||||||
|
|
||||||
for path in search_paths:
|
for path in search_paths:
|
||||||
if str(path).startswith("/app/"):
|
if str(path).startswith("/app/"):
|
||||||
@@ -149,63 +136,75 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
+ sha3_256(
|
+ sha3_256(
|
||||||
str(entry).encode("utf-8"), usedforsecurity=False
|
str(entry).encode("utf-8"), usedforsecurity=False
|
||||||
).hexdigest(),
|
).hexdigest(),
|
||||||
"executable": self.source.executable_format.format(
|
"executable": cd_path
|
||||||
exec=cd_path
|
+ (
|
||||||
+ (
|
(terminal_exec + shlex.quote(executable))
|
||||||
(terminal_exec + shlex.quote(executable))
|
if terminal
|
||||||
if terminal
|
else executable
|
||||||
else executable
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
game = Game(values)
|
game = Game(values)
|
||||||
|
|
||||||
additional_data = {}
|
additional_data = {}
|
||||||
icon_name = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
icon_str = keyfile.get_string("Desktop Entry", "Icon")
|
icon_str = keyfile.get_string("Desktop Entry", "Icon")
|
||||||
|
except GLib.GError:
|
||||||
|
print("AAAAAAAAAAAAAAAAAAAAAAA")
|
||||||
|
yield game
|
||||||
|
continue
|
||||||
|
else:
|
||||||
if "/" in icon_str:
|
if "/" in icon_str:
|
||||||
additional_data = {"local_icon_path": Path(icon_str)}
|
additional_data = {"local_icon_path": Path(icon_str)}
|
||||||
else:
|
yield (game, additional_data)
|
||||||
icon_name = icon_str
|
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:
|
except GLib.GError:
|
||||||
pass
|
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)
|
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):
|
class DesktopLocations(NamedTuple):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DesktopSource(ExecutableFormatSource):
|
class DesktopSource(Source):
|
||||||
"""Generic Flatpak source"""
|
"""Generic Flatpak source"""
|
||||||
|
|
||||||
source_id = "desktop"
|
source_id = "desktop"
|
||||||
name = _("Desktop")
|
name = _("Desktop")
|
||||||
iterable_class = DesktopSourceIterable
|
iterable_class = DesktopSourceIterable
|
||||||
executable_format = "{exec}"
|
|
||||||
available_on = {"linux"}
|
available_on = {"linux"}
|
||||||
|
|
||||||
locations: DesktopLocations
|
locations: DesktopLocations
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ class Source(Iterable):
|
|||||||
def is_available(self) -> bool:
|
def is_available(self) -> bool:
|
||||||
return sys.platform in self.available_on
|
return sys.platform in self.available_on
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def make_executable(self, *args, **kwargs) -> str:
|
def make_executable(self, *args, **kwargs) -> str:
|
||||||
"""
|
"""
|
||||||
Create a game executable command.
|
Create a game executable command.
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class CartridgesApplication(Adw.Application):
|
|||||||
self.win.present()
|
self.win.present()
|
||||||
|
|
||||||
def check_desktop_terminals(self) -> None:
|
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")
|
terminals = ("xdg-terminal-exec", "kgx", "gnome-terminal", "konsole", "xterm")
|
||||||
|
|
||||||
for index, command in enumerate(terminals):
|
for index, command in enumerate(terminals):
|
||||||
|
|||||||
Reference in New Issue
Block a user