More reliance on GLib
This commit is contained in:
@@ -17,12 +17,10 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import re
|
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import GLib, Gtk
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
from src.game import Game
|
from src.game import Game
|
||||||
@@ -41,16 +39,7 @@ class FlatpakSourceIterator(SourceIterator):
|
|||||||
icon_theme = Gtk.IconTheme.new()
|
icon_theme = Gtk.IconTheme.new()
|
||||||
icon_theme.add_search_path(str(self.source.data_location["icons"]))
|
icon_theme.add_search_path(str(self.source.data_location["icons"]))
|
||||||
|
|
||||||
try:
|
blacklist = (
|
||||||
process = subprocess.run(
|
|
||||||
("flatpak-spawn", "--host", "flatpak", "list", "--columns=application"),
|
|
||||||
capture_output=True,
|
|
||||||
encoding="utf-8",
|
|
||||||
check=True,
|
|
||||||
)
|
|
||||||
flatpak_ids = process.stdout.split("\n")
|
|
||||||
|
|
||||||
to_remove = (
|
|
||||||
{"hu.kramo.Cartridges"}
|
{"hu.kramo.Cartridges"}
|
||||||
if shared.schema.get_boolean("flatpak-import-launchers")
|
if shared.schema.get_boolean("flatpak-import-launchers")
|
||||||
else {
|
else {
|
||||||
@@ -63,40 +52,29 @@ class FlatpakSourceIterator(SourceIterator):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
for item in to_remove:
|
|
||||||
if item in flatpak_ids:
|
|
||||||
flatpak_ids.remove(item)
|
|
||||||
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
return
|
|
||||||
|
|
||||||
for entry in (self.source.data_location["applications"]).iterdir():
|
for entry in (self.source.data_location["applications"]).iterdir():
|
||||||
flatpak_id = entry.stem
|
keyfile = GLib.KeyFile.new()
|
||||||
|
|
||||||
if flatpak_id not in flatpak_ids:
|
try:
|
||||||
|
keyfile.load_from_file(str(entry), 0)
|
||||||
|
|
||||||
|
if "Game" not in keyfile.get_string_list("Desktop Entry", "Categories"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with entry.open("r", encoding="utf-8") as open_file:
|
if (
|
||||||
string = open_file.read()
|
flatpak_id := keyfile.get_string("Desktop Entry", "X-Flatpak")
|
||||||
|
) in blacklist:
|
||||||
desktop_values = {"Name": None, "Icon": None, "Categories": None}
|
|
||||||
for key in desktop_values:
|
|
||||||
if regex := re.findall(f"{key}=(.*)\n", string):
|
|
||||||
desktop_values[key] = regex[0]
|
|
||||||
|
|
||||||
if not desktop_values["Name"]:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not desktop_values["Categories"]:
|
name = keyfile.get_string("Desktop Entry", "Name")
|
||||||
continue
|
|
||||||
|
|
||||||
if not "Game" in desktop_values["Categories"].split(";"):
|
except GLib.GError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
"source": self.source.id,
|
"source": self.source.id,
|
||||||
"added": added_time,
|
"added": added_time,
|
||||||
"name": desktop_values["Name"],
|
"name": name,
|
||||||
"game_id": self.source.game_id_format.format(game_id=flatpak_id),
|
"game_id": self.source.game_id_format.format(game_id=flatpak_id),
|
||||||
"executable": self.source.executable_format.format(
|
"executable": self.source.executable_format.format(
|
||||||
flatpak_id=flatpak_id
|
flatpak_id=flatpak_id
|
||||||
@@ -105,10 +83,16 @@ class FlatpakSourceIterator(SourceIterator):
|
|||||||
game = Game(values)
|
game = Game(values)
|
||||||
|
|
||||||
additional_data = {}
|
additional_data = {}
|
||||||
if icon_name := desktop_values["Icon"]:
|
|
||||||
|
try:
|
||||||
if (
|
if (
|
||||||
icon_path := icon_theme.lookup_icon(
|
icon_path := icon_theme.lookup_icon(
|
||||||
icon_name, None, 512, 1, shared.win.get_direction(), 0
|
keyfile.get_string("Desktop Entry", "Icon"),
|
||||||
|
None,
|
||||||
|
512,
|
||||||
|
1,
|
||||||
|
shared.win.get_direction(),
|
||||||
|
0,
|
||||||
)
|
)
|
||||||
.get_file()
|
.get_file()
|
||||||
.get_path()
|
.get_path()
|
||||||
@@ -116,6 +100,8 @@ class FlatpakSourceIterator(SourceIterator):
|
|||||||
additional_data = {"local_icon_path": Path(icon_path)}
|
additional_data = {"local_icon_path": Path(icon_path)}
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
except GLib.GError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Produce game
|
# Produce game
|
||||||
yield (game, additional_data)
|
yield (game, additional_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user