Use flatpak-spawn to run streamlink when running as a flatpak (#3178)

Co-authored-by: Leon Richardt <leon.richardt@gmail.com>
Co-authored-by: Paweł <zneix@zneix.eu>
This commit is contained in:
ilyazzz 2021-08-21 14:00:01 +03:00 committed by GitHub
parent d7fd08b1d6
commit a7ef7e6f7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 18 deletions

View file

@ -14,6 +14,7 @@
- Bugfix: Notifications for moderators about other moderators deleting messages can now be disabled. (#3121) - Bugfix: Notifications for moderators about other moderators deleting messages can now be disabled. (#3121)
- Bugfix: Moderation mode and active filters are now preserved when opening a split as a popup. (#3113, #3130) - Bugfix: Moderation mode and active filters are now preserved when opening a split as a popup. (#3113, #3130)
- Bugfix: Fixed a bug that caused all badge highlights to use the same color. (#3132, #3134) - Bugfix: Fixed a bug that caused all badge highlights to use the same color. (#3132, #3134)
- Bugfix: Allow starting Streamlink from Chatterino when running as a Flatpak. (#3178)
- Dev: Renamed CMake's build option `USE_SYSTEM_QT5KEYCHAIN` to `USE_SYSTEM_QTKEYCHAIN`. (#3103) - Dev: Renamed CMake's build option `USE_SYSTEM_QT5KEYCHAIN` to `USE_SYSTEM_QTKEYCHAIN`. (#3103)
- Dev: Add benchmarks that can be compiled with the `BUILD_BENCHMARKS` CMake flag. Off by default. (#3038) - Dev: Add benchmarks that can be compiled with the `BUILD_BENCHMARKS` CMake flag. Off by default. (#3038)

View file

@ -71,4 +71,9 @@ const bool &Version::isSupportedOS() const
return this->isSupportedOS_; return this->isSupportedOS_;
} }
bool Version::isFlatpak() const
{
return QFileInfo::exists("/.flatpak-info");
}
} // namespace chatterino } // namespace chatterino

View file

@ -29,6 +29,7 @@ public:
const QString &dateOfBuild() const; const QString &dateOfBuild() const;
const QString &fullVersion() const; const QString &fullVersion() const;
const bool &isSupportedOS() const; const bool &isSupportedOS() const;
bool isFlatpak() const;
private: private:
Version(); Version();

View file

@ -232,7 +232,9 @@ void Updates::installUpdates()
void Updates::checkForUpdates() void Updates::checkForUpdates()
{ {
if (!Version::instance().isSupportedOS()) auto version = Version::instance();
if (!version.isSupportedOS())
{ {
qCDebug(chatterinoUpdate) qCDebug(chatterinoUpdate)
<< "Update checking disabled because OS doesn't appear to be one " << "Update checking disabled because OS doesn't appear to be one "
@ -241,7 +243,7 @@ void Updates::checkForUpdates()
} }
// Disable updates on Flatpak // Disable updates on Flatpak
if (QFileInfo::exists("/.flatpak-info")) if (version.isFlatpak())
{ {
return; return;
} }

View file

@ -10,6 +10,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QProcess> #include <QProcess>
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include "common/Version.hpp"
#include <functional> #include <functional>
@ -35,18 +36,6 @@ namespace {
#endif #endif
} }
QString getStreamlinkProgram()
{
if (getSettings()->streamlinkUseCustomPath)
{
return getSettings()->streamlinkPath + "/" + getBinaryName();
}
else
{
return getBinaryName();
}
}
bool checkStreamlinkPath(const QString &path) bool checkStreamlinkPath(const QString &path)
{ {
QFileInfo fileinfo(path); QFileInfo fileinfo(path);
@ -83,7 +72,27 @@ namespace {
QProcess *createStreamlinkProcess() QProcess *createStreamlinkProcess()
{ {
auto p = new QProcess; auto p = new QProcess;
p->setProgram(getStreamlinkProgram());
const QString path = [] {
if (getSettings()->streamlinkUseCustomPath)
{
return getSettings()->streamlinkPath + "/" + getBinaryName();
}
else
{
return QString{getBinaryName()};
}
}();
if (Version::instance().isFlatpak())
{
p->setProgram("flatpak-spawn");
p->setArguments({"--host", path});
}
else
{
p->setProgram(path);
}
QObject::connect(p, &QProcess::errorOccurred, [=](auto err) { QObject::connect(p, &QProcess::errorOccurred, [=](auto err) {
if (err == QProcess::FailedToStart) if (err == QProcess::FailedToStart)
@ -165,7 +174,8 @@ void getStreamQualities(const QString &channelURL,
} }
}); });
p->setArguments({channelURL, "--default-stream=KKona"}); p->setArguments(p->arguments() +
QStringList{channelURL, "--default-stream=KKona"});
p->start(); p->start();
} }
@ -173,7 +183,9 @@ void getStreamQualities(const QString &channelURL,
void openStreamlink(const QString &channelURL, const QString &quality, void openStreamlink(const QString &channelURL, const QString &quality,
QStringList extraArguments) QStringList extraArguments)
{ {
QStringList arguments = extraArguments << channelURL << quality; auto proc = createStreamlinkProcess();
auto arguments = proc->arguments()
<< extraArguments << channelURL << quality;
// Remove empty arguments before appending additional streamlink options // Remove empty arguments before appending additional streamlink options
// as the options might purposely contain empty arguments // as the options might purposely contain empty arguments
@ -182,7 +194,8 @@ void openStreamlink(const QString &channelURL, const QString &quality,
QString additionalOptions = getSettings()->streamlinkOpts.getValue(); QString additionalOptions = getSettings()->streamlinkOpts.getValue();
arguments << splitCommand(additionalOptions); arguments << splitCommand(additionalOptions);
bool res = QProcess::startDetached(getStreamlinkProgram(), arguments); proc->setArguments(std::move(arguments));
bool res = proc->startDetached();
if (!res) if (!res)
{ {