From 9739d8d9c330f49186eb80eb31a31257a1e554e8 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 12 Jul 2020 22:44:33 +0200 Subject: [PATCH] hide user profile avatar if obs is running --- chatterino.pro | 2 + src/util/StreamerMode.cpp | 54 +++++++++++++++++++++++++++ src/util/StreamerMode.hpp | 8 ++++ src/widgets/dialogs/UserInfoPopup.cpp | 6 ++- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/util/StreamerMode.cpp create mode 100644 src/util/StreamerMode.hpp diff --git a/chatterino.pro b/chatterino.pro index 0be840667..63551a23b 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -219,6 +219,7 @@ SOURCES += \ src/util/JsonQuery.cpp \ src/util/RapidjsonHelpers.cpp \ src/util/StreamLink.cpp \ + src/util/StreamerMode.cpp \ src/util/Twitch.cpp \ src/util/NuulsUploader.cpp \ src/util/WindowsHelper.cpp \ @@ -435,6 +436,7 @@ HEADERS += \ src/util/PostToThread.hpp \ src/util/QObjectRef.hpp \ src/util/QStringHash.hpp \ + src/util/StreamerMode.hpp \ src/util/Twitch.hpp \ src/util/rangealgorithm.hpp \ src/util/RapidjsonHelpers.hpp \ diff --git a/src/util/StreamerMode.cpp b/src/util/StreamerMode.cpp new file mode 100644 index 000000000..b8c73c6f5 --- /dev/null +++ b/src/util/StreamerMode.cpp @@ -0,0 +1,54 @@ +#include "StreamerMode.hpp" + +#ifdef USEWINSDK +# include + +# include +# include +# pragma comment(lib, "Wtsapi32.lib") +#endif + +namespace chatterino { + +const QStringList &broadcastingBinaries() +{ +#ifdef USEWINSDK + static QStringList bins = {"obs.exe", "obs64.exe"}; +#else + static QStringList bins = {}; +#endif + return bins; +} + +bool isInStreamerMode() +{ +#ifdef USEWINSDK + if (IsWindowsVistaOrGreater()) + { + WTS_PROCESS_INFO *pWPIs = nullptr; + DWORD dwProcCount = 0; + + if (WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, NULL, 1, &pWPIs, + &dwProcCount)) + { + //Go through all processes retrieved + for (DWORD i = 0; i < dwProcCount; i++) + { + QString processName = QString::fromUtf16( + reinterpret_cast(pWPIs[i].pProcessName)); + qDebug() << processName; + + if (broadcastingBinaries().contains(processName)) + return true; + } + } + + if (pWPIs) + WTSFreeMemory(pWPIs); + } +#endif + + return false; +} + +} // namespace chatterino diff --git a/src/util/StreamerMode.hpp b/src/util/StreamerMode.hpp new file mode 100644 index 000000000..10a58295c --- /dev/null +++ b/src/util/StreamerMode.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace chatterino { + +const QStringList &broadcastingBinaries(); +bool isInStreamerMode(); + +} // namespace chatterino diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 74d35c025..fd31b1b9e 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -14,6 +14,7 @@ #include "util/LayoutCreator.hpp" #include "util/PostToThread.hpp" #include "util/Shortcut.hpp" +#include "util/StreamerMode.hpp" #include "widgets/Label.hpp" #include "widgets/helper/ChannelView.hpp" #include "widgets/helper/EffectLabel.hpp" @@ -484,7 +485,10 @@ void UserInfoPopup::updateUserData() [] { // failure }); - this->loadAvatar(user.profileImageUrl); + if (!isInStreamerMode()) + { + this->loadAvatar(user.profileImageUrl); + } getHelix()->getUserFollowers( user.id,