[spotify] Prevent duplicate scan on startup

The logged_in callback is called during relogin in the initscan.
Additionally initscan explicitly starts the scan leading to a duplicate
scan run.
To prevent this from happening removed the scan call in the logged_in
callback and split the spotify_login_user function into a private
function (without scan) and a public function (with scan).
This commit is contained in:
chme 2017-12-18 22:05:24 +01:00
parent 83d8a55701
commit 210e6228bc

View File

@ -1138,9 +1138,6 @@ logged_in(sp_session *sess, sp_error error)
CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck)); CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck));
listener_notify(LISTENER_SPOTIFY); listener_notify(LISTENER_SPOTIFY);
// Trigger scan after successful login to libspotify
library_exec_async(webapi_rescan, NULL);
} }
/** /**
@ -1571,10 +1568,11 @@ spotify_status_info_get(struct spotify_status_info *info)
} }
/* Thread: library, httpd */ /* Thread: library, httpd */
int static int
spotify_login_user(const char *user, const char *password, char **errmsg) login_user(const char *user, const char *password, char **errmsg)
{ {
sp_error err; sp_error err;
int ret;
if (!g_sess) if (!g_sess)
{ {
@ -1643,7 +1641,30 @@ spotify_login_user(const char *user, const char *password, char **errmsg)
CHECK_ERR(L_SPOTIFY, pthread_cond_wait(&login_cond, &login_lck)); CHECK_ERR(L_SPOTIFY, pthread_cond_wait(&login_cond, &login_lck));
CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck)); CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck));
return 0; CHECK_ERR(L_SPOTIFY, pthread_mutex_lock(&status_lck));
ret = spotify_status_info.libspotify_logged_in ? 0 : -1;
CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&status_lck));
if (ret < 0 && errmsg)
*errmsg = safe_asprintf("Login failed");
return ret;
}
/* Thread: httpd, library */
int
spotify_login_user(const char *user, const char *password, char **errmsg)
{
int ret;
ret = login_user(user, password, errmsg);
if (ret == 0)
{
// Trigger scan after successful login to libspotify
library_exec_async(webapi_rescan, NULL);
}
return ret;
} }
/* Thread: library */ /* Thread: library */
@ -2004,7 +2025,7 @@ initscan()
* Login to spotify needs to be done before scanning tracks from the web api. * Login to spotify needs to be done before scanning tracks from the web api.
* (Scanned tracks need to be registered with libspotify for playback) * (Scanned tracks need to be registered with libspotify for playback)
*/ */
spotify_login_user(NULL, NULL, NULL); login_user(NULL, NULL, NULL);
/* /*
* Scan saved tracks from the web api * Scan saved tracks from the web api