2020-07-12 22:44:33 +02:00
|
|
|
#include "StreamerMode.hpp"
|
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "common/QLogging.hpp"
|
|
|
|
#include "messages/MessageBuilder.hpp"
|
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2020-10-11 13:52:14 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2021-01-09 22:14:25 +01:00
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "widgets/helper/NotebookTab.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Notebook.hpp"
|
2021-01-09 22:14:25 +01:00
|
|
|
#include "widgets/splits/Split.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Window.hpp"
|
2020-10-11 13:52:14 +02:00
|
|
|
|
2020-07-12 22:44:33 +02:00
|
|
|
#ifdef USEWINSDK
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
// clang-format off
|
2020-07-12 22:44:33 +02:00
|
|
|
# include <Windows.h>
|
|
|
|
|
|
|
|
# include <VersionHelpers.h>
|
|
|
|
# include <WtsApi32.h>
|
|
|
|
# pragma comment(lib, "Wtsapi32.lib")
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
// clang-format on
|
2020-07-12 22:44:33 +02:00
|
|
|
#endif
|
|
|
|
|
2021-05-08 15:57:00 +02:00
|
|
|
#include <QProcess>
|
|
|
|
|
2020-07-12 22:44:33 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2020-08-22 15:27:42 +02:00
|
|
|
constexpr int cooldownInS = 10;
|
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
bool shouldShowWarning = true;
|
|
|
|
|
2020-07-12 22:44:33 +02:00
|
|
|
const QStringList &broadcastingBinaries()
|
|
|
|
{
|
|
|
|
#ifdef USEWINSDK
|
2022-05-28 14:17:42 +02:00
|
|
|
static QStringList bins = {
|
|
|
|
"obs.exe", "obs64.exe", "PRISMLiveStudio.exe",
|
|
|
|
"XSplit.Core.exe", "TwitchStudio.exe", "vMix64.exe"};
|
2020-07-12 22:44:33 +02:00
|
|
|
#else
|
2022-05-28 14:17:42 +02:00
|
|
|
static QStringList bins = {"obs", "Twitch Studio", "Streamlabs Desktop"};
|
2020-07-12 22:44:33 +02:00
|
|
|
#endif
|
|
|
|
return bins;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInStreamerMode()
|
|
|
|
{
|
2020-10-11 13:52:14 +02:00
|
|
|
switch (getSettings()->enableStreamerMode.getEnum())
|
|
|
|
{
|
|
|
|
case StreamerModeSetting::Enabled:
|
|
|
|
return true;
|
|
|
|
case StreamerModeSetting::Disabled:
|
|
|
|
return false;
|
2022-05-28 14:17:42 +02:00
|
|
|
case StreamerModeSetting::DetectStreamingSoftware:
|
2020-10-11 13:52:14 +02:00
|
|
|
|
2021-01-30 13:11:08 +01:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
|
2020-08-22 15:27:42 +02:00
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
static bool cache = false;
|
|
|
|
static QDateTime time = QDateTime();
|
|
|
|
|
|
|
|
if (time.isValid() &&
|
|
|
|
time.addSecs(cooldownInS) > QDateTime::currentDateTime())
|
|
|
|
{
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
time = QDateTime::currentDateTime();
|
2020-08-22 15:27:42 +02:00
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
QProcess p;
|
|
|
|
p.start("pgrep", {"-x", broadcastingBinaries().join("|")},
|
|
|
|
QIODevice::NotOpen);
|
2020-08-22 15:27:42 +02:00
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
if (p.waitForFinished(1000) &&
|
|
|
|
p.exitStatus() == QProcess::NormalExit)
|
|
|
|
{
|
|
|
|
cache = (p.exitCode() == 0);
|
|
|
|
return (p.exitCode() == 0);
|
|
|
|
}
|
2020-07-12 22:44:33 +02:00
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
// Fallback to false and showing a warning
|
2020-10-11 13:52:14 +02:00
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
if (shouldShowWarning)
|
2020-07-12 22:44:33 +02:00
|
|
|
{
|
2021-01-09 22:14:25 +01:00
|
|
|
shouldShowWarning = false;
|
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
getApp()->twitch->addGlobalSystemMessage(
|
2021-01-09 22:14:25 +01:00
|
|
|
"Streamer Mode is set to Automatic, but pgrep is missing. "
|
|
|
|
"Install it to fix the issue or set Streamer Mode to "
|
|
|
|
"Enabled or Disabled in the Settings.");
|
2020-07-12 22:44:33 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
qCWarning(chatterinoStreamerMode) << "pgrep execution timed out!";
|
|
|
|
|
|
|
|
cache = false;
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USEWINSDK
|
|
|
|
if (!IsWindowsVistaOrGreater())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static bool cache = false;
|
|
|
|
static QDateTime time = QDateTime();
|
|
|
|
|
|
|
|
if (time.isValid() &&
|
|
|
|
time.addSecs(cooldownInS) > QDateTime::currentDateTime())
|
|
|
|
{
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
time = QDateTime::currentDateTime();
|
2020-07-12 22:44:33 +02:00
|
|
|
|
2021-01-09 22:14:25 +01:00
|
|
|
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<char16_t *>(pWPIs[i].pProcessName));
|
|
|
|
|
|
|
|
if (broadcastingBinaries().contains(processName))
|
|
|
|
{
|
|
|
|
cache = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pWPIs)
|
|
|
|
{
|
|
|
|
WTSFreeMemory(pWPIs);
|
|
|
|
}
|
|
|
|
|
|
|
|
cache = false;
|
2020-10-11 13:52:14 +02:00
|
|
|
#endif
|
2021-01-09 22:14:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-12 22:44:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|