Refactor app loading and window management (#609)

This commit is contained in:
Ken Van Hoeylandt
2026-08-11 23:40:59 +02:00
committed by GitHub
parent dc3f6104b8
commit 37c507544b
243 changed files with 16034 additions and 10865 deletions
+60 -34
View File
@@ -1,50 +1,76 @@
#include <Tactility/app/files/View.h>
#include <Tactility/app/files/State.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/service/loader/Loader.h>
#include <app/event.h>
#include <app/manager.h>
#include <app/manifest.h>
#include <lvgl_window_manager/window_manager.h>
#include <memory>
namespace tt::app::files {
extern const AppManifest manifest;
extern const ::AppManifest manifest;
class FilesApp final : public App {
namespace {
std::unique_ptr<View> view;
std::shared_ptr<State> state;
public:
FilesApp() {
state = std::make_shared<State>();
view = std::make_unique<View>(state);
}
void onShow(AppContext& appContext, lv_obj_t* parent) override {
view->init(appContext, parent);
}
void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
view->onResult(launchId, result, std::move(bundle));
}
void onHide(AppContext& appContext) override {
view->deinit(appContext);
}
struct CreateContext {
View* view;
uint32_t appInstanceId;
};
extern const AppManifest manifest = {
.appId = "Files",
.appName = "Files",
.appCategory = Category::System,
.appFlags = AppManifest::Flags::Hidden,
.createApp = create<FilesApp>
};
void createWidgets(lv_obj_t* parent, void* userData) {
auto* ctx = static_cast<CreateContext*>(userData);
ctx->view->init(ctx->appInstanceId, parent);
}
void start() {
app::start(manifest.appId);
int32_t appMain(uint32_t appInstanceId, int argc, char* argv[]) {
auto state = std::make_shared<State>();
View view(state);
CreateContext createContext { &view, appInstanceId };
AppEventSubscription sub {};
sub.app_instance_id = appInstanceId;
app_event_subscribe(&sub);
WindowId window = window_manager_create(appInstanceId, createWidgets, &createContext);
bool shouldClose = false;
while (!shouldClose) {
AppEvent event {};
if (app_event_await(&sub, &event, portMAX_DELAY) != ERROR_NONE) {
break;
}
switch (event.type) {
case APP_EVENT_CLOSE:
app_manager_finish(appInstanceId);
shouldClose = true;
break;
case APP_EVENT_RESULT:
view.onResult(event.result.launch_id, event.result.result);
app_manager_stop(event.result.launch_id);
break;
default:
break;
}
}
view.deinit();
window_manager_remove(window);
app_event_unsubscribe(&sub);
return 0;
}
} // namespace
extern const ::AppManifest manifest = {
.id = "Files",
.name = "Files",
.category = APP_CATEGORY_SYSTEM,
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
.flags = APP_MANIFEST_FLAG_HIDDEN,
};
} // namespace