Merge pull request #339 from alebastr/master
Tray error handling and logging improvementspull/331/head
commit
032ad925af
|
@ -243,10 +243,14 @@ int waybar::Client::main(int argc, char *argv[]) {
|
||||||
std::string config;
|
std::string config;
|
||||||
std::string style;
|
std::string style;
|
||||||
std::string bar_id;
|
std::string bar_id;
|
||||||
|
std::string log_level;
|
||||||
auto cli = clara::detail::Help(show_help) |
|
auto cli = clara::detail::Help(show_help) |
|
||||||
clara::detail::Opt(show_version)["-v"]["--version"]("Show version") |
|
clara::detail::Opt(show_version)["-v"]["--version"]("Show version") |
|
||||||
clara::detail::Opt(config, "config")["-c"]["--config"]("Config path") |
|
clara::detail::Opt(config, "config")["-c"]["--config"]("Config path") |
|
||||||
clara::detail::Opt(style, "style")["-s"]["--style"]("Style path") |
|
clara::detail::Opt(style, "style")["-s"]["--style"]("Style path") |
|
||||||
|
clara::detail::Opt(
|
||||||
|
log_level,
|
||||||
|
"trace|debug|info|warning|error|critical|off")["-l"]["--log-level"]("Log level") |
|
||||||
clara::detail::Opt(bar_id, "id")["-b"]["--bar"]("Bar id");
|
clara::detail::Opt(bar_id, "id")["-b"]["--bar"]("Bar id");
|
||||||
auto res = cli.parse(clara::detail::Args(argc, argv));
|
auto res = cli.parse(clara::detail::Args(argc, argv));
|
||||||
if (!res) {
|
if (!res) {
|
||||||
|
@ -261,6 +265,9 @@ int waybar::Client::main(int argc, char *argv[]) {
|
||||||
std::cout << "Waybar v" << VERSION << std::endl;
|
std::cout << "Waybar v" << VERSION << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!log_level.empty()) {
|
||||||
|
spdlog::set_level(spdlog::level::from_str(log_level));
|
||||||
|
}
|
||||||
setupConfigs(config, style);
|
setupConfigs(config, style);
|
||||||
setupConfig();
|
setupConfig();
|
||||||
setupCss();
|
setupCss();
|
||||||
|
|
|
@ -1,6 +1,32 @@
|
||||||
#include "modules/sni/item.hpp"
|
|
||||||
#include <glibmm/main.h>
|
#include <glibmm/main.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#include "modules/sni/item.hpp"
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<Glib::ustring> : formatter<std::string> {
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const Glib::ustring& value, FormatContext& ctx) {
|
||||||
|
return formatter<std::string>::format(value, ctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<Glib::VariantBase> : formatter<std::string> {
|
||||||
|
bool is_printable(const Glib::VariantBase& value) {
|
||||||
|
auto type = value.get_type_string();
|
||||||
|
/* Print only primitive (single character excluding 'v') and short complex types */
|
||||||
|
return (type.length() == 1 && islower(type[0]) && type[0] != 'v') || value.get_size() <= 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const Glib::VariantBase& value, FormatContext& ctx) {
|
||||||
|
if (is_printable(value)) {
|
||||||
|
return formatter<std::string>::format(value.print(), ctx);
|
||||||
|
} else {
|
||||||
|
return formatter<std::string>::format(value.get_type_string(), ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
|
@ -54,15 +80,9 @@ void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) {
|
||||||
// this->event_box.set_tooltip_text(this->title);
|
// this->event_box.set_tooltip_text(this->title);
|
||||||
|
|
||||||
} catch (const Glib::Error& err) {
|
} catch (const Glib::Error& err) {
|
||||||
g_error("Failed to create DBus Proxy for %s %s: %s",
|
spdlog::error("Failed to create DBus Proxy for {} {}: {}", bus_name, object_path, err.what());
|
||||||
bus_name.c_str(),
|
|
||||||
object_path.c_str(),
|
|
||||||
err.what().c_str());
|
|
||||||
} catch (const std::exception& err) {
|
} catch (const std::exception& err) {
|
||||||
g_error("Failed to create DBus Proxy for %s %s: %s",
|
spdlog::error("Failed to create DBus Proxy for {} {}: {}", bus_name, object_path, err.what());
|
||||||
bus_name.c_str(),
|
|
||||||
object_path.c_str(),
|
|
||||||
err.what());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,41 +92,57 @@ T get_variant(Glib::VariantBase& value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
|
void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
|
||||||
if (name == "Category") {
|
try {
|
||||||
category = get_variant<std::string>(value);
|
spdlog::trace("Set tray item property: {}.{} = {}", id.empty() ? bus_name : id, name, value);
|
||||||
} else if (name == "Id") {
|
|
||||||
id = get_variant<std::string>(value);
|
if (name == "Category") {
|
||||||
} else if (name == "Title") {
|
category = get_variant<std::string>(value);
|
||||||
title = get_variant<std::string>(value);
|
} else if (name == "Id") {
|
||||||
} else if (name == "Status") {
|
id = get_variant<std::string>(value);
|
||||||
status = get_variant<std::string>(value);
|
} else if (name == "Title") {
|
||||||
} else if (name == "WindowId") {
|
title = get_variant<std::string>(value);
|
||||||
window_id = get_variant<int32_t>(value);
|
} else if (name == "Status") {
|
||||||
} else if (name == "IconName") {
|
status = get_variant<std::string>(value);
|
||||||
icon_name = get_variant<std::string>(value);
|
} else if (name == "WindowId") {
|
||||||
} else if (name == "IconPixmap") {
|
window_id = get_variant<int32_t>(value);
|
||||||
icon_pixmap = this->extractPixBuf(value.gobj());
|
} else if (name == "IconName") {
|
||||||
} else if (name == "OverlayIconName") {
|
icon_name = get_variant<std::string>(value);
|
||||||
overlay_icon_name = get_variant<std::string>(value);
|
} else if (name == "IconPixmap") {
|
||||||
} else if (name == "OverlayIconPixmap") {
|
icon_pixmap = this->extractPixBuf(value.gobj());
|
||||||
// TODO: overlay_icon_pixmap
|
} else if (name == "OverlayIconName") {
|
||||||
} else if (name == "AttentionIconName") {
|
overlay_icon_name = get_variant<std::string>(value);
|
||||||
attention_icon_name = get_variant<std::string>(value);
|
} else if (name == "OverlayIconPixmap") {
|
||||||
} else if (name == "AttentionIconPixmap") {
|
// TODO: overlay_icon_pixmap
|
||||||
// TODO: attention_icon_pixmap
|
} else if (name == "AttentionIconName") {
|
||||||
} else if (name == "AttentionMovieName") {
|
attention_icon_name = get_variant<std::string>(value);
|
||||||
attention_movie_name = get_variant<std::string>(value);
|
} else if (name == "AttentionIconPixmap") {
|
||||||
} else if (name == "ToolTip") {
|
// TODO: attention_icon_pixmap
|
||||||
// TODO: tooltip
|
} else if (name == "AttentionMovieName") {
|
||||||
} else if (name == "IconThemePath") {
|
attention_movie_name = get_variant<std::string>(value);
|
||||||
icon_theme_path = get_variant<std::string>(value);
|
} else if (name == "ToolTip") {
|
||||||
if (!icon_theme_path.empty()) {
|
// TODO: tooltip
|
||||||
icon_theme->set_search_path({icon_theme_path});
|
} else if (name == "IconThemePath") {
|
||||||
|
icon_theme_path = get_variant<std::string>(value);
|
||||||
|
if (!icon_theme_path.empty()) {
|
||||||
|
icon_theme->set_search_path({icon_theme_path});
|
||||||
|
}
|
||||||
|
} else if (name == "Menu") {
|
||||||
|
menu = get_variant<std::string>(value);
|
||||||
|
} else if (name == "ItemIsMenu") {
|
||||||
|
item_is_menu = get_variant<bool>(value);
|
||||||
}
|
}
|
||||||
} else if (name == "Menu") {
|
} catch (const Glib::Error& err) {
|
||||||
menu = get_variant<std::string>(value);
|
spdlog::warn("Failed to set tray item property: {}.{}, value = {}, err = {}",
|
||||||
} else if (name == "ItemIsMenu") {
|
id.empty() ? bus_name : id,
|
||||||
item_is_menu = get_variant<bool>(value);
|
name,
|
||||||
|
value,
|
||||||
|
err.what());
|
||||||
|
} catch (const std::exception& err) {
|
||||||
|
spdlog::warn("Failed to set tray item property: {}.{}, value = {}, err = {}",
|
||||||
|
id.empty() ? bus_name : id,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
err.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +167,7 @@ void Item::processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& _result) {
|
||||||
for (const auto& [name, value] : properties) {
|
for (const auto& [name, value] : properties) {
|
||||||
Glib::VariantBase old_value;
|
Glib::VariantBase old_value;
|
||||||
proxy_->get_cached_property(old_value, name);
|
proxy_->get_cached_property(old_value, name);
|
||||||
if (!value.equal(old_value)) {
|
if (!old_value || !value.equal(old_value)) {
|
||||||
proxy_->set_cached_property(name, value);
|
proxy_->set_cached_property(name, value);
|
||||||
setProperty(name, const_cast<Glib::VariantBase&>(value));
|
setProperty(name, const_cast<Glib::VariantBase&>(value));
|
||||||
}
|
}
|
||||||
|
@ -140,14 +176,15 @@ void Item::processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& _result) {
|
||||||
this->updateImage();
|
this->updateImage();
|
||||||
// this->event_box.set_tooltip_text(this->title);
|
// this->event_box.set_tooltip_text(this->title);
|
||||||
} catch (const Glib::Error& err) {
|
} catch (const Glib::Error& err) {
|
||||||
g_warning("Failed to update properties: %s", err.what().c_str());
|
spdlog::warn("Failed to update properties: {}", err.what());
|
||||||
} catch (const std::exception& err) {
|
} catch (const std::exception& err) {
|
||||||
g_warning("Failed to update properties: %s", err.what());
|
spdlog::warn("Failed to update properties: {}", err.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name,
|
void Item::onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name,
|
||||||
const Glib::VariantContainerBase& arguments) {
|
const Glib::VariantContainerBase& arguments) {
|
||||||
|
spdlog::trace("Tray item '{}' got signal {}", id, signal_name);
|
||||||
if (!update_pending_ && signal_name.compare(0, 3, "New") == 0) {
|
if (!update_pending_ && signal_name.compare(0, 3, "New") == 0) {
|
||||||
/* Debounce signals and schedule update of all properties.
|
/* Debounce signals and schedule update of all properties.
|
||||||
* Based on behavior of Plasma dataengine for StatusNotifierItem.
|
* Based on behavior of Plasma dataengine for StatusNotifierItem.
|
||||||
|
|
Loading…
Reference in New Issue