Waybar/src/factory.cpp

58 lines
1.7 KiB
C++
Raw Normal View History

2018-08-09 10:05:48 +00:00
#include "factory.hpp"
2018-08-20 12:50:45 +00:00
waybar::Factory::Factory(Bar& bar, const Json::Value& config)
: bar_(bar), config_(config)
2018-08-09 10:05:48 +00:00
{}
2018-08-20 12:50:45 +00:00
waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
2018-08-09 10:05:48 +00:00
{
2018-08-13 12:05:13 +00:00
try {
2018-10-25 15:30:26 +00:00
auto ref = name.substr(0, name.find("#"));
if (ref == "battery") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::Battery(config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-08-20 15:20:02 +00:00
#ifdef HAVE_SWAY
2018-10-25 15:30:26 +00:00
if (ref == "sway/workspaces") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::sway::Workspaces(bar_, config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-10-25 15:30:26 +00:00
if (ref == "sway/window") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::sway::Window(bar_, config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-09-10 09:25:53 +00:00
#endif
2018-10-25 15:30:26 +00:00
if (ref == "memory") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::Memory(config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-10-25 15:30:26 +00:00
if (ref == "cpu") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::Cpu(config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-10-25 15:30:26 +00:00
if (ref == "clock") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::Clock(config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-10-25 10:24:39 +00:00
#ifdef HAVE_DBUSMENU
2018-10-25 15:30:26 +00:00
if (ref == "tray") {
return new waybar::modules::SNI::Tray(config_[name]);
}
2018-10-25 09:47:03 +00:00
#endif
2018-08-20 15:20:02 +00:00
#ifdef HAVE_LIBNL
2018-10-25 15:30:26 +00:00
if (ref == "network") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::Network(config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-08-20 15:20:02 +00:00
#endif
#ifdef HAVE_LIBPULSE
2018-10-25 15:30:26 +00:00
if (ref == "pulseaudio") {
2018-08-20 12:50:45 +00:00
return new waybar::modules::Pulseaudio(config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-08-20 15:20:02 +00:00
#endif
2018-10-25 15:30:26 +00:00
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
return new waybar::modules::Custom(ref.substr(7), config_[name]);
2018-08-16 12:29:41 +00:00
}
2018-08-13 12:05:13 +00:00
} catch (const std::exception& e) {
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());
2018-08-19 11:39:57 +00:00
throw std::runtime_error(err);
2018-08-13 12:05:13 +00:00
} catch (...) {
auto err = fmt::format("Disabling module \"{}\", Unknown reason", name);
2018-08-19 11:39:57 +00:00
throw std::runtime_error(err);
2018-08-13 12:05:13 +00:00
}
2018-08-19 11:39:57 +00:00
throw std::runtime_error("Unknown module: " + name);
2018-08-09 10:05:48 +00:00
}