mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #332 from Organic-Code/enhancement/spdlog
Adding spdlog
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
#include "modules/battery.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
waybar::modules::Battery::Battery(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{capacity}%", 60) {
|
||||
@ -103,7 +104,7 @@ const std::tuple<uint8_t, uint32_t, std::string> waybar::modules::Battery::getIn
|
||||
uint16_t capacity = total / batteries_.size();
|
||||
return {capacity, total_current, status};
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
spdlog::error("Battery: {}", e.what());
|
||||
return {0, 0, "Unknown"};
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "modules/cpu.hpp"
|
||||
#include <numeric>
|
||||
|
||||
waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{usage}%", 10) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "modules/custom.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
waybar::modules::Custom::Custom(const std::string& name, const Json::Value& config)
|
||||
: ALabel(config, "{}"), name_(name), fp_(nullptr), pid_(-1) {
|
||||
@ -58,7 +59,7 @@ void waybar::modules::Custom::continuousWorker() {
|
||||
if (exit_code != 0) {
|
||||
output_ = {exit_code, ""};
|
||||
dp.emit();
|
||||
std::cerr << name_ + " just stopped unexpectedly, is it endless?" << std::endl;
|
||||
spdlog::error("{} stopped unexpectedly, is it endless?", name_);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "modules/mpd.hpp"
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <iostream>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{album} - {artist} - {title}", 5),
|
||||
@ -14,11 +14,11 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
|
||||
status_(nullptr, &mpd_status_free),
|
||||
song_(nullptr, &mpd_song_free) {
|
||||
if (!config_["port"].isNull() && !config_["port"].isUInt()) {
|
||||
std::cerr << module_name_ << ": `port` configuration should be an unsigned int" << std::endl;
|
||||
spdlog::warn("{}: `port` configuration should be an unsigned int", module_name_);
|
||||
}
|
||||
|
||||
if (!config_["timeout"].isNull() && !config_["timeout"].isUInt()) {
|
||||
std::cerr << module_name_ << ": `timeout` configuration should be an unsigned int" << std::endl;
|
||||
spdlog::warn("{}: `timeout` configuration should be an unsigned int", module_name_);
|
||||
}
|
||||
|
||||
label_.set_name("mpd");
|
||||
@ -28,7 +28,7 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
|
||||
|
||||
if (!config["server"].isNull()) {
|
||||
if (!config_["server"].isString()) {
|
||||
std::cerr << module_name_ << "`server` configuration should be a string" << std::endl;
|
||||
spdlog::warn("{}:`server` configuration should be a string", module_name_);
|
||||
}
|
||||
server_ = config["server"].asCString();
|
||||
}
|
||||
@ -51,7 +51,7 @@ auto waybar::modules::MPD::update() -> void {
|
||||
periodic_updater().detach();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << module_name_ + ": " + e.what() << std::endl;
|
||||
spdlog::error("{}: {}", module_name_, e.what());
|
||||
state_ = MPD_STATE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ std::thread waybar::modules::MPD::event_listener() {
|
||||
dp.emit();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << module_name_ + ": " + e.what() << std::endl;
|
||||
spdlog::warn("{}: {}", module_name_, e.what());
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -206,12 +206,12 @@ std::string waybar::modules::MPD::getStateIcon() {
|
||||
}
|
||||
|
||||
if (connection_ == nullptr) {
|
||||
std::cerr << module_name_ << ": Trying to fetch state icon while disconnected" << std::endl;
|
||||
spdlog::warn("{}: Trying to fetch state icon while disconnected", module_name_);
|
||||
return "";
|
||||
}
|
||||
|
||||
if (stopped()) {
|
||||
std::cerr << module_name_ << ": Trying to fetch state icon while stopped" << std::endl;
|
||||
spdlog::warn("{}: Trying to fetch state icon while stopped", module_name_);
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ std::string waybar::modules::MPD::getOptionIcon(std::string optionName, bool act
|
||||
}
|
||||
|
||||
if (connection_ == nullptr) {
|
||||
std::cerr << module_name_ << ": Trying to fetch option icon while disconnected" << std::endl;
|
||||
spdlog::warn("{}: Trying to fetch option icon while disconnected", module_name_);
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ void waybar::modules::MPD::tryConnect() {
|
||||
unique_connection(mpd_connection_new(server_, port_, timeout_), &mpd_connection_free);
|
||||
|
||||
if (connection_ == nullptr || alternate_connection_ == nullptr) {
|
||||
std::cerr << module_name_ << ": Failed to connect to MPD" << std::endl;
|
||||
spdlog::error("{}: Failed to connect to MPD", module_name_);
|
||||
connection_.reset();
|
||||
alternate_connection_.reset();
|
||||
return;
|
||||
@ -259,9 +259,9 @@ void waybar::modules::MPD::tryConnect() {
|
||||
|
||||
try {
|
||||
checkErrors(connection_.get());
|
||||
std::cerr << module_name_ << ": Connected to MPD" << std::endl;
|
||||
spdlog::info("{}: Connected to MPD", module_name_);
|
||||
} catch (std::runtime_error& e) {
|
||||
std::cerr << module_name_ << ": Failed to connect to MPD: " << e.what() << std::endl;
|
||||
spdlog::error("{}: Failed to connect to MPD: {}", module_name_, e.what());
|
||||
connection_.reset();
|
||||
alternate_connection_.reset();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "modules/network.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
@ -13,7 +13,7 @@ namespace {
|
||||
std::ifstream netstat(NETSTAT_FILE);
|
||||
std::optional<unsigned long long> read_netstat(std::string_view category, std::string_view key) {
|
||||
if (!netstat) {
|
||||
std::cerr << "Failed to open netstat file " << NETSTAT_FILE << '\n' << std::flush;
|
||||
spdlog::warn("Failed to open netstat file {}", NETSTAT_FILE);
|
||||
return {};
|
||||
}
|
||||
netstat.seekg(std::ios_base::beg);
|
||||
@ -28,7 +28,7 @@ namespace {
|
||||
std::string read;
|
||||
while (std::getline(netstat, read) && !starts_with(read, category));
|
||||
if (!starts_with(read, category)) {
|
||||
std::cerr << "Category '" << category << "' not found in netstat file " << NETSTAT_FILE << '\n' << std::flush;
|
||||
spdlog::warn("Category '{}' not found in netstat file {}", category, NETSTAT_FILE);
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ namespace {
|
||||
}
|
||||
|
||||
if (r_it == read.end() && k_it != key.end()) {
|
||||
std::cerr << "Key '" << key << "' not found in category '" << category << "' of netstat file " << NETSTAT_FILE << '\n' << std::flush;
|
||||
spdlog::warn("Key '{}' not found in category '{}' of netstat file {}", key, category, NETSTAT_FILE);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "modules/sni/host.hpp"
|
||||
#include <iostream>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
@ -63,14 +64,14 @@ void Host::proxyReady(GObject* src, GAsyncResult* res, gpointer data) {
|
||||
GError* error = nullptr;
|
||||
SnWatcher* watcher = sn_watcher_proxy_new_finish(res, &error);
|
||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
std::cerr << error->message << std::endl;
|
||||
spdlog::error("Host: {}", error->message);
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
auto host = static_cast<SNI::Host*>(data);
|
||||
host->watcher_ = watcher;
|
||||
if (error != nullptr) {
|
||||
std::cerr << error->message << std::endl;
|
||||
spdlog::error("Host: {}", error->message);
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
@ -82,13 +83,13 @@ void Host::registerHost(GObject* src, GAsyncResult* res, gpointer data) {
|
||||
GError* error = nullptr;
|
||||
sn_watcher_call_register_host_finish(SN_WATCHER(src), res, &error);
|
||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
std::cerr << error->message << std::endl;
|
||||
spdlog::error("Host: {}", error->message);
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
auto host = static_cast<SNI::Host*>(data);
|
||||
if (error != nullptr) {
|
||||
std::cerr << error->message << std::endl;
|
||||
spdlog::error("Host: {}", error->message);
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
@ -139,4 +140,4 @@ void Host::addRegisteredItem(std::string service) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace waybar::modules::SNI
|
||||
} // namespace waybar::modules::SNI
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "modules/sni/item.hpp"
|
||||
#include <glibmm/main.h>
|
||||
#include <iostream>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
@ -47,8 +47,7 @@ void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) {
|
||||
this->proxy_->signal_signal().connect(sigc::mem_fun(*this, &Item::onSignal));
|
||||
|
||||
if (this->id.empty() || this->category.empty() || this->status.empty()) {
|
||||
std::cerr << "Invalid Status Notifier Item: " + this->bus_name + "," + this->object_path
|
||||
<< std::endl;
|
||||
spdlog::error("Invalid Status Notifier Item: {}, {}", bus_name, object_path);
|
||||
return;
|
||||
}
|
||||
this->updateImage();
|
||||
@ -235,7 +234,7 @@ void Item::updateImage() {
|
||||
image.set(getIconByName(icon_name, icon_size));
|
||||
}
|
||||
} catch (Glib::Error& e) {
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
spdlog::error("Item '{}': {}", id, static_cast<std::string>(e.what()));
|
||||
}
|
||||
} else if (icon_pixmap) {
|
||||
// An icon extracted may be the wrong size for the tray
|
||||
@ -321,4 +320,4 @@ bool Item::handleClick(GdkEventButton* const& ev) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace waybar::modules::SNI
|
||||
} // namespace waybar::modules::SNI
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "modules/sni/tray.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
@ -40,4 +39,4 @@ auto Tray::update() -> void {
|
||||
|
||||
Tray::operator Gtk::Widget&() { return box_; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "modules/sni/watcher.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
using namespace waybar::modules::SNI;
|
||||
|
||||
@ -35,7 +34,7 @@ void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib:
|
||||
if (error != nullptr) {
|
||||
// Don't print an error when a watcher is already present
|
||||
if (error->code != 2) {
|
||||
std::cerr << error->message << std::endl;
|
||||
spdlog::error("Watcher {}: {}", watcher_id_, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
@ -194,4 +193,4 @@ void Watcher::updateRegisteredItems(SnWatcher* obj) {
|
||||
sn_watcher_set_registered_items(obj, items);
|
||||
g_variant_unref(variant);
|
||||
g_free(items);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "modules/sway/mode.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
@ -24,7 +25,7 @@ void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
||||
}
|
||||
dp.emit();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Mode: " << e.what() << std::endl;
|
||||
spdlog::error("Mode: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +34,7 @@ void Mode::worker() {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Mode: " << e.what() << std::endl;
|
||||
spdlog::error("Mode: {}", e.what());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -50,4 +51,4 @@ auto Mode::update() -> void {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace waybar::modules::sway
|
||||
} // namespace waybar::modules::sway
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "modules/sway/window.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
@ -55,7 +56,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||
dp.emit();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Window: " << e.what() << std::endl;
|
||||
spdlog::error("Window: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +65,7 @@ void Window::worker() {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Window: " << e.what() << std::endl;
|
||||
spdlog::error("Window: {}", e.what());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -102,7 +103,7 @@ void Window::getTree() {
|
||||
try {
|
||||
ipc_.sendCmd(IPC_GET_TREE);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
spdlog::error("Window: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "modules/sway/workspaces.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
@ -28,7 +29,7 @@ void Workspaces::onEvent(const struct Ipc::ipc_response &res) {
|
||||
try {
|
||||
ipc_.sendCmd(IPC_GET_WORKSPACES);
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +51,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
dp.emit();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
} else {
|
||||
if (scrolling_) {
|
||||
@ -64,7 +65,7 @@ void Workspaces::worker() {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -139,7 +140,7 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) {
|
||||
try {
|
||||
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", pair.first->first));
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
});
|
||||
if (!config_["disable-scroll"].asBool()) {
|
||||
@ -208,7 +209,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||
try {
|
||||
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user