mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-02-01 12:03:15 +00:00
Yellow squiggly lines begone! Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes. If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed. The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports. Not everything is removed, but the cleanup should be substantial enough. Because this done on Linux, code that isn't used on it is mostly untouched. (Hopefully no open PR is depending on these imports...)
101 lines
2.4 KiB
C++
101 lines
2.4 KiB
C++
// Copyright 2018 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
#include "DolphinQt/DiscordHandler.h"
|
|
|
|
#include <chrono>
|
|
|
|
#include <QApplication>
|
|
|
|
#include "Common/Thread.h"
|
|
|
|
#include "UICommon/DiscordPresence.h"
|
|
|
|
#include "DolphinQt/DiscordJoinRequestDialog.h"
|
|
#include "DolphinQt/QtUtils/RunOnObject.h"
|
|
|
|
DiscordHandler::DiscordHandler(QWidget* parent) : QObject{parent}, m_parent{parent}
|
|
{
|
|
connect(this, &DiscordHandler::JoinRequest, this, &DiscordHandler::ShowNewJoinRequest);
|
|
}
|
|
|
|
DiscordHandler::~DiscordHandler()
|
|
{
|
|
Stop();
|
|
}
|
|
|
|
void DiscordHandler::Start()
|
|
{
|
|
m_stop_requested.Set(false);
|
|
m_thread = std::thread(&DiscordHandler::Run, this);
|
|
}
|
|
|
|
void DiscordHandler::Stop()
|
|
{
|
|
if (!m_thread.joinable())
|
|
return;
|
|
|
|
m_stop_requested.Set(true);
|
|
m_wakeup_event.Set();
|
|
m_thread.join();
|
|
}
|
|
|
|
void DiscordHandler::DiscordJoinRequest(const char* id, const std::string& discord_tag,
|
|
const char* avatar)
|
|
{
|
|
emit DiscordHandler::JoinRequest(id, discord_tag, avatar);
|
|
}
|
|
|
|
void DiscordHandler::DiscordJoin()
|
|
{
|
|
emit DiscordHandler::Join();
|
|
}
|
|
|
|
void DiscordHandler::ShowNewJoinRequest(const std::string& id, const std::string& discord_tag,
|
|
const std::string& avatar)
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_request_dialogs_mutex);
|
|
m_request_dialogs.emplace_front(m_parent, id, discord_tag, avatar);
|
|
DiscordJoinRequestDialog& request_dialog = m_request_dialogs.front();
|
|
request_dialog.show();
|
|
request_dialog.raise();
|
|
request_dialog.activateWindow();
|
|
QApplication::alert(nullptr, DiscordJoinRequestDialog::s_max_lifetime_seconds * 1000);
|
|
}
|
|
|
|
void DiscordHandler::Run()
|
|
{
|
|
Common::SetCurrentThreadName("DiscordHandler");
|
|
|
|
while (!m_stop_requested.IsSet())
|
|
{
|
|
Discord::CallPendingCallbacks();
|
|
|
|
// close and remove dead requests
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_request_dialogs_mutex);
|
|
for (auto request_dialog = m_request_dialogs.begin();
|
|
request_dialog != m_request_dialogs.end();)
|
|
{
|
|
if (std::time(nullptr) < request_dialog->GetCloseTimestamp())
|
|
{
|
|
++request_dialog;
|
|
continue;
|
|
}
|
|
|
|
RunOnObject(m_parent, [this, &request_dialog] {
|
|
request_dialog->close();
|
|
request_dialog = m_request_dialogs.erase(request_dialog);
|
|
return nullptr;
|
|
});
|
|
}
|
|
}
|
|
|
|
m_wakeup_event.WaitFor(std::chrono::seconds{2});
|
|
}
|
|
}
|
|
|
|
#endif
|