2018-08-09 10:05:48 +00:00
|
|
|
#include "factory.hpp"
|
|
|
|
|
2019-04-18 15:52:00 +00:00
|
|
|
waybar::Factory::Factory(const Bar& bar, const Json::Value& config) : bar_(bar), config_(config) {}
|
2018-08-09 10:05:48 +00:00
|
|
|
|
2019-06-15 12:57:52 +00:00
|
|
|
waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
|
2018-08-13 12:05:13 +00:00
|
|
|
try {
|
2019-04-24 10:37:24 +00:00
|
|
|
auto hash_pos = name.find('#');
|
2018-12-18 16:30:54 +00:00
|
|
|
auto ref = name.substr(0, hash_pos);
|
|
|
|
auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : "";
|
2019-05-12 17:53:14 +00:00
|
|
|
#ifndef NO_FILESYSTEM
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "battery") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::Battery(id, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2019-05-12 17:53:14 +00:00
|
|
|
#endif
|
2019-04-18 15:52:00 +00:00
|
|
|
#ifdef HAVE_SWAY
|
2018-10-30 12:39:30 +00:00
|
|
|
if (ref == "sway/mode") {
|
2019-05-07 11:21:18 +00:00
|
|
|
return new waybar::modules::sway::Mode(id, config_[name]);
|
2018-10-30 12:39:30 +00:00
|
|
|
}
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "sway/workspaces") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::sway::Workspaces(id, bar_, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "sway/window") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::sway::Window(id, bar_, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2019-04-18 15:52:00 +00:00
|
|
|
#endif
|
2019-02-17 14:27:54 +00:00
|
|
|
if (ref == "idle_inhibitor") {
|
|
|
|
return new waybar::modules::IdleInhibitor(id, bar_, config_[name]);
|
|
|
|
}
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "memory") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::Memory(id, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "cpu") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::Cpu(id, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "clock") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::Clock(id, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2019-09-23 20:25:54 +00:00
|
|
|
if (ref == "disk") {
|
|
|
|
return new waybar::modules::Disk(id, config_[name]);
|
|
|
|
}
|
2019-05-12 17:53:14 +00:00
|
|
|
#if defined(HAVE_DBUSMENU) && !defined(NO_FILESYSTEM)
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "tray") {
|
2019-03-22 11:25:05 +00:00
|
|
|
return new waybar::modules::SNI::Tray(id, bar_, config_[name]);
|
2018-08-29 18:36:39 +00:00
|
|
|
}
|
2019-04-18 15:52:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBNL
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "network") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::Network(id, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2019-04-18 15:52:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBUDEV
|
2019-02-19 04:11:18 +00:00
|
|
|
if (ref == "backlight") {
|
|
|
|
return new waybar::modules::Backlight(id, config_[name]);
|
|
|
|
}
|
2019-04-18 15:52:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBPULSE
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref == "pulseaudio") {
|
2018-12-18 16:30:54 +00:00
|
|
|
return new waybar::modules::Pulseaudio(id, config_[name]);
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2019-04-18 15:52:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBMPDCLIENT
|
2019-04-16 14:34:37 +00:00
|
|
|
if (ref == "mpd") {
|
|
|
|
return new waybar::modules::MPD(id, config_[name]);
|
|
|
|
}
|
2019-04-18 15:52:00 +00:00
|
|
|
#endif
|
2019-03-13 12:18:08 +00:00
|
|
|
if (ref == "temperature") {
|
|
|
|
return new waybar::modules::Temperature(id, config_[name]);
|
|
|
|
}
|
2018-10-25 15:30:26 +00:00
|
|
|
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
|
2019-05-22 10:20:13 +00:00
|
|
|
return new waybar::modules::Custom(ref.substr(7), id, 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
|
|
|
}
|