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: 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: 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: 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_;
}
bool Version::isFlatpak() const
{
return QFileInfo::exists("/.flatpak-info");
}
} // namespace chatterino

View file

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

View file

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

View file

@ -10,6 +10,7 @@
#include <QFileInfo>
#include <QProcess>
#include "common/QLogging.hpp"
#include "common/Version.hpp"
#include <functional>
@ -35,18 +36,6 @@ namespace {
#endif
}
QString getStreamlinkProgram()
{
if (getSettings()->streamlinkUseCustomPath)
{
return getSettings()->streamlinkPath + "/" + getBinaryName();
}
else
{
return getBinaryName();
}
}
bool checkStreamlinkPath(const QString &path)
{
QFileInfo fileinfo(path);
@ -83,7 +72,27 @@ namespace {
QProcess *createStreamlinkProcess()
{
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) {
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();
}
@ -173,7 +183,9 @@ void getStreamQualities(const QString &channelURL,
void openStreamlink(const QString &channelURL, const QString &quality,
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
// 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();
arguments << splitCommand(additionalOptions);
bool res = QProcess::startDetached(getStreamlinkProgram(), arguments);
proc->setArguments(std::move(arguments));
bool res = proc->startDetached();
if (!res)
{