Skip to content

Commit 97ba433

Browse files
committed
At connect get list of pre-installed modules and use that to figure out if we need to drag in other things
1 parent 7e5ac02 commit 97ba433

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

js/appinfo.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ function translateJS(options, app, code) {
100100

101101
// Run JS through EspruinoTools to pull in modules/etc
102102
function parseJS(storageFile, options, app) {
103+
options = options||{};
104+
options.device = options.device||{};
103105
if (storageFile.url && storageFile.url.endsWith(".js") && !storageFile.url.endsWith(".min.js")) {
104106
// if original file ends in '.js'...
105107
let js = storageFile.content;
@@ -111,8 +113,12 @@ function parseJS(storageFile, options, app) {
111113
if (typeof window!=="undefined")
112114
localModulesURL = window.location.origin + window.location.pathname.replace(/[^/]*$/,"") + "modules";
113115
let builtinModules = ["Flash","Storage","heatshrink","tensorflow","locale","notify"];
114-
if (options && options.device && options.device.id=="BANGLEJS2")
115-
builtinModules.push("crypto");
116+
// FIXME: now we check options.device.modules below, do we need the hard-coded list above?
117+
if (options.device.modules)
118+
options.device.modules.forEach(mod => {
119+
if (!builtinModules.includes(mod)) builtinModules.push(mod);
120+
});
121+
116122
// add any modules that were defined for this app (no need to search for them!)
117123
builtinModules = builtinModules.concat(app.storage.map(f=>f.name).filter(name => name && !name.includes(".")));
118124
// Check for modules in pre-installed apps?

js/comms.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ const Comms = {
240240
return;
241241
}
242242

243-
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)`;
243+
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)`;
244244
if (Const.SINGLE_APP_ONLY) // only one app on device, info file is in app.info
245245
cmd = `\x10Bluetooth.println("["+(require("Storage").read("app.info")||"null")+","+${finalJS})\n`;
246246
else
@@ -262,6 +262,7 @@ const Comms = {
262262
// unpack the last 6 elements which are board info (See finalJS above)
263263
info.uid = appList.pop(); // unique ID for watch (hash of internal serial number and MAC)
264264
info.currentTime = appList.pop()*1000; // time in ms
265+
info.modules = appList.pop().split(","); // see what modules we have internally so we don't have to upload them if they exist
265266
info.exptr = appList.pop(); // used for compilation
266267
info.version = appList.pop();
267268
info.id = appList.pop();

js/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ function getInstalledApps(refresh) {
995995
device.id = info.id;
996996
device.version = info.version;
997997
device.exptr = info.exptr;
998+
device.modules = info.modules||[];
998999
device.storageStats = info.storageStats;
9991000
device.appsInstalled = info.apps;
10001001
haveInstalledApps = true;

0 commit comments

Comments
 (0)