Skip to content

Commit 25a0e7f

Browse files
committed
Allow dynamic loading of miniApp files
1 parent dbebb7a commit 25a0e7f

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

android/tremola4chrome/resources/tremola.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
<script type="text/javascript" charset="UTF-8" src="../src/sketch.js"></script>
1717
<script type="text/javascript" charset="UTF-8" src="../src/miniAppHelper.js"></script>
1818
<script type="text/javascript" charset="UTF-8" src="../src/mini_apps.js"></script>
19-
<!-- Import all miniapp files here (only for chrome)-->
20-
<script type="text/javascript" charset="UTF-8" src="../miniApps/tictactoe/src/ttt.js"></script>
21-
<script type="text/javascript" charset="UTF-8" src="../miniApps/tictactoe/src/ttt_ui.js"></script>
22-
<link rel="stylesheet" type="text/css" href="../miniApps/tictactoe/resources/ttt.css" media="screen" />
2319
</head>
2420
<body style="background-image: url('../assets/splash-as-background.jpg'); background-size: cover; background-color: white; overflow: hidden" onload="backend('ready');">
2521
<div style="width: 100%; height: 100%; margin: 0px">

android/tremola4chrome/src/mini_apps.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,53 @@ function initializeMiniApps() {
6565
function handleManifestContent(content) {
6666
setTimeout(() => {
6767
const manifest = JSON.parse(content);
68-
let htmlFile = "../miniApps/" + manifest.id + "/" + manifest.htmlFile;
68+
let miniAppPath = "../miniApps/" + manifest.id + "/";
69+
70+
// Load and inject CSS file
71+
if (manifest.cssFile) {
72+
const cssFilePath = miniAppPath + manifest.cssFile;
73+
fetch(cssFilePath)
74+
.then(response => response.text())
75+
.then(cssContent => {
76+
const styleEl = document.createElement('style');
77+
styleEl.innerText = cssContent;
78+
document.head.appendChild(styleEl);
79+
console.log("CSS content added to document head:", cssFilePath);
80+
})
81+
.catch(error => console.error("Error loading CSS:", error));
82+
}
6983

84+
// Load and inject HTML file
85+
let htmlFile = miniAppPath + manifest.htmlFile;
7086
fetch(htmlFile)
7187
.then(response => response.text())
7288
.then(text => {
7389
(function () {
7490
var coreDiv = document.getElementById('core');
7591
if (coreDiv) {
76-
coreDiv.insertAdjacentHTML("beforeend", text); // ✅ Fix: Keeps existing elements
92+
coreDiv.insertAdjacentHTML("beforeend", text);
7793
console.log("HTML content added to core div");
7894
} else {
7995
console.log("Core div not found");
8096
}
8197
})();
8298
})
8399
.catch(error => console.error("Error loading HTML:", error));
100+
101+
// Load and inject JS files from the "scripts" array
102+
const scripts = manifest.scripts || [];
103+
scripts.forEach(scriptPath => {
104+
let fullScriptPath = miniAppPath + scriptPath;
105+
fetch(fullScriptPath)
106+
.then(response => response.text())
107+
.then(scriptContent => {
108+
const scriptEl = document.createElement('script');
109+
scriptEl.text = scriptContent;
110+
document.body.appendChild(scriptEl);
111+
console.log("JS file loaded and executed:", fullScriptPath);
112+
})
113+
.catch(error => console.error("Error loading JS:", error));
114+
});
84115

85116
// Process the manifest data (e.g., create buttons)
86117
const listElement = document.getElementById("lst:miniapps");

0 commit comments

Comments
 (0)