Skip to content

Commit 92eaff1

Browse files
committed
Make finding of miniApps dynamic
Rather than having to manually list the manifest.json file's location, the application attempts to find it on its own
1 parent 25a0e7f commit 92eaff1

2 files changed

Lines changed: 55 additions & 16 deletions

File tree

android/tremola4chrome/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Tremola-Development: virtual backend for the Chrome Browser
22

3-
Rationale: instead of writing JS and HTML code for your app, compile
3+
### Rationale
4+
instead of writing JS and HTML code for your app, compile
45
in Android and then test it, this "tremola4chrome" environment enables
56
you to run it inside a Chrome brower tab.
67

78
Using Chrome's broadcast feature between tabs, new log entries are
89
sent to all tabs where they are funneled to your JS app logic. See the
9-
attached PDF for details (parts in German).
10+
attached PDFs for details in "/docs" (parts in German).
11+
12+
### MiniApp Instructions for Chrome Browser
13+
In order to make use of the chrome environment when developing miniApps, you should start chrome with the *--allow-file-access-from-files* flag. On windows, this can be done by simultaneously pressing Windows + R and then inputting:<br> *chrome.exe --allow-file-access-from-files*
14+
15+
For an overview of the structure of a miniApp, consult the *miniApps.md* file in the */doc* folder

android/tremola4chrome/src/mini_apps.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ if (!window.miniApps) {
1414
window.miniApps = {}; // Ensure it's defined
1515
}
1616

17-
console.log("MiniApps Object:", window.miniApps);
18-
console.log("TicTacToe App:", window.miniApps?.["tictactoe"]);
19-
console.log("TicTacToe handleRequest:", window.miniApps?.["tictactoe"]?.handleRequest);
20-
21-
2217
/**
2318
* Handles the paths to manifest files.
2419
*
@@ -42,18 +37,56 @@ function handleManifestPaths(manifestPathsJson) {
4237
initializeMiniApps();
4338

4439
function initializeMiniApps() {
45-
console.log("Initializing Mini Apps");
46-
let paths = ["../miniApps/tictactoe/manifest.json", "../miniApps/kanban/manifest.json"];
47-
//for each path in paths
48-
paths.forEach(path => {
49-
//read the manifest file
50-
fetch(path)
40+
console.log("Initializing Mini Apps using local directory listing");
41+
42+
const miniAppsUrl = "../miniApps/";
43+
44+
fetch(miniAppsUrl)
5145
.then(response => response.text())
52-
.then(text => handleManifestContent(text))
53-
// outputs the content of the text file
54-
});
46+
.then(htmlText => {
47+
console.log("Directory listing HTML:", htmlText);
48+
49+
// Use regex to extract folder names from addRow calls.
50+
// This regex captures the first string argument of addRow, e.g., "kanban" in addRow("kanban", "kanban", 1, ...)
51+
const regex = /addRow\("([^"]+)"\s*,\s*"([^"]+)"\s*,/g;
52+
const folderNames = [];
53+
let match;
54+
while ((match = regex.exec(htmlText)) !== null) {
55+
const folderName = match[1];
56+
// Exclude "." or ".." if present.
57+
if (folderName !== "." && folderName !== "..") {
58+
folderNames.push(folderName);
59+
}
60+
}
61+
62+
console.log("Extracted mini app folders:", folderNames);
63+
64+
// For each extracted folder name, fetch its manifest.json
65+
folderNames.forEach(folder => {
66+
const manifestPath = `${miniAppsUrl}${folder}/manifest.json`;
67+
fetch(manifestPath)
68+
.then(response => {
69+
if (!response.ok) {
70+
throw new Error(`HTTP error: ${response.status}`);
71+
}
72+
return response.text();
73+
})
74+
.then(manifestText => {
75+
handleManifestContent(manifestText);
76+
})
77+
.catch(error => {
78+
console.error(`Error loading manifest for folder ${folder}:`, error);
79+
});
80+
});
81+
})
82+
.catch(error => {
83+
console.error("Error fetching miniApps directory listing:", error);
84+
});
5585
}
5686

87+
88+
89+
5790
/**
5891
* Handles the content of a manifest file.
5992
*

0 commit comments

Comments
 (0)