mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Added automatic streamer mode detection to Linux (#2316)
This commit is contained in:
parent
b3e01a40d7
commit
fca62f7c1d
7 changed files with 104 additions and 47 deletions
|
@ -3,7 +3,7 @@
|
|||
## Unversioned
|
||||
|
||||
- Major: Added "Channel Filters". See https://wiki.chatterino.com/Filters/ for how they work or how to configure them. (#1748, #2083, #2090, #2200)
|
||||
- Major: Added Streamer Mode configuration (under `Settings -> General`), where you can select which features of Chatterino should behave differently when you are in Streamer Mode. (#2001)
|
||||
- Major: Added Streamer Mode configuration (under `Settings -> General`), where you can select which features of Chatterino should behave differently when you are in Streamer Mode. (#2001, #2316)
|
||||
- Major: Color mentions to match the mentioned users. You can disable this by unchecking "Color @usernames" under `Settings -> General -> Advanced (misc.)`. (#1963, #2284)
|
||||
- Minor: Added a button to the split context menu to open the moderation view for a channel when the account selected has moderator permissions. (#2321)
|
||||
- Minor: Made BetterTTV emote tooltips use authors' display name. (#2267)
|
||||
|
|
|
@ -28,6 +28,8 @@ Q_LOGGING_CATEGORY(chatterinoNuulsuploader, "chatterino.nuulsuploader",
|
|||
logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoPubsub, "chatterino.pubsub", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoStreamlink, "chatterino.streamlink", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoStreamerMode, "chatterino.streamermode",
|
||||
logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoTokenizer, "chatterino.tokenizer", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoTwitch, "chatterino.twitch", logThreshold);
|
||||
Q_LOGGING_CATEGORY(chatterinoUpdate, "chatterino.update", logThreshold);
|
||||
|
|
|
@ -21,6 +21,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoNotification);
|
|||
Q_DECLARE_LOGGING_CATEGORY(chatterinoNuulsuploader);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoPubsub);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoStreamlink);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoStreamerMode);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoTokenizer);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoTwitch);
|
||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoUpdate);
|
||||
|
|
|
@ -137,7 +137,7 @@ void AbstractIrcServer::open(ConnectionType type)
|
|||
}
|
||||
}
|
||||
|
||||
void AbstractIrcServer::addGlobalSystemMessage(QString messageText)
|
||||
void AbstractIrcServer::addGlobalSystemMessage(const QString &messageText)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->channelMutex);
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
|
||||
void addFakeMessage(const QString &data);
|
||||
|
||||
void addGlobalSystemMessage(const QString &messageText);
|
||||
|
||||
// iteration
|
||||
void forEachChannel(std::function<void(ChannelPtr)> func);
|
||||
|
||||
|
@ -78,8 +80,6 @@ protected:
|
|||
|
||||
void open(ConnectionType type);
|
||||
|
||||
void addGlobalSystemMessage(QString messageText);
|
||||
|
||||
QMap<QString, std::weak_ptr<Channel>> channels;
|
||||
std::mutex channelMutex;
|
||||
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#include "StreamerMode.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/Window.hpp"
|
||||
#include "widgets/helper/NotebookTab.hpp"
|
||||
#include "widgets/splits/Split.hpp"
|
||||
|
||||
#ifdef USEWINSDK
|
||||
# include <Windows.h>
|
||||
|
@ -14,12 +23,14 @@ namespace chatterino {
|
|||
|
||||
constexpr int cooldownInS = 10;
|
||||
|
||||
bool shouldShowWarning = true;
|
||||
|
||||
const QStringList &broadcastingBinaries()
|
||||
{
|
||||
#ifdef USEWINSDK
|
||||
static QStringList bins = {"obs.exe", "obs64.exe"};
|
||||
#else
|
||||
static QStringList bins = {};
|
||||
static QStringList bins = {"obs"};
|
||||
#endif
|
||||
return bins;
|
||||
}
|
||||
|
@ -32,7 +43,48 @@ bool isInStreamerMode()
|
|||
return true;
|
||||
case StreamerModeSetting::Disabled:
|
||||
return false;
|
||||
case StreamerModeSetting::DetectObs:
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
||||
static bool cache = false;
|
||||
static QDateTime time = QDateTime();
|
||||
|
||||
if (time.isValid() &&
|
||||
time.addSecs(cooldownInS) > QDateTime::currentDateTime())
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
time = QDateTime::currentDateTime();
|
||||
|
||||
QProcess p;
|
||||
p.start("pgrep", {"-x", broadcastingBinaries().join("|")},
|
||||
QIODevice::NotOpen);
|
||||
|
||||
if (p.waitForFinished(1000) &&
|
||||
p.exitStatus() == QProcess::NormalExit)
|
||||
{
|
||||
cache = (p.exitCode() == 0);
|
||||
return (p.exitCode() == 0);
|
||||
}
|
||||
|
||||
// Fallback to false and showing a warning
|
||||
|
||||
if (shouldShowWarning)
|
||||
{
|
||||
shouldShowWarning = false;
|
||||
|
||||
getApp()->twitch2->addGlobalSystemMessage(
|
||||
"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.");
|
||||
}
|
||||
|
||||
qCWarning(chatterinoStreamerMode) << "pgrep execution timed out!";
|
||||
|
||||
cache = false;
|
||||
return false;
|
||||
#endif
|
||||
|
||||
#ifdef USEWINSDK
|
||||
if (!IsWindowsVistaOrGreater())
|
||||
|
@ -47,14 +99,13 @@ bool isInStreamerMode()
|
|||
{
|
||||
return cache;
|
||||
}
|
||||
|
||||
time = QDateTime::currentDateTime();
|
||||
|
||||
WTS_PROCESS_INFO *pWPIs = nullptr;
|
||||
DWORD dwProcCount = 0;
|
||||
|
||||
if (WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, NULL, 1, &pWPIs,
|
||||
&dwProcCount))
|
||||
if (WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, NULL, 1,
|
||||
&pWPIs, &dwProcCount))
|
||||
{
|
||||
//Go through all processes retrieved
|
||||
for (DWORD i = 0; i < dwProcCount; i++)
|
||||
|
@ -78,6 +129,8 @@ bool isInStreamerMode()
|
|||
cache = false;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -320,13 +320,14 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
|
||||
layout.addTitle("Streamer Mode");
|
||||
layout.addDescription(
|
||||
"Chatterino can automatically change behavior if it "
|
||||
"detects that \"OBS Studio\" is running.\nSelect which "
|
||||
"things you want to change while streaming");
|
||||
"Chatterino can automatically change behavior if it detects that \"OBS "
|
||||
"Studio\" is running (Automatic mode works only on Windows and "
|
||||
"Linux).\nSelect which things you want to change while streaming");
|
||||
|
||||
ComboBox *dankDropdown =
|
||||
layout.addDropdown<std::underlying_type<StreamerModeSetting>::type>(
|
||||
"Enable Streamer Mode", {"No", "Yes", "Detect OBS (Windows only)"},
|
||||
"Enable Streamer Mode",
|
||||
{"Disabled", "Enabled", "Automatic (Detect OBS)"},
|
||||
s.enableStreamerMode,
|
||||
[](int value) {
|
||||
return value;
|
||||
|
|
Loading…
Reference in a new issue