fix(client): catch error on update

pull/105/head
Alexis 2018-11-24 11:13:52 +01:00
parent 087de4e956
commit 4cc48b3cfd
2 changed files with 13 additions and 11 deletions

View File

@ -184,7 +184,13 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos)
if (pos == "modules-right") { if (pos == "modules-right") {
modules_right_.emplace_back(module); modules_right_.emplace_back(module);
} }
module->dp.connect([module] { module->update(); }); module->dp.connect([module] {
try {
module->update();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
});
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
} }

View File

@ -12,16 +12,12 @@ waybar::modules::Cpu::Cpu(const Json::Value& config)
auto waybar::modules::Cpu::update() -> void auto waybar::modules::Cpu::update() -> void
{ {
try { // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both auto cpu_load = getCpuLoad();
auto cpu_load = getCpuLoad(); auto [cpu_usage, tooltip] = getCpuUsage();
auto [cpu_usage, tooltip] = getCpuUsage(); label_.set_tooltip_text(tooltip);
label_.set_tooltip_text(tooltip); label_.set_markup(fmt::format(format_,
label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
} }
uint16_t waybar::modules::Cpu::getCpuLoad() uint16_t waybar::modules::Cpu::getCpuLoad()