| 255 | } |
| 256 | |
| 257 | void waybar::modules::Custom::parseOutputJson() { |
| 258 | std::istringstream output(output_.out); |
| 259 | std::string line; |
| 260 | class_.clear(); |
| 261 | while (getline(output, line)) { |
| 262 | auto parsed = parser_.parse(line); |
| 263 | if (config_["escape"].isBool() && config_["escape"].asBool()) { |
| 264 | text_ = Glib::Markup::escape_text(parsed["text"].asString()); |
| 265 | } else { |
| 266 | text_ = parsed["text"].asString(); |
| 267 | } |
| 268 | if (config_["escape"].isBool() && config_["escape"].asBool()) { |
| 269 | alt_ = Glib::Markup::escape_text(parsed["alt"].asString()); |
| 270 | } else { |
| 271 | alt_ = parsed["alt"].asString(); |
| 272 | } |
| 273 | if (config_["escape"].isBool() && config_["escape"].asBool()) { |
| 274 | tooltip_ = Glib::Markup::escape_text(parsed["tooltip"].asString()); |
| 275 | } else { |
| 276 | tooltip_ = parsed["tooltip"].asString(); |
| 277 | } |
| 278 | if (parsed["class"].isString()) { |
| 279 | class_.push_back(parsed["class"].asString()); |
| 280 | } else if (parsed["class"].isArray()) { |
| 281 | for (auto const& c : parsed["class"]) { |
| 282 | class_.push_back(c.asString()); |
| 283 | } |
| 284 | } |
| 285 | if (!parsed["percentage"].asString().empty() && parsed["percentage"].isNumeric()) { |
| 286 | percentage_ = (int)lround(parsed["percentage"].asFloat()); |
| 287 | } else { |
| 288 | percentage_ = 0; |
| 289 | } |
| 290 | break; |
| 291 | } |
| 292 | } |