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:
+29
-16
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user