fix Android: load shell.rml, add loadAppContent function, fallback to built-in apps

This commit is contained in:
2026-01-20 10:56:58 +01:00
parent 41fc6fdd86
commit 2134a53921
3 changed files with 188 additions and 39 deletions

View File

@@ -20,6 +20,7 @@
#include <chrono>
#include <format>
#include <fstream>
#include <sstream>
#include <filesystem>
// Sandbox API includes for RmlUi integration
@@ -390,8 +391,8 @@ static int LuaGoHome(lua_State* L)
// Switch sandbox context back to home screen
SwitchAppSandbox("com.mosis.home", g_data_root);
// Load home screen
const char* home_path = "apps/home/home.rml";
// Load shell (which shows home by default)
const char* home_path = "apps/shell/shell.rml";
// Unload current document
if (g_document)
@@ -525,6 +526,57 @@ static int LuaSwitchAppSandbox(lua_State* L)
return 1;
}
// Load app content fragment into a container element
static int LuaLoadAppContent(lua_State* L)
{
// Get element from first argument
Rml::Element* element = Rml::Lua::LuaType<Rml::Element>::check(L, 1);
if (!element) {
Logger::Log("loadAppContent: Invalid element argument");
lua_pushboolean(L, false);
return 1;
}
// Get path from second argument
const char* path = luaL_checkstring(L, 2);
Logger::Log(std::format("loadAppContent: Loading {} into element", path));
// Read file content - try assets first, then filesystem
std::string content;
AAssetManager* am = AssetsManager::Native();
AAsset* asset = AAssetManager_open(am, path, AASSET_MODE_BUFFER);
if (asset) {
// Load from assets
size_t length = AAsset_getLength(asset);
const char* data = static_cast<const char*>(AAsset_getBuffer(asset));
content = std::string(data, length);
AAsset_close(asset);
Logger::Log(std::format(" -> Loaded {} bytes from assets", length));
} else {
// Try filesystem (for installed apps)
std::string fs_path = GetFilesDir() + "/" + path;
std::ifstream file(fs_path);
if (file.is_open()) {
std::stringstream buffer;
buffer << file.rdbuf();
content = buffer.str();
Logger::Log(std::format(" -> Loaded {} bytes from filesystem", content.size()));
} else {
Logger::Log(std::format("loadAppContent: Cannot open file: {}", path));
lua_pushboolean(L, false);
return 1;
}
}
// Set inner RML
element->SetInnerRML(content);
Logger::Log("loadAppContent: Content loaded successfully");
lua_pushboolean(L, true);
return 1;
}
// Register Lua functions for navigation
static void RegisterLuaFunctions(const std::string& current_app_id, bool is_system_app)
{
@@ -535,7 +587,9 @@ static void RegisterLuaFunctions(const std::string& current_app_id, bool is_syst
lua_setglobal(L, "goHome");
lua_pushcfunction(L, LuaSwitchAppSandbox);
lua_setglobal(L, "switchAppSandbox");
Logger::Log("Registered Lua loadScreen, goHome, and switchAppSandbox functions");
lua_pushcfunction(L, LuaLoadAppContent);
lua_setglobal(L, "loadAppContent");
Logger::Log("Registered Lua loadScreen, goHome, switchAppSandbox, and loadAppContent functions");
// Register app management APIs
if (g_app_manager && g_update_service) {
@@ -633,11 +687,11 @@ void Kernel::main_loop()
Rml::LoadFontFace("fonts/Roboto/Roboto-VariableFont_wdth,wght.ttf");
Rml::LoadFontFace("fonts/Roboto/Roboto-Italic-VariableFont_wdth,wght.ttf");
// Load home screen document
g_document = g_context->LoadDocument("apps/home/home.rml");
// Load shell document (provides persistent status bar, nav bar, and loads home content)
g_document = g_context->LoadDocument("apps/shell/shell.rml");
if (!g_document)
{
Logger::Log("Failed to load home.rml document");
Logger::Log("Failed to load shell.rml document");
Rml::Shutdown();
return;
}