diff --git a/CHANGELOG.md b/CHANGELOG.md index d79f8c9c2..d77657086 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/common/Version.cpp b/src/common/Version.cpp index aa8639dce..67a3bb477 100644 --- a/src/common/Version.cpp +++ b/src/common/Version.cpp @@ -71,4 +71,9 @@ const bool &Version::isSupportedOS() const return this->isSupportedOS_; } +bool Version::isFlatpak() const +{ + return QFileInfo::exists("/.flatpak-info"); +} + } // namespace chatterino diff --git a/src/common/Version.hpp b/src/common/Version.hpp index 1a858c0ea..967363358 100644 --- a/src/common/Version.hpp +++ b/src/common/Version.hpp @@ -29,6 +29,7 @@ public: const QString &dateOfBuild() const; const QString &fullVersion() const; const bool &isSupportedOS() const; + bool isFlatpak() const; private: Version(); diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index 5751b59cc..cf32b30ff 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -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; } diff --git a/src/util/StreamLink.cpp b/src/util/StreamLink.cpp index b631cad51..8b61ca9d7 100644 --- a/src/util/StreamLink.cpp +++ b/src/util/StreamLink.cpp @@ -10,6 +10,7 @@ #include #include #include "common/QLogging.hpp" +#include "common/Version.hpp" #include @@ -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) {