From 4cc48b3cfd2a9f8e89bda3f0313811aa996dce29 Mon Sep 17 00:00:00 2001 From: Alexis Date: Sat, 24 Nov 2018 11:13:52 +0100 Subject: [PATCH] fix(client): catch error on update --- src/bar.cpp | 8 +++++++- src/modules/cpu.cpp | 16 ++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index 961a321..1bbb40d 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -184,7 +184,13 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) if (pos == "modules-right") { 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) { std::cerr << e.what() << std::endl; } diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index bd2b480..91e177d 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -12,16 +12,12 @@ waybar::modules::Cpu::Cpu(const Json::Value& config) auto waybar::modules::Cpu::update() -> void { - try { - // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both - auto cpu_load = getCpuLoad(); - auto [cpu_usage, tooltip] = getCpuUsage(); - label_.set_tooltip_text(tooltip); - label_.set_markup(fmt::format(format_, - fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage))); - } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; - } + // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both + auto cpu_load = getCpuLoad(); + auto [cpu_usage, tooltip] = getCpuUsage(); + label_.set_tooltip_text(tooltip); + label_.set_markup(fmt::format(format_, + fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage))); } uint16_t waybar::modules::Cpu::getCpuLoad()