Skip to content

Commit

Permalink
Check for pulseaudio support
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed May 4, 2020
1 parent c45aabf commit b8e040f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/spotify/clienthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ QString ClientHandler::start()
{
Settings settings;
// Check if empty
auto path = settings.sptPath();
path = settings.sptPath();
if (path.isEmpty())
return "path is empty";
// Check if path exists
Expand All @@ -39,13 +39,22 @@ QString ClientHandler::start()
return "no password provided";
// Attempt to start spotifyd
process = new QProcess();
process->start(path, {
"--backend", "pulseaudio",
"--bitrate", QString::number(settings.sptBitrate()),
"--device-name", "spotify-qt",
"--username", username,
"--password", password
QStringList arguments({
"--bitrate", QString::number(settings.sptBitrate()),
"--device-name", "spotify-qt",
"--username", username,
"--password", password
});
if (supportsPulse())
arguments.append({
"--backend", "pulseaudio"
});
else
qDebug() << "warning: spotifyd was compiled without pulseaudio support";
process->start(path, arguments);
return QString();
}

QString ClientHandler::clientExec(const QString &path, const QStringList &arguments)
{
// Check if it exists
Expand All @@ -64,6 +73,13 @@ QString ClientHandler::clientExec(const QString &path, const QStringList &argume
return process.readAllStandardOutput().trimmed();
}

bool ClientHandler::supportsPulse()
{
return clientExec(path, {
"--help"
}).contains("pulseaudio");
}

QString ClientHandler::version(const QString &path)
{
return clientExec(path, {
Expand Down
2 changes: 2 additions & 0 deletions src/spotify/clienthandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace spt
QProcess *process = nullptr;
private:
QWidget *parent;
QString path;
bool supportsPulse();
static QString clientExec(const QString &path, const QStringList &arguments);
};
}

0 comments on commit b8e040f

Please sign in to comment.