diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 27fbd95a..8e104f3b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -94,6 +94,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { trayIcon->deleteLater(); event->accept(); + mainContent = nullptr; } } @@ -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) @@ -830,9 +833,20 @@ void MainWindow::resetLibraryPlaylist() const void MainWindow::onSpotifyStatusChanged(const QString &status) { + if (status.isEmpty() || mainContent == nullptr) + { + return; + } + + const auto message = QString("Spotify client error: %1") + .arg(status); + if ((windowState() & Qt::WindowActive) > 0) { - QMessageBox::warning(this, QStringLiteral("Client error"), - QString("Failed to start Spotify client: %1").arg(status)); + StatusMessage::warn(message); + } + else + { + QMessageBox::warning(this, QStringLiteral("Client error"), message); } } diff --git a/src/spotifyclient/runner.cpp b/src/spotifyclient/runner.cpp index 6bef9b0c..ec451d4a 100644 --- a/src/spotifyclient/runner.cpp +++ b/src/spotifyclient/runner.cpp @@ -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 } } @@ -243,7 +242,36 @@ void SpotifyClient::Runner::onStarted() void SpotifyClient::Runner::onErrorOccurred(QProcess::ProcessError error) { - emit statusChanged(QString("Error %1").arg(error)); + QString message; + + switch (error) + { + case QProcess::FailedToStart: + message = QStringLiteral("Process failed to start"); + break; + + case QProcess::Crashed: + message = QStringLiteral("Process stopped or crashed"); + break; + + case QProcess::Timedout: + message = QStringLiteral("Process timed out"); + break; + + case QProcess::WriteError: + message = QStringLiteral("Process with write error"); + break; + + case QProcess::ReadError: + message = QStringLiteral("Process with read error"); + break; + + default: + message = QStringLiteral("Process with unknown error"); + break; + } + + emit statusChanged(message); } auto SpotifyClient::Runner::getLog() -> const std::vector &