refactor(temperature): check if file exist on init

pull/265/head
Alex 2019-04-11 15:08:23 +02:00
parent 24684ca71b
commit 5870421f84
2 changed files with 12 additions and 1 deletions

View File

@ -4,6 +4,11 @@
#include <fstream>
#include "util/sleeper_thread.hpp"
#include "ALabel.hpp"
#ifdef FILESYSTEM_EXPERIMENTAL
#include <experimental/filesystem>
#else
#include <filesystem>
#endif
namespace waybar::modules {

View File

@ -10,7 +10,13 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone);
}
#ifdef FILESYSTEM_EXPERIMENTAL
if (!std::experimental::filesystem::exists(file_path_)) {
#else
if (!std::filesystem::exists(file_path_)) {
#endif
throw std::runtime_error("Can't open " + file_path_);
}
label_.set_name("temperature");
if (!id.empty()) {
label_.get_style_context()->add_class(id);