Skip to content

Commit

Permalink
Qt: Fix Discord Rich Presence if the game title is excessively, extre…
Browse files Browse the repository at this point in the history
…mely, overly, ridiculously, very very long (fixes #2697)
  • Loading branch information
endrift committed Oct 19, 2022
1 parent 879e756 commit 75da9f0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/platform/qt/DiscordCoordinator.cpp
Expand Up @@ -22,15 +22,15 @@ namespace DiscordCoordinator {

static bool s_gameRunning = false;
static bool s_inited = false;
static QString s_title;
static QByteArray s_title;

static void updatePresence() {
if (!s_inited) {
return;
}
if (s_gameRunning) {
DiscordRichPresence discordPresence{};
discordPresence.details = s_title.toUtf8().constData();
discordPresence.details = s_title.constData();
discordPresence.instance = 1;
discordPresence.largeImageKey = "mgba";
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
Expand Down Expand Up @@ -74,8 +74,10 @@ void gameStarted(std::shared_ptr<CoreController> controller) {
s_title = controller->thread()->core->dirs.baseName;
QString dbTitle = controller->dbTitle();
if (!dbTitle.isNull()) {
s_title = dbTitle;
s_title = dbTitle.toUtf8();
}
// Non-const QByteArrays are null-terminated so we don't need to append null even after truncation
s_title.truncate(128);
updatePresence();
}

Expand Down

0 comments on commit 75da9f0

Please sign in to comment.