#include "system_manager.h" #include "shell.h" #include "tft_handler.h" #include "example_programs.h" #include void SystemManager::init(DISPLAY_STATE* display_state, Shell* shell, TFT_Handler* tft) { _display_state = display_state; _shell = shell; _tft = tft; // Register all available programs register_program("CounterProgram"); register_program("TextEditorProgram"); register_program("CalculatorProgram"); register_program("GameProgram"); register_program("SettingsProgram"); } bool SystemManager::spawn_program(Window* window, const std::string& program_class) { // Check if program with same name is already running for (const auto& prog : _programs) { if (prog->get_name() == window->title) { return false; } } // Check if the program class exists auto it = _program_factories.find(program_class); if (it == _program_factories.end()) { Serial.printf("Program class '%s' not found!\n", program_class.c_str()); return false; } // Create the program instance using the factory Program* program = it->second(); // Assign ID and initialize window->id = _next_program_id; program->init(_next_program_id, window->title, window, _shell, _tft, _display_state); _next_program_id++; _programs.push_back(program); Serial.printf("Spawned program: %s (ID: %d)\n", window->title.c_str(), window->id); return true; } void SystemManager::close_program(int id) { for (size_t i = 0; i < _programs.size(); ++i) { if (_programs[i]->get_id() == id) { Serial.printf("Closing program ID: %d\n", id); delete _programs[i]; _programs.erase(_programs.begin() + i); break; } } }