Skip to content

Commit

Permalink
Flatpak: Create shortcuts that launch flatpak
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinKinloch authored and Exzap committed Jan 17, 2024
1 parent f899ab7 commit e53c63b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/gui/components/wxGameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ void wxGameList::CreateShortcut(GameInfo2& gameInfo) {
const auto title_id = gameInfo.GetBaseTitleId();
const auto title_name = gameInfo.GetTitleName();
auto exe_path = ActiveSettings::GetExecutablePath();
const char *flatpak_id = getenv("FLATPAK_ID");

// GetExecutablePath returns the AppImage's temporary mount location, instead of its actual path
wxString appimage_path;
Expand Down Expand Up @@ -1292,22 +1293,31 @@ void wxGameList::CreateShortcut(GameInfo2& gameInfo) {
}
}
}

std::string desktop_exec_entry;
if (flatpak_id)
desktop_exec_entry = fmt::format("/usr/bin/flatpak run {0} --title-id {1:016x}", flatpak_id, title_id);
else
desktop_exec_entry = fmt::format("{0:?} --title-id {1:016x}", _pathToUtf8(exe_path), title_id);

// 'Icon' accepts spaces in file name, does not accept quoted file paths
// 'Exec' does not accept non-escaped spaces, and can accept quoted file paths
const auto desktop_entry_string =
auto desktop_entry_string =
fmt::format("[Desktop Entry]\n"
"Name={0}\n"
"Comment=Play {0} on Cemu\n"
"Exec={1:?} --title-id {2:016x}\n"
"Icon={3}\n"
"Exec={1}\n"
"Icon={2}\n"
"Terminal=false\n"
"Type=Application\n"
"Categories=Game;",
"Categories=Game;\n",
title_name,
_pathToUtf8(exe_path),
title_id,
desktop_exec_entry,
_pathToUtf8(icon_path.value_or("")));

if (flatpak_id)
desktop_entry_string += fmt::format("X-Flatpak={}\n", flatpak_id);

std::ofstream output_stream(output_path);
if (!output_stream.good())
{
Expand Down

0 comments on commit e53c63b

Please sign in to comment.