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

View File

@ -231,7 +231,7 @@ private:
void ShowFFmpegErrorMessage();
private slots:
void OnStartGame();
void OnResumeGame(bool first_start);
void OnRestartGame();
void OnPauseGame();
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
// Refer to the license.txt file included.
@ -11,7 +11,7 @@ public:
virtual ~DiscordInterface() = default;
virtual void Pause() = 0;
virtual void Update() = 0;
virtual void Update(bool is_powered_on) = 0;
};
class NullImpl : public DiscordInterface {
@ -19,7 +19,7 @@ public:
~NullImpl() = default;
void Pause() override {}
void Update() override {}
void Update(bool is_powered_on) override {}
};
} // namespace DiscordRPC

View File

@ -30,12 +30,11 @@ void DiscordImpl::Pause() {
Discord_ClearPresence();
}
void DiscordImpl::Update() {
void DiscordImpl::Update(bool is_powered_on) {
s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
std::string title;
const bool is_powered_on = system.IsPoweredOn();
if (is_powered_on) {
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
// Refer to the license.txt file included.
@ -18,7 +18,7 @@ public:
~DiscordImpl() override;
void Pause() override;
void Update() override;
void Update(bool is_powered_on) override;
private:
const Core::System& system;