qt: Properly fix discord rich presence

This commit is contained in:
PabloMK7 2026-04-13 13:17:31 +02:00
parent 6d230d28da
commit 4dbe0fd497
5 changed files with 22 additions and 20 deletions

View file

@ -366,7 +366,7 @@ GMainWindow::GMainWindow(Core::System& system_)
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue());
discord_rpc->Update(); discord_rpc->Update(false);
#endif #endif
play_time_manager = std::make_unique<PlayTime::PlayTimeManager>(); play_time_manager = std::make_unique<PlayTime::PlayTimeManager>();
@ -975,7 +975,7 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) {
OnPauseGame(); OnPauseGame();
} else if (!emu_thread->IsRunning() && auto_paused && state == Qt::ApplicationActive) { } else if (!emu_thread->IsRunning() && auto_paused && state == Qt::ApplicationActive) {
auto_paused = false; auto_paused = false;
OnStartGame(); OnResumeGame(false);
} }
} }
if (UISettings::values.mute_when_in_background) { if (UISettings::values.mute_when_in_background) {
@ -1530,7 +1530,7 @@ void GMainWindow::BootGame(const QString& filename) {
ShowFullscreen(); ShowFullscreen();
} }
OnStartGame(); OnResumeGame(true);
} }
void GMainWindow::ShutdownGame() { void GMainWindow::ShutdownGame() {
@ -1583,7 +1583,7 @@ void GMainWindow::ShutdownGame() {
OnCloseMovie(); OnCloseMovie();
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
discord_rpc->Update(); discord_rpc->Update(false);
#endif #endif
#ifdef __unix__ #ifdef __unix__
Common::Linux::StopGamemode(); Common::Linux::StopGamemode();
@ -2508,7 +2508,7 @@ void GMainWindow::OnMenuRecentFile() {
} }
} }
void GMainWindow::OnStartGame() { void GMainWindow::OnResumeGame(bool first_start) {
qt_cameras->ResumeCameras(); qt_cameras->ResumeCameras();
PreventOSSleep(); PreventOSSleep();
@ -2525,9 +2525,12 @@ void GMainWindow::OnStartGame() {
play_time_manager->SetProgramId(game_title_id); play_time_manager->SetProgramId(game_title_id);
play_time_manager->Start(); play_time_manager->Start();
if (first_start) {
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
discord_rpc->Update(); discord_rpc->Update(true);
#endif #endif
}
#ifdef __unix__ #ifdef __unix__
Common::Linux::StartGamemode(); Common::Linux::StartGamemode();
#endif #endif
@ -2563,7 +2566,7 @@ void GMainWindow::OnPauseContinueGame() {
if (emu_thread->IsRunning() && !system.frame_limiter.IsFrameAdvancing()) { if (emu_thread->IsRunning() && !system.frame_limiter.IsFrameAdvancing()) {
OnPauseGame(); OnPauseGame();
} else { } else {
OnStartGame(); OnResumeGame(false);
} }
} }
} }
@ -2865,6 +2868,7 @@ void GMainWindow::OnConfigure() {
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) { if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) {
SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue());
discord_rpc->Update(system.IsPoweredOn());
} }
#endif #endif
#ifdef __unix__ #ifdef __unix__
@ -3032,7 +3036,7 @@ void GMainWindow::OnCloseMovie() {
} }
if (was_running) { if (was_running) {
OnStartGame(); OnResumeGame(false);
} }
} }
@ -3054,7 +3058,7 @@ void GMainWindow::OnSaveMovie() {
} }
if (was_running) { if (was_running) {
OnStartGame(); OnResumeGame(false);
} }
} }
@ -3098,7 +3102,7 @@ void GMainWindow::OnCaptureScreenshot() {
screenshot_window->CaptureScreenshot( screenshot_window->CaptureScreenshot(
UISettings::values.screenshot_resolution_factor.GetValue(), UISettings::values.screenshot_resolution_factor.GetValue(),
QString::fromStdString(path)); QString::fromStdString(path));
OnStartGame(); OnResumeGame(false);
} }
} }
@ -3501,7 +3505,7 @@ void GMainWindow::OnStopVideoDumping() {
ShutdownGame(); ShutdownGame();
} else if (game_paused_for_dumping) { } else if (game_paused_for_dumping) {
game_paused_for_dumping = false; game_paused_for_dumping = false;
OnStartGame(); OnResumeGame(false);
} }
}); });
future_watcher->setFuture(future); future_watcher->setFuture(future);
@ -4235,7 +4239,6 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
} else { } else {
discord_rpc = std::make_unique<DiscordRPC::NullImpl>(); discord_rpc = std::make_unique<DiscordRPC::NullImpl>();
} }
discord_rpc->Update();
} }
#endif #endif

View file

@ -231,7 +231,7 @@ private:
void ShowFFmpegErrorMessage(); void ShowFFmpegErrorMessage();
private slots: private slots:
void OnStartGame(); void OnResumeGame(bool first_start);
void OnRestartGame(); void OnRestartGame();
void OnPauseGame(); void OnPauseGame();
void OnPauseContinueGame(); void OnPauseContinueGame();

View file

@ -1,4 +1,4 @@
// Copyright 2018 Citra Emulator Project // Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -11,7 +11,7 @@ public:
virtual ~DiscordInterface() = default; virtual ~DiscordInterface() = default;
virtual void Pause() = 0; virtual void Pause() = 0;
virtual void Update() = 0; virtual void Update(bool is_powered_on) = 0;
}; };
class NullImpl : public DiscordInterface { class NullImpl : public DiscordInterface {
@ -19,7 +19,7 @@ public:
~NullImpl() = default; ~NullImpl() = default;
void Pause() override {} void Pause() override {}
void Update() override {} void Update(bool is_powered_on) override {}
}; };
} // namespace DiscordRPC } // namespace DiscordRPC

View file

@ -30,12 +30,11 @@ void DiscordImpl::Pause() {
Discord_ClearPresence(); Discord_ClearPresence();
} }
void DiscordImpl::Update() { void DiscordImpl::Update(bool is_powered_on) {
s64 start_time = std::chrono::duration_cast<std::chrono::seconds>( s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()) std::chrono::system_clock::now().time_since_epoch())
.count(); .count();
std::string title; std::string title;
const bool is_powered_on = system.IsPoweredOn();
if (is_powered_on) { if (is_powered_on) {
system.GetAppLoader().ReadTitle(title); system.GetAppLoader().ReadTitle(title);
} }

View file

@ -1,4 +1,4 @@
// Copyright 2018 Citra Emulator Project // Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -18,7 +18,7 @@ public:
~DiscordImpl() override; ~DiscordImpl() override;
void Pause() override; void Pause() override;
void Update() override; void Update(bool is_powered_on) override;
private: private:
const Core::System& system; const Core::System& system;