fix(bar): handle ipc connection errors.
Try to use the default bar id (`bar-0`) if none is set.
This commit is contained in:
parent
6bfb674d1b
commit
2290fe10aa
10
src/bar.cpp
10
src/bar.cpp
|
@ -61,6 +61,7 @@ const Bar::bar_mode_map Bar::PRESET_MODES = { //
|
||||||
|
|
||||||
const std::string_view Bar::MODE_DEFAULT = "default";
|
const std::string_view Bar::MODE_DEFAULT = "default";
|
||||||
const std::string_view Bar::MODE_INVISIBLE = "invisible";
|
const std::string_view Bar::MODE_INVISIBLE = "invisible";
|
||||||
|
const std::string_view DEFAULT_BAR_ID = "bar-0";
|
||||||
|
|
||||||
#ifdef HAVE_GTK_LAYER_SHELL
|
#ifdef HAVE_GTK_LAYER_SHELL
|
||||||
struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
|
struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
|
@ -556,7 +557,14 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||||
if (auto id = config["id"]; id.isString()) {
|
if (auto id = config["id"]; id.isString()) {
|
||||||
bar_id = id.asString();
|
bar_id = id.asString();
|
||||||
}
|
}
|
||||||
_ipc_client = std::make_unique<BarIpcClient>(*this);
|
if (bar_id.empty()) {
|
||||||
|
bar_id = DEFAULT_BAR_ID;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
_ipc_client = std::make_unique<BarIpcClient>(*this);
|
||||||
|
} catch (const std::exception& exc) {
|
||||||
|
spdlog::warn("Failed to open bar ipc connection: {}", exc.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <fmt/ostream.h>
|
#include <fmt/ostream.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "bar.hpp"
|
#include "bar.hpp"
|
||||||
#include "modules/sway/ipc/ipc.hpp"
|
#include "modules/sway/ipc/ipc.hpp"
|
||||||
|
|
||||||
|
@ -47,13 +49,13 @@ struct swaybar_config parseConfig(const Json::Value& payload) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BarIpcClient::onInitialConfig(const struct Ipc::ipc_response& res) {
|
void BarIpcClient::onInitialConfig(const struct Ipc::ipc_response& res) {
|
||||||
try {
|
auto payload = parser_.parse(res.payload);
|
||||||
auto payload = parser_.parse(res.payload);
|
if (auto success = payload.get("success", true); !success.asBool()) {
|
||||||
auto config = parseConfig(payload);
|
auto err = payload.get("error", "Unknown error");
|
||||||
onConfigUpdate(config);
|
throw std::runtime_error(err.asString());
|
||||||
} catch (const std::exception& e) {
|
|
||||||
spdlog::error("BarIpcClient::onInitialConfig {}", e.what());
|
|
||||||
}
|
}
|
||||||
|
auto config = parseConfig(payload);
|
||||||
|
onConfigUpdate(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BarIpcClient::onIpcEvent(const struct Ipc::ipc_response& res) {
|
void BarIpcClient::onIpcEvent(const struct Ipc::ipc_response& res) {
|
||||||
|
|
Loading…
Reference in New Issue