Delay resume playback on startup to make sure Tidal login is refreshed

This commit is contained in:
Jonas Kvinge 2021-07-14 13:02:54 +02:00
parent facf49b2b7
commit fab1d94d34
2 changed files with 12 additions and 3 deletions

View File

@ -1431,7 +1431,9 @@ void MainWindow::LoadPlaybackStatus() {
s.endGroup();
if (resume_playback && playback_state != Engine::Empty && playback_state != Engine::Idle) {
QObject::connect(app_->playlist_manager(), &PlaylistManager::AllPlaylistsLoaded, this, &MainWindow::ResumePlayback);
QObject::connect(app_->playlist_manager(), &PlaylistManager::AllPlaylistsLoaded, this, [this]() {
QTimer::singleShot(400, this, &MainWindow::ResumePlayback);
});
}
}

View File

@ -20,6 +20,7 @@
#include "config.h"
#include <memory>
#include <chrono>
#include <QObject>
#include <QDesktopServices>
@ -80,6 +81,8 @@ const char *TidalService::kArtistsSongsFtsTable = "tidal_artists_songs_fts";
const char *TidalService::kAlbumsSongsFtsTable = "tidal_albums_songs_fts";
const char *TidalService::kSongsFtsTable = "tidal_songs_fts";
using namespace std::chrono_literals;
TidalService::TidalService(Application *app, QObject *parent)
: InternetService(Song::Source_Tidal, "Tidal", "tidal", TidalSettingsPage::kSettingsGroup, SettingsDialog::Page_Tidal, app, parent),
app_(app),
@ -258,8 +261,12 @@ void TidalService::LoadSession() {
if (!refresh_token_.isEmpty()) {
qint64 time = expires_in_ - (QDateTime::currentDateTime().toSecsSinceEpoch() - login_time_);
if (time < 6) time = 6;
timer_refresh_login_->setInterval(static_cast<int>(time * kMsecPerSec));
if (time <= 0) {
timer_refresh_login_->setInterval(200ms);
}
else {
timer_refresh_login_->setInterval(static_cast<int>(time * kMsecPerSec));
}
timer_refresh_login_->start();
}