Skip to content

Commit

Permalink
At connect get list of pre-installed modules and use that to figure o…
Browse files Browse the repository at this point in the history
…ut if we need to drag in other things
gfwilliams committed Oct 24, 2024
1 parent 7e5ac02 commit 97ba433
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions js/appinfo.js
Original file line number Diff line number Diff line change
@@ -100,6 +100,8 @@ function translateJS(options, app, code) {

// Run JS through EspruinoTools to pull in modules/etc
function parseJS(storageFile, options, app) {
options = options||{};
options.device = options.device||{};
if (storageFile.url && storageFile.url.endsWith(".js") && !storageFile.url.endsWith(".min.js")) {
// if original file ends in '.js'...
let js = storageFile.content;
@@ -111,8 +113,12 @@ function parseJS(storageFile, options, app) {
if (typeof window!=="undefined")
localModulesURL = window.location.origin + window.location.pathname.replace(/[^/]*$/,"") + "modules";
let builtinModules = ["Flash","Storage","heatshrink","tensorflow","locale","notify"];
if (options && options.device && options.device.id=="BANGLEJS2")
builtinModules.push("crypto");
// FIXME: now we check options.device.modules below, do we need the hard-coded list above?
if (options.device.modules)
options.device.modules.forEach(mod => {
if (!builtinModules.includes(mod)) builtinModules.push(mod);
});

// add any modules that were defined for this app (no need to search for them!)
builtinModules = builtinModules.concat(app.storage.map(f=>f.name).filter(name => name && !name.includes(".")));
// Check for modules in pre-installed apps?
3 changes: 2 additions & 1 deletion js/comms.js
Original file line number Diff line number Diff line change
@@ -240,7 +240,7 @@ const Comms = {
return;
}

let cmd, finalJS = `JSON.stringify(require("Storage").getStats?require("Storage").getStats():{})+","+E.toJS([process.env.BOARD,process.env.VERSION,process.env.EXPTR,0|getTime(),E.CRC32(getSerial()+NRF.getAddress())]).substr(1)`;
let cmd, finalJS = `JSON.stringify(require("Storage").getStats?require("Storage").getStats():{})+","+E.toJS([process.env.BOARD,process.env.VERSION,process.env.EXPTR,process.env.MODULES,0|getTime(),E.CRC32(getSerial()+NRF.getAddress())]).substr(1)`;
if (Const.SINGLE_APP_ONLY) // only one app on device, info file is in app.info
cmd = `\x10Bluetooth.println("["+(require("Storage").read("app.info")||"null")+","+${finalJS})\n`;
else
@@ -262,6 +262,7 @@ const Comms = {
// unpack the last 6 elements which are board info (See finalJS above)
info.uid = appList.pop(); // unique ID for watch (hash of internal serial number and MAC)
info.currentTime = appList.pop()*1000; // time in ms
info.modules = appList.pop().split(","); // see what modules we have internally so we don't have to upload them if they exist
info.exptr = appList.pop(); // used for compilation
info.version = appList.pop();
info.id = appList.pop();
1 change: 1 addition & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -995,6 +995,7 @@ function getInstalledApps(refresh) {
device.id = info.id;
device.version = info.version;
device.exptr = info.exptr;
device.modules = info.modules||[];
device.storageStats = info.storageStats;
device.appsInstalled = info.apps;
haveInstalledApps = true;

0 comments on commit 97ba433

Please sign in to comment.