Fixed shortcuts generated via Flatpak not working

This commit is contained in:
OpenSauce04 2024-08-12 14:54:44 +01:00
parent 1c75bf4b7f
commit 6d37ef8b27
3 changed files with 28 additions and 19 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2014 Citra Emulator Project
// Copyright Citra Emulator Project / Lime3DS Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

View File

@ -1699,9 +1699,9 @@ void GMainWindow::OnGameListRemovePlayTimeData(u64 program_id) {
bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
const std::string& comment,
const std::filesystem::path& icon_path,
const std::filesystem::path& command,
const std::string& arguments, const std::string& categories,
const std::string& keywords, const std::string& name) try {
const std::string& command, const std::string& arguments,
const std::string& categories, const std::string& keywords,
const std::string& name, const bool& skip_tryexec) try {
#if defined(__linux__) || defined(__FreeBSD__) // Linux and FreeBSD
std::filesystem::path shortcut_path_full = shortcut_path / (name + ".desktop");
std::ofstream shortcut_stream(shortcut_path_full, std::ios::binary | std::ios::trunc);
@ -1720,8 +1720,10 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
if (std::filesystem::is_regular_file(icon_path)) {
fmt::print(shortcut_stream, "Icon={}\n", icon_path.string());
}
fmt::print(shortcut_stream, "TryExec={}\n", command.string());
fmt::print(shortcut_stream, "Exec={} {}\n", command.string(), arguments);
if (!skip_tryexec) {
fmt::print(shortcut_stream, "TryExec={}\n", command);
}
fmt::print(shortcut_stream, "Exec={} {}\n", command, arguments);
if (!categories.empty()) {
fmt::print(shortcut_stream, "Categories={}\n", categories);
}
@ -1858,12 +1860,20 @@ bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_vi
void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path,
GameListShortcutTarget target) {
// Get path to citra executable
std::string citra_command{};
bool skip_tryexec = false;
const char* env_flatpak_id = getenv("FLATPAK_ID");
if (env_flatpak_id) {
citra_command = fmt::format("flatpak run {}", env_flatpak_id);
skip_tryexec = true;
} else {
// Get path to Lime3DS executable
const QStringList args = QApplication::arguments();
std::filesystem::path citra_command = args[0].toStdString();
citra_command = args[0].toStdString();
// If relative path, make it an absolute path
if (citra_command.c_str()[0] == '.') {
citra_command = FileUtil::GetCurrentDir().value_or("") + DIR_SEP + citra_command.string();
citra_command = FileUtil::GetCurrentDir().value_or("") + DIR_SEP + citra_command;
}
}
// Shortcut path
@ -1919,8 +1929,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
// Warn once if we are making a shortcut to a volatile AppImage
const std::string appimage_ending =
std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage");
if (citra_command.string().ends_with(appimage_ending) &&
!UISettings::values.shortcut_already_warned) {
if (citra_command.ends_with(appimage_ending) && !UISettings::values.shortcut_already_warned) {
if (CreateShortcutMessagesGUI(this, CREATE_SHORTCUT_MSGBOX_APPIMAGE_VOLATILE_WARNING,
qt_game_title)) {
return;
@ -1938,7 +1947,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
const std::string keywords = "3ds;Nintendo;";
if (CreateShortcutLink(shortcut_path, comment, out_icon_path, citra_command, arguments,
categories, keywords, game_title)) {
categories, keywords, game_title, skip_tryexec)) {
CreateShortcutMessagesGUI(this, CREATE_SHORTCUT_MSGBOX_SUCCESS, qt_game_title);
return;
}

View File

@ -214,10 +214,10 @@ private:
bool MakeShortcutIcoPath(const u64 program_id, const std::string_view game_file_name,
std::filesystem::path& out_icon_path);
bool CreateShortcutLink(const std::filesystem::path& shortcut_path, const std::string& comment,
const std::filesystem::path& icon_path,
const std::filesystem::path& command, const std::string& arguments,
const std::string& categories, const std::string& keywords,
const std::string& name);
const std::filesystem::path& icon_path, const std::string& command,
const std::string& arguments, const std::string& categories,
const std::string& keywords, const std::string& name,
const bool& skip_tryexec);
private slots:
void OnStartGame();