Waybar/src/factory.cpp

46 lines
1.4 KiB
C++
Raw Normal View History

2018-08-09 10:05:48 +00:00
#include "factory.hpp"
waybar::Factory::Factory(Bar &bar, Json::Value config)
2018-08-16 12:29:41 +00:00
: _bar(bar), _config(std::move(config))
2018-08-09 10:05:48 +00:00
{}
2018-08-19 11:39:57 +00:00
waybar::IModule* waybar::Factory::makeModule(const std::string &name)
2018-08-09 10:05:48 +00:00
{
2018-08-13 12:05:13 +00:00
try {
2018-08-16 12:29:41 +00:00
if (name == "battery") {
2018-08-13 12:05:13 +00:00
return new waybar::modules::Battery(_config[name]);
2018-08-16 12:29:41 +00:00
}
if (name == "sway/workspaces") {
2018-08-15 18:17:17 +00:00
return new waybar::modules::sway::Workspaces(_bar, _config[name]);
2018-08-16 12:29:41 +00:00
}
if (name == "sway/window") {
2018-08-15 18:17:17 +00:00
return new waybar::modules::sway::Window(_bar, _config[name]);
2018-08-16 12:29:41 +00:00
}
if (name == "memory") {
2018-08-13 12:05:13 +00:00
return new waybar::modules::Memory(_config[name]);
2018-08-16 12:29:41 +00:00
}
if (name == "cpu") {
2018-08-13 12:05:13 +00:00
return new waybar::modules::Cpu(_config[name]);
2018-08-16 12:29:41 +00:00
}
if (name == "clock") {
2018-08-13 12:05:13 +00:00
return new waybar::modules::Clock(_config[name]);
2018-08-16 12:29:41 +00:00
}
if (name == "network") {
2018-08-13 12:05:13 +00:00
return new waybar::modules::Network(_config[name]);
2018-08-16 12:29:41 +00:00
}
if (name == "pulseaudio") {
2018-08-13 12:05:13 +00:00
return new waybar::modules::Pulseaudio(_config[name]);
2018-08-16 12:29:41 +00:00
}
if (name.compare(0, 7, "custom/") == 0 && name.size() > 7) {
2018-08-13 12:05:13 +00:00
return new waybar::modules::Custom(name.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
}