refactor: try/catch, sigc trackable
This commit is contained in:
parent
0c3c548bc0
commit
362c393b1d
|
@ -63,8 +63,8 @@ class Item : public sigc::trackable {
|
|||
bool makeMenu(GdkEventButton* const& ev);
|
||||
bool handleClick(GdkEventButton* const& /*ev*/);
|
||||
|
||||
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
||||
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
||||
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
||||
bool update_pending_;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Mode : public ALabel {
|
||||
class Mode : public ALabel, public sigc::trackable {
|
||||
public:
|
||||
Mode(const std::string&, const Json::Value&);
|
||||
~Mode() = default;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Window : public ALabel {
|
||||
class Window : public ALabel, public sigc::trackable {
|
||||
public:
|
||||
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Window() = default;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Workspaces : public IModule {
|
||||
class Workspaces : public IModule, public sigc::trackable {
|
||||
public:
|
||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Workspaces() = default;
|
||||
|
|
|
@ -5,15 +5,16 @@
|
|||
namespace waybar::util {
|
||||
|
||||
struct JsonParser {
|
||||
JsonParser() : reader_(builder_.newCharReader()) {}
|
||||
JsonParser() {}
|
||||
|
||||
const Json::Value parse(const std::string& data) const {
|
||||
Json::Value root(Json::objectValue);
|
||||
if (data.empty()) {
|
||||
return root;
|
||||
}
|
||||
std::string err;
|
||||
bool res = reader_->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||
std::unique_ptr<Json::CharReader> const reader(builder_.newCharReader());
|
||||
std::string err;
|
||||
bool res = reader->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||
if (!res) throw std::runtime_error(err);
|
||||
return root;
|
||||
}
|
||||
|
@ -21,8 +22,7 @@ struct JsonParser {
|
|||
~JsonParser() = default;
|
||||
|
||||
private:
|
||||
Json::CharReaderBuilder builder_;
|
||||
std::unique_ptr<Json::CharReader> const reader_;
|
||||
Json::CharReaderBuilder builder_;
|
||||
};
|
||||
|
||||
} // namespace waybar::util
|
||||
|
|
|
@ -14,11 +14,6 @@ Watcher::Watcher()
|
|||
watcher_(sn_watcher_skeleton_new()) {}
|
||||
|
||||
Watcher::~Watcher() {
|
||||
if (bus_name_id_ != 0) {
|
||||
Gio::DBus::unown_name(bus_name_id_);
|
||||
bus_name_id_ = 0;
|
||||
}
|
||||
|
||||
if (hosts_ != nullptr) {
|
||||
g_slist_free_full(hosts_, gfWatchFree);
|
||||
hosts_ = nullptr;
|
||||
|
|
|
@ -19,7 +19,13 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
|||
worker();
|
||||
}
|
||||
|
||||
void Workspaces::onEvent(const struct Ipc::ipc_response &res) { ipc_.sendCmd(IPC_GET_WORKSPACES); }
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
if (res.type == IPC_GET_WORKSPACES) {
|
||||
|
@ -194,7 +200,11 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
||||
try {
|
||||
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue