New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Importing Desktop Files (Native Games) #28
Comments
This is more complex than it might sound. ScanningI can think of 2 ways to do this, both have issues though. Method 1:
Workarounds/Ideas:
Method 2:
Game Image Banners
Overall, this is not easy at all. If someone wants to help out with the implementation or at least help us do more research about potential solutions, or looking for any robust Python libraries that could help with this, then please share your findings! :) |
We have decided to go forward with Option 1, the Here's some more research I've been doing: .desktop file parsing library
.desktop file loading priorityThese are the locations we need to RECURSIVELY scan (because desktop files are allowed to be within subfolders). The later entries in this list will OVERRIDE any conflicting filenames found in any earlier entries in the list. So let's say two locations contain a Flatpak folders and priorities are taken from their docs: https://github.com/flatpak/flatpak/wiki/Filesystem Anyway, here's the list of locations, from lowest override priority (at the top) to highest priority (at the bottom):
This means:
And before anyone suggests it: We cannot use the XDG environment vars because they don't work inside Flatpaks:
Anyway... We need to do this:
|
Here's a quick implementation to get us started. I don't have time to finish it, rewriting it to work inside the Flatpak sandbox, adding Flatpak permissions to the manifest, etc. But at least it helps us get started. from pathlib import Path
from pprint import pprint
scan_desktop_paths = [
"/usr/share/applications",
"/usr/local/share/applications",
"/var/lib/flatpak/exports/share/applications",
Path.home() / ".local/share/flatpak/exports/share/applications",
Path.home() / ".local/share/applications",
]
found_desktop_files = {}
for desktop_path in scan_desktop_paths:
for desktop_file in Path(desktop_path).glob("**/*.desktop"): # Note: Glob automatically ignores missing `desktop_path` locations.
if desktop_file.name in found_desktop_files:
print(
f"Overriding: {found_desktop_files[desktop_file.name]} -> {desktop_file}"
)
found_desktop_files[desktop_file.name] = desktop_file
# Now just process every desktop file via the desktop parsing library: https://pypi.org/project/desktop-parser/
# Read the "Desktop Entry" section from the files (see https://github.com/ArianeTeam/Ariane/blob/main/ariane/main.py#L68).
# Check if they have a game-related category, if not then ignore them.
# Filter out all desktop files that are from a source that's natively supported by Cartridges (ie Steam, Bottles, Heroic)
# All remaining desktop files are now unique, sideloaded games
# Use the Gio library to read their icon.
# Generate a fake banner for the game using their icon overlaid on top of a static gradient background (possibly enlarge + blur the official icon, and overlay a black/gray gradient to darken it, to get a really nice banner image).
# And lastly, take their "Exec=" data and use that as launch argument (but remove `%U` and other dynamic arguments).
pprint(found_desktop_files) It's basically solved but I don't have time to finish it. I have so much to do... |
Hi ! Just a bit of knowledge coming from my prior development on Gali. I agree with the idea of looking for the
There, in the current state of things you will hit a roablock for all apps coming from flatpaks, since their desktop entries cannot be exposed to the sandbox, A solution would be a portal to request desktop entries, which I already requested a while back : xdg-desktop-portal issue #809. |
As discussed with @kra-mo on the side, while |
Under |
We can already follow the XDG specification and detect the game |
I just recently started using Cartridges. Until now, I hadn't been using any fancy GUI for launching games, and had in fact been relying on Linux Mint's application menu as the one place to access all of my games. Ensuring that all of them were easily accessible in this way meant manually creating some desktop entries in Knowing that all of my games have desktop entries, and now having decided that I wanted to add all of my miscellaneous non-Steam/Itch/Bottles/Flatpak games to Cartridges, I wrote a script (purely for personal use) which partially automates the process of adding games from desktop entries. The script takes any number of desktop entry locations as arguments; for each one, it parses the
|
Thanks for the comment. Overall, I agree with what you said.
Pretty sure gtk-launch is part of GTK3 so we shouldn't rely on it. cd-ing into a directory is easy enough and there is a distro-agnostic way to run a command in any terminal (though the standard is fairly new). Gio.AppInfo.launch does handle all of this, but since we want to run the command on the host, we would need to run a module from the sandbox on the host using this, which is pretty much a hack and probably not doable. We could also do some automatic detection of terminals' desktop entries and hard code some, (GNOME Console, GNOME Terminal, Konsole, xterm), but that could change in the future and all of this is messy. I think the best way to handle this would be to not import terminal games initially unless xdg-terminal-exec is present. If it isn't, inform the user in a popup and let them pick which terminal to use from a hard-coded list of presets or optionally, type in a command of their own.
This hasn't been considered when adding new sources previously either, because I don't think it can work. Any solution to this would be a hack and could lead to unexpected results. Games added manually don't play a role in imports in any way and I don't think they should. Worst case scenario is that the user has to delete/hide some games. |
Fair enough. Even in the absence of manually added games, the possibility of duplicates is nothing new. I got one game imported twice because I had installed it from Itch.io and then added it to Bottles after vanilla Wine failed to run it smoothly. Hiding the imported Itch.io copy was easy. Having added so many games manually, though, I would probably prefer to turn off desktop entry imports on my system. I see that other import sources can already be toggled, so I assume it will be possible for desktop entry imports as well. As for non-game programs being added because they are categorized as "Game", I should point out that this isn't new either. Cartridges imported the Flatpak version of ScummVM on my system, for example. Some might prefer that behavior, actually. I just hid it after the import. |
Resolved by #174 😄 |
Games like Battle for Wesnoth and Unciv might be installed through flatpak or the package manager without using a game client.
It would be nice if cartridges imported those games automatically. Adding them manually works fine but it is still a chore.
The text was updated successfully, but these errors were encountered: