mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(mpd): Allow for specifying the reconnect interval
This commit is contained in:
parent
8c9dd94670
commit
557b786ce0
@ -27,7 +27,8 @@ class MPD : public ALabel {
|
|||||||
|
|
||||||
// Not using unique_ptr since we don't manage the pointer
|
// Not using unique_ptr since we don't manage the pointer
|
||||||
// (It's either nullptr, or from the config)
|
// (It's either nullptr, or from the config)
|
||||||
const char* server;
|
const char* server_;
|
||||||
|
unsigned port_;
|
||||||
|
|
||||||
unique_connection connection_;
|
unique_connection connection_;
|
||||||
unique_status status_;
|
unique_status status_;
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
waybar::modules::MPD::MPD(const std::string& id, const Json::Value &config)
|
waybar::modules::MPD::MPD(const std::string& id, const Json::Value &config)
|
||||||
: ALabel(config, "{album} - {artist} - {title}", 2),
|
: ALabel(config, "{album} - {artist} - {title}", 5),
|
||||||
server(nullptr),
|
server_(nullptr),
|
||||||
|
port_(config["port"].asUInt()),
|
||||||
connection_(nullptr, &mpd_connection_free),
|
connection_(nullptr, &mpd_connection_free),
|
||||||
status_(nullptr, &mpd_status_free),
|
status_(nullptr, &mpd_status_free),
|
||||||
song_(nullptr, &mpd_song_free) {
|
song_(nullptr, &mpd_song_free) {
|
||||||
@ -14,7 +15,7 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value &config)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!config["server"].isNull()) {
|
if (!config["server"].isNull()) {
|
||||||
server = config["server"].asCString();
|
server_ = config["server"].asCString();
|
||||||
}
|
}
|
||||||
|
|
||||||
worker_ = worker();
|
worker_ = worker();
|
||||||
@ -40,7 +41,7 @@ std::thread waybar::modules::MPD::worker() {
|
|||||||
if (connection_ == nullptr) {
|
if (connection_ == nullptr) {
|
||||||
// Retry periodically if no connection
|
// Retry periodically if no connection
|
||||||
update();
|
update();
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(interval_);
|
||||||
} else {
|
} else {
|
||||||
// Else, update on any event
|
// Else, update on any event
|
||||||
waitForEvent();
|
waitForEvent();
|
||||||
@ -117,7 +118,7 @@ void waybar::modules::MPD::tryConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
connection_ = unique_connection(
|
connection_ = unique_connection(
|
||||||
mpd_connection_new(server, config_["port"].asUInt(), 5'000),
|
mpd_connection_new(server_, port_, 5'000),
|
||||||
&mpd_connection_free);
|
&mpd_connection_free);
|
||||||
|
|
||||||
if (connection_ == nullptr) {
|
if (connection_ == nullptr) {
|
||||||
|
Loading…
Reference in New Issue
Block a user