1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

fix(github): Clear label on empty notifications

Fixes #278
This commit is contained in:
Michael Carlberg 2017-01-13 14:33:16 +01:00
parent 57e8914fa6
commit 2fea813c3d
3 changed files with 14 additions and 3 deletions

View file

@ -60,6 +60,7 @@ namespace drawtypes {
string get() const;
operator bool();
label_t clone();
void clear();
void reset_tokens();
bool has_token(const string& token);
void replace_token(const string& token, string replacement);

View file

@ -24,6 +24,10 @@ namespace drawtypes {
m_margin, m_maxlen, m_ellipsis, move(tokens));
}
void label::clear() {
m_tokenized.clear();
}
void label::reset_tokens() {
m_tokenized = m_text;
}

View file

@ -1,5 +1,7 @@
#include "modules/github.hpp"
#include <cassert>
#include "drawtypes/label.hpp"
#include "modules/github.hpp"
#include "modules/meta/base.inl"
@ -23,6 +25,8 @@ namespace modules {
m_label = load_optional_label(m_conf, name(), TAG_LABEL, "Notifications: %notifications%");
m_label->replace_token("%notifications%", m_empty_notifications ? "0" : "");
}
assert(static_cast<bool>(m_label));
}
/**
@ -50,9 +54,11 @@ namespace modules {
notifications++;
}
if (m_label) {
if (notifications || m_empty_notifications) {
m_label->reset_tokens();
m_label->replace_token("%notifications%", notifications || m_empty_notifications ? to_string(notifications) : "");
m_label->replace_token("%notifications%", to_string(notifications));
} else {
m_label->clear();
}
return true;