Fixed incorrect applications directory path while using Flatpak build

This commit is contained in:
OpenSauce04
2024-08-13 20:25:25 +01:00
parent 6d37ef8b27
commit a3a6aed9be
6 changed files with 35 additions and 9 deletions

View File

@@ -1882,8 +1882,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
shortcut_path =
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).toStdString();
} else if (target == GameListShortcutTarget::Applications) {
shortcut_path =
QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString();
shortcut_path = GetApplicationsDirectory();
}
// Icon path and title

View File

@@ -1,11 +1,14 @@
// Copyright 2015 Citra Emulator Project
// Copyright Citra Emulator Project / Lime3DS Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <array>
#include <cmath>
#include <QPainter>
#include <QStandardPaths>
#include "citra_qt/util/util.h"
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/logging/log.h"
#include "core/loader/smdh.h"
@@ -160,3 +163,15 @@ bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image)
return false;
#endif
}
const std::string GetApplicationsDirectory() {
// This alternate method is required for Flatpak compatibility as
// QStandardPaths::ApplicationsLocation returns a path inside the Flatpak data directory instead of
// $HOME/.local/share
#if defined(__linux__) || defined(__FreeBSD__)
return FileUtil::GetHomeDirectory() + DIR_SEP + ".local" + DIR_SEP + "share" + DIR_SEP +
"applications";
#else
return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString();
#endif
}

View File

@@ -1,4 +1,4 @@
// Copyright 2015 Citra Emulator Project
// Copyright Citra Emulator Project / Lime3DS Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
@@ -36,3 +36,8 @@ QPixmap GetQPixmapFromSMDH(const std::vector<u8>& smdh_data);
* @return bool If the operation succeeded
*/
[[nodiscard]] bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image);
/**
* @return The users applications directory
*/
[[nodiscard]] const std::string GetApplicationsDirectory();