fix(mpd): Broadcast connection state changes once

This commit is contained in:
Michael Carlberg 2016-06-27 22:22:33 +02:00
parent 26daf744bb
commit 78823fda6d
2 changed files with 13 additions and 3 deletions

View File

@ -63,9 +63,12 @@ namespace modules
std::chrono::system_clock::time_point synced_at;
float sync_interval = 1.0f;
bool clickable_progress = false;
std::string progress_fill, progress_empty, progress_indicator;
// This flag is used to let thru a broadcast once every time
// the connection state changes
concurrency::Atomic<bool> connection_state_broadcasted { true };
public:
explicit MpdModule(std::string name);
~MpdModule();

View File

@ -25,6 +25,7 @@ MpdModule::MpdModule(std::string name_)
TAG_ICON_RANDOM, TAG_ICON_REPEAT, TAG_ICON_REPEAT_ONE, TAG_ICON_PREV,
TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE, TAG_ICON_NEXT,
TAG_ICON_SEEKB, TAG_ICON_SEEKF });
this->formatter->add(FORMAT_OFFLINE, "", { TAG_LABEL_OFFLINE });
if (this->formatter->has(TAG_ICON_PLAY) || this->formatter->has(TAG_TOGGLE))
@ -107,9 +108,11 @@ void MpdModule::start()
bool MpdModule::has_event()
{
bool has_event = false;
bool has_event = !this->connection_state_broadcasted();
if (!this->mpd->connected()) {
this->connection_state_broadcasted = false;
try {
this->mpd->connect();
} catch (mpd::Exception &e) {
@ -117,11 +120,15 @@ bool MpdModule::has_event()
}
if (!this->mpd->connected()) {
this->sleep(3s);
this->sleep(2s);
return false;
}
}
if (!this->connection_state_broadcasted) {
this->connection_state_broadcasted = true;
}
if (!this->status) {
this->status = this->mpd->get_status();
this->status->update(-1, this->mpd);