Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 21 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Bugfix: Fixed a bug that caused all badge highlights to use the same color. (#3132, #3134)
- 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)
- Bugfix: Use `flatpak-spawn` to call streamlink when running as a Flatapk. Fixes streamlink functionality. (#3178)
ilya-zlobintsev marked this conversation as resolved.
Show resolved Hide resolved

## 2.3.4

Expand Down
5 changes: 5 additions & 0 deletions src/common/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ const bool &Version::isSupportedOS() const
return this->isSupportedOS_;
}

bool Version::isFlatpak() const
{
return QFileInfo::exists("/.flatpak-info");
}

} // namespace chatterino
1 change: 1 addition & 0 deletions src/common/Version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Version
const QString &dateOfBuild() const;
const QString &fullVersion() const;
const bool &isSupportedOS() const;
bool isFlatpak() const;

private:
Version();
Expand Down
6 changes: 4 additions & 2 deletions src/singletons/Updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -241,7 +243,7 @@ void Updates::checkForUpdates()
}

// Disable updates on Flatpak
if (QFileInfo::exists("/.flatpak-info"))
if (version.isFlatpak())
{
return;
}
Expand Down
38 changes: 34 additions & 4 deletions src/util/StreamLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QFileInfo>
#include <QProcess>
#include "common/QLogging.hpp"
#include "common/Version.hpp"

#include <functional>

Expand Down Expand Up @@ -83,7 +84,17 @@ namespace {
QProcess *createStreamlinkProcess()
{
auto p = new QProcess;
p->setProgram(getStreamlinkProgram());

if (Version::instance().isFlatpak())
{
p->setProgram("flatpak-spawn");

p->setArguments({"--host", getStreamlinkProgram()});
}
else
{
p->setProgram(getStreamlinkProgram());
}

QObject::connect(p, &QProcess::errorOccurred, [=](auto err) {
if (err == QProcess::FailedToStart)
Expand All @@ -98,6 +109,9 @@ namespace {
p->deleteLater();
});

qCWarning(chatterinoStreamlink)
<< "command:" << p->program() << p->arguments().join(" ");

QObject::connect(
p,
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
Expand Down Expand Up @@ -165,15 +179,31 @@ void getStreamQualities(const QString &channelURL,
}
});

p->setArguments({channelURL, "--default-stream=KKona"});
p->setArguments(p->arguments() +
QStringList({channelURL, "--default-stream=KKona"}));
ilya-zlobintsev marked this conversation as resolved.
Show resolved Hide resolved

p->start();
}

void openStreamlink(const QString &channelURL, const QString &quality,
QStringList extraArguments)
{
QStringList arguments = extraArguments << channelURL << quality;
QStringList arguments;

QString program;

if (Version::instance().isFlatpak())
{
program = "flatpak-spawn";

arguments << "--host" << getStreamlinkProgram();
}
else
{
program = getStreamlinkProgram();
}
ilya-zlobintsev marked this conversation as resolved.
Show resolved Hide resolved

arguments << extraArguments << channelURL << quality;

// Remove empty arguments before appending additional streamlink options
// as the options might purposely contain empty arguments
Expand All @@ -182,7 +212,7 @@ void openStreamlink(const QString &channelURL, const QString &quality,
QString additionalOptions = getSettings()->streamlinkOpts.getValue();
arguments << splitCommand(additionalOptions);

bool res = QProcess::startDetached(getStreamlinkProgram(), arguments);
bool res = QProcess::startDetached(program, arguments);

if (!res)
{
Expand Down