#pragma once #include "ui/apps/app.h" #include #include #include "esp_log.h" #include class AppRegistry { public: static AppRegistry& instance() { static AppRegistry registry; return registry; } /** * @brief Initialize the app registry with built-in apps * */ esp_err_t init(void); void register_app(std::unique_ptr app_descriptor) { if (app_descriptors_.find(app_descriptor->get_name()) != app_descriptors_.end()) { // App already registered ESP_LOGW("AppRegistry", "App '%s' is already registered", app_descriptor->get_name().c_str()); return; } app_descriptors_.emplace(app_descriptor->get_name(), std::move(app_descriptor)); } size_t size() const { return app_descriptors_.size(); } // iterators to access registered apps auto begin() { return app_descriptors_.begin(); } auto begin() const { return app_descriptors_.begin(); } auto end() { return app_descriptors_.end(); } auto end() const { return app_descriptors_.end(); } // [] operator to get app by name AppDescriptor* operator[](const std::string& name) { auto it = app_descriptors_.find(name); if (it != app_descriptors_.end()) { return it->second.get(); } return nullptr; } private: std::map> app_descriptors_ = {}; AppRegistry() = default; // Disable copy and move semantics AppRegistry(const AppRegistry&) = delete; AppRegistry& operator=(const AppRegistry&) = delete; AppRegistry(AppRegistry&&) = delete; AppRegistry& operator=(AppRegistry&&) = delete; };