Add sandbox API integration for RmlUi Lua state

- Register sandbox APIs (timer, JSON, crypto, VFS) into RmlUi's Lua state
- Add switchAppSandbox() function for context switching between apps
- Update goHome() to reset sandbox context when returning home
- Fix icon loading for third-party apps (handle full paths vs relative)
- Mirror changes between Android service (kernel.cpp) and desktop designer

This enables third-party apps to use sandbox APIs when running in RmlUi.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 15:49:35 +01:00
parent ea44f0bba4
commit cb86d52705
3 changed files with 213 additions and 8 deletions

View File

@@ -810,6 +810,19 @@ bool InitializeRmlUi(const std::string& assets_path, int fb_width, int fb_height
std::cout << "goHome called - returning to home screen" << std::endl;
// Reset sandbox back to home context
if (g_sandbox && !g_current_app_id.empty()) {
g_sandbox->UnregisterAPIs(L);
g_sandbox->Reset();
mosis::DesktopSandboxConfig config;
config.app_id = "com.mosis.home";
config.data_root = g_main_assets_path + "/sandbox_data";
g_sandbox = std::make_unique<mosis::DesktopSandbox>(config);
g_sandbox->RegisterAPIs(L);
std::cout << "Sandbox reset to home context" << std::endl;
}
// Close existing documents (except debugger)
while (g_context->GetNumDocuments() > 1) {
auto* doc = g_context->GetDocument(0);
@@ -839,7 +852,36 @@ bool InitializeRmlUi(const std::string& assets_path, int fb_width, int fb_height
return 1;
});
lua_setglobal(L, "goHome");
std::cout << "Registered Lua loadScreen and goHome functions" << std::endl;
// Register switchAppSandbox function for third-party app launching
lua_pushcfunction(L, [](lua_State* L) -> int {
const char* app_id = luaL_checkstring(L, 1);
const char* install_path = luaL_checkstring(L, 2);
std::cout << "switchAppSandbox called for: " << app_id << " at " << install_path << std::endl;
// Store current app ID
g_current_app_id = app_id;
// Reset sandbox for the new app
if (g_sandbox) {
g_sandbox->UnregisterAPIs(L);
g_sandbox->Reset();
// Re-configure sandbox with app-specific data root
mosis::DesktopSandboxConfig config;
config.app_id = app_id;
config.data_root = std::string(install_path) + "/sandbox_data";
g_sandbox = std::make_unique<mosis::DesktopSandbox>(config);
g_sandbox->RegisterAPIs(L);
std::cout << "Sandbox switched to: " << app_id << std::endl;
}
lua_pushboolean(L, true);
return 1;
});
lua_setglobal(L, "switchAppSandbox");
std::cout << "Registered Lua loadScreen, goHome, and switchAppSandbox functions" << std::endl;
// Register simulator API (if in simulator mode)
if (g_simulator_mode) {