Files
ink-board/main/ui/apps/registry.h
GW_MC 06e81301b2 Refactor RootLayout and UIHandler for improved structure and functionality
- Updated RootLayout to manage layout initialization and deinitialization more effectively.
- Removed unnecessary dependencies and streamlined event handling for keyboard events.
- Enhanced UIHandler to utilize shared pointers for app descriptors, improving memory management.
- Added methods for showing and hiding navigation elements in RootLayout.
- Introduced textarea widget with instant response by disabling animations.
- Improved error handling and logging throughout the UI components.
2026-02-01 13:03:56 +08:00

54 lines
1.5 KiB
C++

#pragma once
#include "ui/apps/app.h"
#include <map>
#include <string>
#include "esp_log.h"
#include <memory>
class AppRegistry {
public:
static AppRegistry& instance() {
static AppRegistry registry;
return registry;
}
void register_app(std::unique_ptr<AppDescriptor> 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<std::string, std::unique_ptr<AppDescriptor>> 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;
};