2021-10-23 20:21:36 +00:00
|
|
|
#!/usr/bin/node
|
|
|
|
|
2021-10-28 11:14:02 +00:00
|
|
|
/*
|
|
|
|
var EMULATOR = "banglejs2";
|
|
|
|
var DEVICEID = "BANGLEJS2";
|
|
|
|
*/
|
2021-10-23 20:21:36 +00:00
|
|
|
var EMULATOR = "banglejs1";
|
2021-10-28 11:14:02 +00:00
|
|
|
var DEVICEID = "BANGLEJS";
|
2021-10-23 20:21:36 +00:00
|
|
|
|
2021-10-26 11:40:08 +00:00
|
|
|
var singleAppId;
|
2021-10-23 20:21:36 +00:00
|
|
|
|
2021-10-26 11:40:08 +00:00
|
|
|
if (process.argv.length!=3 && process.argv.length!=2) {
|
2021-10-23 20:21:36 +00:00
|
|
|
console.log("USAGE:");
|
2021-10-26 11:40:08 +00:00
|
|
|
console.log(" bin/thumbnailer.js");
|
|
|
|
console.log(" - all thumbnails");
|
|
|
|
console.log(" bin/thumbnailer.js APP_ID");
|
|
|
|
console.log(" - just one app");
|
2021-10-23 20:21:36 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2021-10-26 11:40:08 +00:00
|
|
|
if (process.argv.length==3)
|
|
|
|
singleAppId = process.argv[2];
|
2021-10-23 20:21:36 +00:00
|
|
|
|
|
|
|
if (!require("fs").existsSync(__dirname + "/../../EspruinoWebIDE")) {
|
|
|
|
console.log("You need to:");
|
|
|
|
console.log(" git clone https://github.com/espruino/EspruinoWebIDE");
|
|
|
|
console.log("At the same level as this project");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
eval(require("fs").readFileSync(__dirname + "/../../EspruinoWebIDE/emu/emulator_"+EMULATOR+".js").toString());
|
|
|
|
eval(require("fs").readFileSync(__dirname + "/../../EspruinoWebIDE/emu/emu_"+EMULATOR+".js").toString());
|
|
|
|
eval(require("fs").readFileSync(__dirname + "/../../EspruinoWebIDE/emu/common.js").toString());
|
|
|
|
|
|
|
|
var SETTINGS = {
|
|
|
|
pretokenise : true
|
|
|
|
};
|
|
|
|
var Const = {
|
|
|
|
};
|
|
|
|
module = undefined;
|
2022-07-12 11:46:25 +00:00
|
|
|
var Espruino = require(__dirname + "/../core/lib/espruinotools.js");
|
|
|
|
//eval(require("fs").readFileSync(__dirname + "/../core/lib/espruinotools.js").toString());
|
2021-10-23 20:21:36 +00:00
|
|
|
eval(require("fs").readFileSync(__dirname + "/../core/js/utils.js").toString());
|
|
|
|
eval(require("fs").readFileSync(__dirname + "/../core/js/appinfo.js").toString());
|
|
|
|
var apps = JSON.parse(require("fs").readFileSync(__dirname+"/../apps.json"));
|
|
|
|
|
2021-10-26 11:40:08 +00:00
|
|
|
/* we factory reset ONCE, get this, then we can use it to reset
|
|
|
|
state quickly for each new app */
|
|
|
|
var factoryFlashMemory = new Uint8Array(FLASH_SIZE);
|
2021-10-28 11:14:02 +00:00
|
|
|
// Log of messages from app
|
|
|
|
var appLog = "";
|
|
|
|
// List of apps that errored
|
|
|
|
var erroredApps = [];
|
2021-10-23 20:21:36 +00:00
|
|
|
|
|
|
|
jsRXCallback = function() {};
|
|
|
|
jsUpdateGfx = function() {};
|
|
|
|
|
2021-10-26 11:40:08 +00:00
|
|
|
function ERROR(s) {
|
|
|
|
console.error(s);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2021-10-28 11:14:02 +00:00
|
|
|
function onConsoleOutput(txt) {
|
|
|
|
appLog += txt + "\n";
|
|
|
|
}
|
|
|
|
|
2021-10-26 11:40:08 +00:00
|
|
|
function getThumbnail(appId, imageFn) {
|
|
|
|
console.log("Thumbnail for "+appId);
|
|
|
|
var app = apps.find(a=>a.id==appId);
|
|
|
|
if (!app) ERROR(`App ${JSON.stringify(appId)} not found`);
|
|
|
|
if (app.custom) ERROR(`App ${JSON.stringify(appId)} requires HTML customisation`);
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
AppInfo.getFiles(app, {
|
|
|
|
fileGetter:function(url) {
|
|
|
|
console.log(__dirname+"/"+url);
|
|
|
|
return Promise.resolve(require("fs").readFileSync(__dirname+"/../"+url).toString("binary"));
|
2021-10-28 11:14:02 +00:00
|
|
|
},
|
|
|
|
settings : SETTINGS,
|
|
|
|
device : { id : DEVICEID }
|
|
|
|
}).then(files => {
|
2022-07-13 19:23:33 +00:00
|
|
|
console.log(`AppInfo returned for ${appId}`);//, files);
|
2021-10-26 11:40:08 +00:00
|
|
|
flashMemory.set(factoryFlashMemory);
|
|
|
|
jsTransmitString("reset()\n");
|
|
|
|
console.log("Uploading...");
|
|
|
|
jsTransmitString("g.clear()\n");
|
|
|
|
var command = files.map(f=>f.cmd).join("\n")+"\n";
|
|
|
|
command += `load("${appId}.app.js")\n`;
|
2021-10-28 11:14:02 +00:00
|
|
|
appLog = "";
|
2021-10-26 11:40:08 +00:00
|
|
|
jsTransmitString(command);
|
|
|
|
console.log("Done.");
|
2022-07-13 19:23:33 +00:00
|
|
|
jsTransmitString("Bangle.setLCDMode();clearInterval();clearTimeout();\n");
|
2021-10-26 11:40:08 +00:00
|
|
|
jsStopIdle();
|
|
|
|
|
|
|
|
var rgba = new Uint8Array(GFX_WIDTH*GFX_HEIGHT*4);
|
|
|
|
jsGetGfxContents(rgba);
|
|
|
|
var rgba32 = new Uint32Array(rgba.buffer);
|
|
|
|
var firstPixel = rgba32[0];
|
|
|
|
var blankImage = rgba32.every(col=>col==firstPixel)
|
|
|
|
|
2022-07-12 12:14:49 +00:00
|
|
|
if (appLog.replace("Uncaught Storage Updated!", "").indexOf("Uncaught")>=0)
|
2021-10-28 11:14:02 +00:00
|
|
|
erroredApps.push( { id : app.id, log : appLog } );
|
|
|
|
|
2021-10-26 11:40:08 +00:00
|
|
|
if (!blankImage) {
|
|
|
|
var Jimp = require("jimp");
|
|
|
|
let image = new Jimp(GFX_WIDTH, GFX_HEIGHT, function (err, image) {
|
|
|
|
if (err) throw err;
|
|
|
|
let buffer = image.bitmap.data;
|
|
|
|
buffer.set(rgba);
|
|
|
|
image.write(imageFn, (err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
console.log("Image written as "+imageFn);
|
|
|
|
resolve(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log("Image is empty");
|
|
|
|
resolve(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var screenshots = [];
|
|
|
|
|
2021-10-23 20:21:36 +00:00
|
|
|
// wait until loaded...
|
|
|
|
setTimeout(function() {
|
|
|
|
console.log("Loaded...");
|
|
|
|
jsInit();
|
2021-10-26 11:40:08 +00:00
|
|
|
jsIdle();
|
|
|
|
console.log("Factory reset");
|
|
|
|
jsTransmitString("Bangle.factoryReset()\n");
|
|
|
|
factoryFlashMemory.set(flashMemory);
|
|
|
|
console.log("Ready!");
|
|
|
|
|
|
|
|
if (singleAppId) {
|
2021-10-28 11:14:02 +00:00
|
|
|
getThumbnail(singleAppId, "screenshots/"+singleAppId+"-"+EMULATOR+".png");
|
2021-10-26 11:40:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-28 11:14:02 +00:00
|
|
|
var appList = apps.filter(app => (!app.type || app.type=="clock") && !app.custom);
|
|
|
|
appList = appList.filter(app => !app.screenshots && app.supports.includes(DEVICEID));
|
|
|
|
|
2021-10-26 11:40:08 +00:00
|
|
|
var promise = Promise.resolve();
|
2021-10-28 11:14:02 +00:00
|
|
|
appList.forEach(app => {
|
2021-10-26 11:40:08 +00:00
|
|
|
promise = promise.then(() => {
|
2021-10-28 11:14:02 +00:00
|
|
|
var imageFile = "screenshots/"+app.id+"-"+EMULATOR+".png";
|
|
|
|
return getThumbnail(app.id, imageFile).then(ok => {
|
2021-10-26 11:40:08 +00:00
|
|
|
screenshots.push({
|
2021-10-28 11:14:02 +00:00
|
|
|
id : app.id,
|
|
|
|
url : imageFile,
|
|
|
|
version: app.version
|
2021-10-23 20:21:36 +00:00
|
|
|
});
|
|
|
|
});
|
2021-10-26 11:40:08 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
promise.then(function() {
|
|
|
|
console.log("Complete!");
|
|
|
|
require("fs").writeFileSync("screenshots.json", JSON.stringify(screenshots,null,2));
|
2021-10-28 11:14:02 +00:00
|
|
|
console.log("Errored Apps", erroredApps);
|
2021-10-26 11:40:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-10-23 20:21:36 +00:00
|
|
|
});
|