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

Fixes #251: segfault (stopClient) and showing error (not active window) #252

Merged
merged 4 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 7 additions & 5 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
{
trayIcon->deleteLater();
event->accept();
mainContent = nullptr;
}
}

Expand Down Expand Up @@ -593,8 +594,10 @@ auto MainWindow::startClient() -> const SpotifyClient::Runner *

void MainWindow::stopClient()
{
spotifyRunner->deleteLater();
spotifyRunner = nullptr;
if (spotifyRunner != nullptr){
spotifyRunner->deleteLater();
spotifyRunner = nullptr;
}
}

void MainWindow::openLyrics(const lib::spt::track &track)
Expand Down Expand Up @@ -830,9 +833,8 @@ void MainWindow::resetLibraryPlaylist() const

void MainWindow::onSpotifyStatusChanged(const QString &status)
{
if ((windowState() & Qt::WindowActive) > 0)
kraxarn marked this conversation as resolved.
Show resolved Hide resolved
{
if (!status.isEmpty() && mainContent != nullptr){
QMessageBox::warning(this, QStringLiteral("Client error"),
QString("Failed to start Spotify client: %1").arg(status));
QString("Spotify client error: %1").arg(status));
}
}
29 changes: 25 additions & 4 deletions src/spotifyclient/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,17 @@ void SpotifyClient::Runner::logOutput(const QByteArray &output, lib::log_type lo

log.emplace_back(lib::date_time::now(), logType, line.toStdString());

#ifdef USE_KEYCHAIN
if (line.contains(QStringLiteral("Bad credentials")))
{
#ifdef USE_KEYCHAIN
const auto username = QString::fromStdString(settings.spotify.username);
if (Keychain::clearPassword(username))
{
lib::log::warn("Bad credentials, cleared saved password");
}

#endif
emit statusChanged(QStringLiteral("Bad credentials, please try again"));
}
#endif
}
}

Expand Down Expand Up @@ -243,7 +242,29 @@ void SpotifyClient::Runner::onStarted()

void SpotifyClient::Runner::onErrorOccurred(QProcess::ProcessError error)
{
emit statusChanged(QString("Error %1").arg(error));
std::string_view message;
kraxarn marked this conversation as resolved.
Show resolved Hide resolved
switch (error)
{
case QProcess::FailedToStart:
message = "Process failed to start";
break;
case QProcess::Crashed:
message = "Process stopped or crashed";
break;
case QProcess::Timedout:
message = "Process timed out";
break;
case QProcess::WriteError:
message = "Process with write error";
break;
case QProcess::ReadError:
message = "Process with read error";
break;
default:
message = "Process with unknown error";
break;
}
emit statusChanged(QString::fromUtf8(message.data(), message.size()));
}

auto SpotifyClient::Runner::getLog() -> const std::vector<lib::log_message> &
Expand Down