Better implementation for desktop entry source
This commit is contained in:
@@ -311,32 +311,12 @@ template $PreferencesWindow : Adw.PreferencesWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Adw.ExpanderRow desktop_expander_row {
|
Adw.ActionRow {
|
||||||
title: _("Desktop Entries");
|
title: _("Desktop Entries");
|
||||||
show-enable-switch: true;
|
activatable-widget: desktop_switch;
|
||||||
|
|
||||||
Adw.ComboRow desktop_terminal_exec_row {
|
Switch desktop_switch {
|
||||||
title: _("Terminal");
|
|
||||||
subtitle: _("Used only by games that require one to run");
|
|
||||||
model: StringList {
|
|
||||||
strings [
|
|
||||||
_("Custom"),
|
|
||||||
"xdg-terminal-exec",
|
|
||||||
"GNOME Console",
|
|
||||||
"GNOME Terminal",
|
|
||||||
"Konsole",
|
|
||||||
"XTerm"
|
|
||||||
]
|
|
||||||
};
|
|
||||||
[suffix]
|
|
||||||
Revealer desktop_tereminal_custom_exec_revealer {
|
|
||||||
transition-type: slide_right;
|
|
||||||
|
|
||||||
Entry desktop_tereminal_custom_exec {
|
|
||||||
valign: center;
|
valign: center;
|
||||||
placeholder-text: _("Executable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<schemalist gettext-domain="cartridges">
|
<schemalist gettext-domain="cartridges">
|
||||||
|
|
||||||
<enum id="@APP_ID@.terminals">
|
|
||||||
<value nick="custom" value="0"/>
|
|
||||||
<value nick="xdg-terminal-exec" value="1"/>
|
|
||||||
<value nick="kgx" value="2"/>
|
|
||||||
<value nick="gnome-terminal" value="3"/>
|
|
||||||
<value nick="konsole" value="4"/>
|
|
||||||
<value nick="xterm" value="5"/>
|
|
||||||
</enum>
|
|
||||||
|
|
||||||
<schema id="@APP_ID@" path="@PREFIX@/">
|
<schema id="@APP_ID@" path="@PREFIX@/">
|
||||||
<key name="exit-after-launch" type="b">
|
<key name="exit-after-launch" type="b">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
@@ -89,12 +80,6 @@
|
|||||||
<key name="desktop" type="b">
|
<key name="desktop" type="b">
|
||||||
<default>true</default>
|
<default>true</default>
|
||||||
</key>
|
</key>
|
||||||
<key name="desktop-terminal" enum="@APP_ID@.terminals">
|
|
||||||
<default>"xdg-terminal-exec"</default>
|
|
||||||
</key>
|
|
||||||
<key name="desktop-terminal-custom-exec" type="s">
|
|
||||||
<default>""</default>
|
|
||||||
</key>
|
|
||||||
<key name="flatpak" type="b">
|
<key name="flatpak" type="b">
|
||||||
<default>true</default>
|
<default>true</default>
|
||||||
</key>
|
</key>
|
||||||
@@ -144,8 +129,5 @@
|
|||||||
<key name="steam-limiter-tokens-history" type="s">
|
<key name="steam-limiter-tokens-history" type="s">
|
||||||
<default>"[]"</default>
|
<default>"[]"</default>
|
||||||
</key>
|
</key>
|
||||||
<key name="terminal-check-done" type="b">
|
|
||||||
<default>false</default>
|
|
||||||
</key>
|
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
|
import subprocess
|
||||||
from hashlib import sha3_256
|
from hashlib import sha3_256
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import time
|
from time import time
|
||||||
@@ -62,7 +64,7 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
icon_theme.add_search_path(str(path))
|
icon_theme.add_search_path(str(path))
|
||||||
|
|
||||||
terminal_exec = self.get_terminal_exec()
|
launch_command, full_path = self.check_launch_command()
|
||||||
|
|
||||||
for path in search_paths:
|
for path in search_paths:
|
||||||
if str(path).startswith("/app/"):
|
if str(path).startswith("/app/"):
|
||||||
@@ -116,18 +118,6 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
except GLib.GError:
|
except GLib.GError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
|
||||||
terminal = keyfile.get_boolean("Desktop Entry", "Terminal")
|
|
||||||
except GLib.GError:
|
|
||||||
terminal = False
|
|
||||||
|
|
||||||
try:
|
|
||||||
cd_path = (
|
|
||||||
"cd " + keyfile.get_string("Desktop Entry", "Path") + " && "
|
|
||||||
)
|
|
||||||
except GLib.GError:
|
|
||||||
cd_path = ""
|
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"added": added_time,
|
"added": added_time,
|
||||||
@@ -136,12 +126,7 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
+ sha3_256(
|
+ sha3_256(
|
||||||
str(entry).encode("utf-8"), usedforsecurity=False
|
str(entry).encode("utf-8"), usedforsecurity=False
|
||||||
).hexdigest(),
|
).hexdigest(),
|
||||||
"executable": cd_path
|
"executable": f"{launch_command} {shlex.quote(str(entry if full_path else entry.stem))}",
|
||||||
+ (
|
|
||||||
(terminal_exec + shlex.quote(executable))
|
|
||||||
if terminal
|
|
||||||
else executable
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
game = Game(values)
|
game = Game(values)
|
||||||
|
|
||||||
@@ -177,21 +162,27 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
yield (game, additional_data)
|
yield (game, additional_data)
|
||||||
|
|
||||||
def get_terminal_exec(self) -> str:
|
def check_launch_command(self) -> (str, bool):
|
||||||
match shared.schema.get_enum("desktop-terminal"):
|
"""Check whether `gio launch` `gtk4-launch` or `gtk-launch` are available on the system"""
|
||||||
case 0:
|
commands = (("gio launch", True), ("gtk4-launch", False), ("gtk-launch", False))
|
||||||
terminal_exec = shared.schema.get_string("desktop-terminal-custom-exec")
|
flatpak_str = "flatpak-spawn --host /bin/sh -c "
|
||||||
case 1:
|
|
||||||
terminal_exec = "xdg-terminal-exec"
|
for command, full_path in commands:
|
||||||
case 2:
|
check_command = (
|
||||||
terminal_exec = "kgx -e"
|
"gio help launch"
|
||||||
case 3:
|
if command == "gio launch"
|
||||||
terminal_exec = "gnome-terminal --"
|
else f"type {command} &> /dev/null"
|
||||||
case 4:
|
)
|
||||||
terminal_exec = "konsole -e"
|
if os.getenv("FLATPAK_ID") == shared.APP_ID:
|
||||||
case 5:
|
check_command = flatpak_str + shlex.quote(check_command)
|
||||||
terminal_exec = "xterm -e"
|
|
||||||
return terminal_exec + " "
|
try:
|
||||||
|
subprocess.run(check_command, shell=True, check=True)
|
||||||
|
return command, full_path
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return commands[2]
|
||||||
|
|
||||||
|
|
||||||
class DesktopLocations(NamedTuple):
|
class DesktopLocations(NamedTuple):
|
||||||
|
|||||||
20
src/main.py
20
src/main.py
@@ -75,10 +75,6 @@ class CartridgesApplication(Adw.Application):
|
|||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
migrate_files_v1_to_v2()
|
migrate_files_v1_to_v2()
|
||||||
else:
|
|
||||||
if not shared.state_schema.get_boolean("terminal-check-done"):
|
|
||||||
self.check_desktop_terminals()
|
|
||||||
shared.state_schema.set_boolean("terminal-check-done", True)
|
|
||||||
|
|
||||||
# Set fallback icon-name
|
# Set fallback icon-name
|
||||||
Gtk.Window.set_default_icon_name(shared.APP_ID)
|
Gtk.Window.set_default_icon_name(shared.APP_ID)
|
||||||
@@ -149,22 +145,6 @@ class CartridgesApplication(Adw.Application):
|
|||||||
|
|
||||||
self.win.present()
|
self.win.present()
|
||||||
|
|
||||||
def check_desktop_terminals(self) -> None:
|
|
||||||
"""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):
|
|
||||||
command = f"type {command} &> /dev/null"
|
|
||||||
if os.getenv("FLATPAK_ID") == shared.APP_ID:
|
|
||||||
command = "flatpak-spawn --host /bin/sh -c " + shlex.quote(command)
|
|
||||||
|
|
||||||
try:
|
|
||||||
subprocess.run(command, shell=True, check=True)
|
|
||||||
shared.schema.set_enum("desktop-terminal", index + 1)
|
|
||||||
return
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def load_games_from_disk(self) -> None:
|
def load_games_from_disk(self) -> None:
|
||||||
if shared.games_dir.is_dir():
|
if shared.games_dir.is_dir():
|
||||||
for game_file in shared.games_dir.iterdir():
|
for game_file in shared.games_dir.iterdir():
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ from gi.repository import Adw, Gio, GLib, Gtk
|
|||||||
from src import shared
|
from src import shared
|
||||||
from src.game import Game
|
from src.game import Game
|
||||||
from src.importer.sources.bottles_source import BottlesSource
|
from src.importer.sources.bottles_source import BottlesSource
|
||||||
from src.importer.sources.desktop_source import DesktopSource
|
|
||||||
from src.importer.sources.flatpak_source import FlatpakSource
|
from src.importer.sources.flatpak_source import FlatpakSource
|
||||||
from src.importer.sources.heroic_source import HeroicSource
|
from src.importer.sources.heroic_source import HeroicSource
|
||||||
from src.importer.sources.itch_source import ItchSource
|
from src.importer.sources.itch_source import ItchSource
|
||||||
@@ -98,10 +97,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
flatpak_data_file_chooser_button = Gtk.Template.Child()
|
flatpak_data_file_chooser_button = Gtk.Template.Child()
|
||||||
flatpak_import_launchers_switch = Gtk.Template.Child()
|
flatpak_import_launchers_switch = Gtk.Template.Child()
|
||||||
|
|
||||||
desktop_expander_row = Gtk.Template.Child()
|
desktop_switch = Gtk.Template.Child()
|
||||||
desktop_terminal_exec_row = Gtk.Template.Child()
|
|
||||||
desktop_tereminal_custom_exec_revealer = Gtk.Template.Child()
|
|
||||||
desktop_tereminal_custom_exec = Gtk.Template.Child()
|
|
||||||
|
|
||||||
sgdb_key_group = Gtk.Template.Child()
|
sgdb_key_group = Gtk.Template.Child()
|
||||||
sgdb_key_entry_row = Gtk.Template.Child()
|
sgdb_key_entry_row = Gtk.Template.Child()
|
||||||
@@ -150,7 +146,6 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
for source_class in (
|
for source_class in (
|
||||||
BottlesSource,
|
BottlesSource,
|
||||||
FlatpakSource,
|
FlatpakSource,
|
||||||
DesktopSource,
|
|
||||||
HeroicSource,
|
HeroicSource,
|
||||||
ItchSource,
|
ItchSource,
|
||||||
LegendarySource,
|
LegendarySource,
|
||||||
@@ -165,36 +160,6 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
else:
|
else:
|
||||||
self.init_source_row(source)
|
self.init_source_row(source)
|
||||||
|
|
||||||
# Desktop Terminal Executable
|
|
||||||
def set_terminal_exec(widget: Adw.ComboRow, _param: Any) -> None:
|
|
||||||
shared.schema.set_enum("desktop-terminal", widget.get_selected())
|
|
||||||
self.desktop_tereminal_custom_exec_revealer.set_reveal_child(
|
|
||||||
widget.get_selected() == 0
|
|
||||||
)
|
|
||||||
|
|
||||||
self.desktop_terminal_exec_row.connect("notify::selected", set_terminal_exec)
|
|
||||||
self.desktop_terminal_exec_row.set_selected(
|
|
||||||
terminal_value := shared.schema.get_enum("desktop-terminal")
|
|
||||||
)
|
|
||||||
if not terminal_value:
|
|
||||||
set_terminal_exec(
|
|
||||||
self.desktop_terminal_exec_row, None
|
|
||||||
) # The default value is supposed to be 4294967295, but it's 0 and I can't change it
|
|
||||||
|
|
||||||
self.desktop_tereminal_custom_exec.set_text(
|
|
||||||
shared.schema.get_string("desktop-terminal-custom-exec")
|
|
||||||
)
|
|
||||||
|
|
||||||
def desktop_custom_exec_changed(*_args: Any) -> None:
|
|
||||||
shared.schema.set_string(
|
|
||||||
"desktop-terminal-custom-exec",
|
|
||||||
self.desktop_tereminal_custom_exec.get_text(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.desktop_tereminal_custom_exec.connect(
|
|
||||||
"changed", desktop_custom_exec_changed
|
|
||||||
)
|
|
||||||
|
|
||||||
# SteamGridDB
|
# SteamGridDB
|
||||||
def sgdb_key_changed(*_args: Any) -> None:
|
def sgdb_key_changed(*_args: Any) -> None:
|
||||||
shared.schema.set_string("sgdb-key", self.sgdb_key_entry_row.get_text())
|
shared.schema.set_string("sgdb-key", self.sgdb_key_entry_row.get_text())
|
||||||
@@ -236,6 +201,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
"sgdb",
|
"sgdb",
|
||||||
"sgdb-prefer",
|
"sgdb-prefer",
|
||||||
"sgdb-animated",
|
"sgdb-animated",
|
||||||
|
"desktop",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user