Add Discord Rich Presence Support (#3883)

* Initial Discord RPC support

Build with Discord Presence ON

Fix RPC detection

Fix Time elapsed on pause; will now continue to count.

* Fix CI builds with compile flag

Addressed reviews

Fix silly mistakes

Fix 'Not in-game' display

class instead of namespace

Fix

Revamped

remove redundant code

Using Pimpl pattern

* Implement Null class

* Fix config updation

* Addressed All Reviews

* externals/discord-rpc : Updated to latest commit
This commit is contained in:
Vamsi Krishna 2018-08-20 14:50:33 +05:30 committed by Ben
parent 96c025e4c2
commit 6cb9a45154
19 changed files with 193 additions and 11 deletions

View file

@ -34,6 +34,7 @@
#include "citra_qt/debugger/profiler.h"
#include "citra_qt/debugger/registers.h"
#include "citra_qt/debugger/wait_tree.h"
#include "citra_qt/discord.h"
#include "citra_qt/game_list.h"
#include "citra_qt/hotkeys.h"
#include "citra_qt/main.h"
@ -58,6 +59,10 @@
#include "core/loader/loader.h"
#include "core/settings.h"
#ifdef USE_DISCORD_PRESENCE
#include "citra_qt/discord_impl.h"
#endif
#ifdef QT_STATICPLUGIN
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
#endif
@ -120,6 +125,9 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
default_theme_paths = QIcon::themeSearchPaths();
UpdateUITheme();
SetDiscordEnabled(UISettings::values.enable_discord_presence);
discord_rpc->Update();
Network::Init();
InitializeWidgets();
@ -748,6 +756,7 @@ void GMainWindow::BootGame(const QString& filename) {
}
void GMainWindow::ShutdownGame() {
discord_rpc->Pause();
emu_thread->RequestStop();
// Release emu threads from any breakpoints
@ -763,6 +772,8 @@ void GMainWindow::ShutdownGame() {
emu_thread->wait();
emu_thread = nullptr;
discord_rpc->Update();
Camera::QtMultimediaCameraHandler::ReleaseHandlers();
// The emulation is stopped, so closing the window or not does not matter anymore
@ -1049,6 +1060,8 @@ void GMainWindow::OnStartGame() {
ui.action_Stop->setEnabled(true);
ui.action_Restart->setEnabled(true);
ui.action_Report_Compatibility->setEnabled(true);
discord_rpc->Update();
}
void GMainWindow::OnPauseGame() {
@ -1184,11 +1197,14 @@ void GMainWindow::OnConfigure() {
connect(&configureDialog, &ConfigureDialog::languageChanged, this,
&GMainWindow::OnLanguageChanged);
auto old_theme = UISettings::values.theme;
const bool old_discord_presence = UISettings::values.enable_discord_presence;
auto result = configureDialog.exec();
if (result == QDialog::Accepted) {
configureDialog.applyConfiguration();
if (UISettings::values.theme != old_theme)
UpdateUITheme();
if (UISettings::values.enable_discord_presence != old_discord_presence)
SetDiscordEnabled(UISettings::values.enable_discord_presence);
emit UpdateThemedIcons();
SyncMenuUISettings();
config->Save();
@ -1481,6 +1497,19 @@ void GMainWindow::RetranslateStatusBar() {
multiplayer_state->retranslateUi();
}
void GMainWindow::SetDiscordEnabled(bool state) {
#ifdef USE_DISCORD_PRESENCE
if (state) {
discord_rpc = std::make_unique<DiscordRPC::DiscordImpl>();
} else {
discord_rpc = std::make_unique<DiscordRPC::NullImpl>();
}
#else
discord_rpc = std::make_unique<DiscordRPC::NullImpl>();
#endif
discord_rpc->Update();
}
#ifdef main
#undef main
#endif