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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main point of this was to not grab attention when the window is minimized. Maybe StatusMessage::error() is better when the window isn't active? That way, you have to actively open the window to see if anything went wrong.

{
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that this is still primarily a C++11 project, so std::string_view isn't available. It's something I'm planning to change for the next major release, as some configurations require C++17, and mixing versions is quite messy. However, in this case, I think QStringLiteral makes more sense, no point in working with C++ strings, when you only want to use it as a Qt string.

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