#pragma once #include #include "app.h" namespace roro { struct AppInfo { const char* id; const char* title; bool hidden; // not listed in the Launcher, but can still be opened App* app; }; // Owns which App is in the foreground and routes keys. Home always returns to the Launcher; // Back is offered to the App first and returns to the Launcher if the App doesn't consume it. class AppManager { public: explicit AppManager(App& launcher); void registerApp(const AppInfo& info); std::vector visibleApps() const; void begin(); bool open(const char* id); // refused while a modal App runs void home(); // A modal App (e.g. the first-boot wizard) can't be left with Home or Back: those keys go to it, // and it ends itself with endModal(), which returns to the Launcher. bool openModal(const char* id); void endModal(); void handleKey(const KeyEvent& event); void update(uint32_t nowMs) { foreground_->update(nowMs); } App& foreground() const { return *foreground_; } const char* foregroundTitle() const; // nullptr for the Launcher // True once after the screen needs redrawing (App switch, or the App asked for it). bool takeRedraw(); private: void switchTo(App& app); App* find(const char* id) const; App& launcher_; App* foreground_; std::vector apps_; bool redraw_ = true; bool modal_ = false; }; } // namespace roro