Gracefully handle failures when asking for a password
Fix for #446 and #447.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# ncmpcpp-0.9.2 (????-??-??)
|
||||
* Revert suppression of output of all external commands as that makes e.g album
|
||||
art addons no longer work.
|
||||
* Gracefully handle failures when asking for a password.
|
||||
|
||||
# ncmpcpp-0.9.1 (2020-12-23)
|
||||
* Add support for fetching lyrics from musixmatch.com.
|
||||
|
||||
@@ -192,14 +192,29 @@ void Status::handleServerError(MPD::ServerError &e)
|
||||
Statusbar::printf("MPD: %1%", e.what());
|
||||
if (e.code() == MPD_SERVER_ERROR_PERMISSION)
|
||||
{
|
||||
NC::Window::ScopedPromptHook helper(*wFooter, nullptr);
|
||||
Statusbar::put() << "Password: ";
|
||||
Mpd.SetPassword(wFooter->prompt("", -1, true));
|
||||
try {
|
||||
try
|
||||
{
|
||||
NC::Window::ScopedPromptHook helper(*wFooter, nullptr);
|
||||
Statusbar::put() << "Password: ";
|
||||
Mpd.SetPassword(wFooter->prompt("", -1, true));
|
||||
Mpd.SendPassword();
|
||||
Statusbar::print("Password accepted");
|
||||
} catch (MPD::ServerError &e_prim) {
|
||||
handleServerError(e_prim);
|
||||
}
|
||||
// SendPassword might throw if connection is closed
|
||||
catch (MPD::ClientError &e_prim)
|
||||
{
|
||||
handleClientError(e_prim);
|
||||
}
|
||||
// Wrong password, we'll ask again later
|
||||
catch (MPD::ServerError &e_prim)
|
||||
{
|
||||
Statusbar::printf("MPD: %1%", e_prim.what());
|
||||
}
|
||||
// If prompt asking for a password is aborted, exit the application to
|
||||
// prevent getting stuck in the prompt indefinitely.
|
||||
catch (NC::PromptAborted &)
|
||||
{
|
||||
Actions::ExitMainLoop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user