add dynamic app discovery and remove unused static RML files
This commit is contained in:
@@ -67,6 +67,12 @@ function loadAppContent_internal(app_id, app_path)
|
||||
current_app = app_id
|
||||
current_app_path = app_path
|
||||
print("[Shell] App loaded: " .. app_id)
|
||||
|
||||
-- If home was loaded, populate apps dynamically
|
||||
if app_id == "home" then
|
||||
populateHomeApps()
|
||||
end
|
||||
|
||||
return true
|
||||
else
|
||||
print("[Shell] Failed to load app: " .. app_id)
|
||||
@@ -347,11 +353,167 @@ function shellCanGoBack()
|
||||
return #nav_history > 0
|
||||
end
|
||||
|
||||
-- ===== DYNAMIC APP DISCOVERY =====
|
||||
|
||||
-- Default colors for apps without custom colors
|
||||
local app_colors = {
|
||||
["com.mosis.browser"] = "#F44336",
|
||||
["com.mosis.camera"] = "#9C27B0",
|
||||
["com.mosis.contacts"] = "#FF9800",
|
||||
["com.mosis.dialer"] = "#4CAF50",
|
||||
["com.mosis.messages"] = "#2196F3",
|
||||
["com.mosis.music"] = "#E91E63",
|
||||
["com.mosis.settings"] = "#607D8B",
|
||||
["com.mosis.store"] = "#3F51B5",
|
||||
}
|
||||
|
||||
-- Default color for unknown apps
|
||||
local default_colors = {
|
||||
"#FF5722", "#009688", "#795548", "#673AB7",
|
||||
"#3F51B5", "#00BCD4", "#8BC34A", "#CDDC39"
|
||||
}
|
||||
local color_index = 1
|
||||
|
||||
function getAppColor(package_id)
|
||||
if app_colors[package_id] then
|
||||
return app_colors[package_id]
|
||||
end
|
||||
-- Assign a default color
|
||||
local color = default_colors[color_index]
|
||||
color_index = (color_index % #default_colors) + 1
|
||||
app_colors[package_id] = color
|
||||
return color
|
||||
end
|
||||
|
||||
-- Populate home screen with discovered apps
|
||||
function populateHomeApps()
|
||||
if not mosis or not mosis.apps then
|
||||
print("[Shell] mosis.apps not available")
|
||||
return
|
||||
end
|
||||
|
||||
local apps = mosis.apps.getInstalled()
|
||||
if not apps or #apps == 0 then
|
||||
print("[Shell] No apps discovered")
|
||||
return
|
||||
end
|
||||
|
||||
print("[Shell] Populating home with " .. #apps .. " apps")
|
||||
|
||||
local grid_container = shell_document:GetElementById("installed-apps")
|
||||
if not grid_container then
|
||||
print("[Shell] installed-apps container not found")
|
||||
return
|
||||
end
|
||||
|
||||
local apps_html = ""
|
||||
local dock_apps = {}
|
||||
|
||||
for _, app in ipairs(apps) do
|
||||
-- Skip home app itself
|
||||
if app.package_id ~= "com.mosis.home" then
|
||||
local color = getAppColor(app.package_id)
|
||||
local icon = app.icon or "../../icons/app.tga"
|
||||
local name = app.name or app.package_id
|
||||
|
||||
-- Build app icon HTML
|
||||
local app_html = [[
|
||||
<div class="app-icon">
|
||||
<div class="app-icon-image" style="background-color: ]] .. color .. [[;"
|
||||
onclick="launchDiscoveredApp(']] .. app.package_id .. [[')">
|
||||
<img src="]] .. icon .. [["/>
|
||||
</div>
|
||||
<span class="app-icon-label">]] .. name .. [[</span>
|
||||
</div>
|
||||
]]
|
||||
apps_html = apps_html .. app_html
|
||||
|
||||
-- Track dock apps (dialer, messages, contacts, browser)
|
||||
if app.package_id == "com.mosis.dialer" then
|
||||
dock_apps.dialer = {icon = icon, color = color, id = app.package_id}
|
||||
elseif app.package_id == "com.mosis.messages" then
|
||||
dock_apps.messages = {icon = icon, color = color, id = app.package_id}
|
||||
elseif app.package_id == "com.mosis.contacts" then
|
||||
dock_apps.contacts = {icon = icon, color = color, id = app.package_id}
|
||||
elseif app.package_id == "com.mosis.browser" then
|
||||
dock_apps.browser = {icon = icon, color = color, id = app.package_id}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set grid content
|
||||
grid_container.inner_rml = apps_html
|
||||
|
||||
-- Populate dock
|
||||
local dock_container = shell_document:GetElementById("home-dock")
|
||||
if dock_container and (dock_apps.dialer or dock_apps.messages or dock_apps.contacts or dock_apps.browser) then
|
||||
local dock_html = ""
|
||||
local dock_order = {"dialer", "messages", "contacts", "browser"}
|
||||
for _, key in ipairs(dock_order) do
|
||||
local app = dock_apps[key]
|
||||
if app then
|
||||
dock_html = dock_html .. [[
|
||||
<div class="dock-item" style="background-color: ]] .. app.color .. [[;"
|
||||
onclick="launchDiscoveredApp(']] .. app.id .. [[')">
|
||||
<img src="]] .. app.icon .. [["/>
|
||||
</div>
|
||||
]]
|
||||
end
|
||||
end
|
||||
dock_container.inner_rml = dock_html
|
||||
end
|
||||
|
||||
print("[Shell] Home populated with " .. #apps - 1 .. " apps")
|
||||
end
|
||||
|
||||
-- Launch a discovered app by package_id
|
||||
function launchDiscoveredApp(package_id)
|
||||
if not mosis or not mosis.apps then
|
||||
print("[Shell] mosis.apps not available")
|
||||
showToast("Cannot launch app", "error")
|
||||
return
|
||||
end
|
||||
|
||||
local apps = mosis.apps.getInstalled()
|
||||
for _, app in ipairs(apps) do
|
||||
if app.package_id == package_id then
|
||||
print("[Shell] Launching discovered app: " .. package_id)
|
||||
|
||||
-- Push current to history
|
||||
if current_app then
|
||||
table.insert(nav_history, {
|
||||
app_id = current_app,
|
||||
app_path = current_app_path
|
||||
})
|
||||
print("[Shell] Pushed to history: " .. current_app .. " (depth: " .. #nav_history .. ")")
|
||||
end
|
||||
|
||||
-- Build content path - convert entry.rml to entry_content.rml
|
||||
local entry = app.entry_point or "main.rml"
|
||||
local content_entry = entry:gsub("%.rml$", "_content.rml")
|
||||
local content_path = "apps/" .. package_id:gsub("com.mosis.", "") .. "/" .. content_entry
|
||||
|
||||
-- Switch sandbox if available
|
||||
if switchAppSandbox then
|
||||
switchAppSandbox(package_id, app.install_path)
|
||||
end
|
||||
|
||||
return loadAppContent_internal(package_id, content_path)
|
||||
end
|
||||
end
|
||||
|
||||
print("[Shell] App not found: " .. package_id)
|
||||
showToast("App not found", "error")
|
||||
return false
|
||||
end
|
||||
|
||||
-- Make shell functions globally available for apps
|
||||
_G.showToast = showToast
|
||||
_G.showDialog = showDialog
|
||||
_G.addNotification = addNotification
|
||||
_G.shellNavigateTo = shellNavigateTo
|
||||
_G.shellLaunchApp = shellLaunchApp
|
||||
_G.launchDiscoveredApp = launchDiscoveredApp
|
||||
_G.populateHomeApps = populateHomeApps
|
||||
|
||||
print("[Shell] Shell script loaded")
|
||||
|
||||
Reference in New Issue
Block a user