BangleApps/bin/thumbnailer.js

102 lines
2.6 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
/*
var EMULATOR = "banglejs2";
var DEVICEID = "BANGLEJS2";
*/
var EMULATOR = "banglejs1";
var DEVICEID = "BANGLEJS";
var emu = require("./lib/emulator.js");
var apploader = require("./lib/apploader.js");
2021-10-26 11:40:08 +00:00
var singleAppId;
2021-10-26 11:40:08 +00:00
if (process.argv.length!=3 && process.argv.length!=2) {
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");
process.exit(1);
}
2021-10-26 11:40:08 +00:00
if (process.argv.length==3)
singleAppId = process.argv[2];
// List of apps that errored
var erroredApps = [];
2021-10-26 11:40:08 +00:00
function ERROR(s) {
console.error(s);
process.exit(1);
}
function getThumbnail(appId, imageFn) {
console.log("Thumbnail for "+appId);
var app = apploader.apps.find(a=>a.id==appId);
2021-10-26 11:40:08 +00:00
if (!app) ERROR(`App ${JSON.stringify(appId)} not found`);
if (app.custom) ERROR(`App ${JSON.stringify(appId)} requires HTML customisation`);
return apploader.getAppFilesString(app).then(command => {
console.log(`AppInfo returned for ${appId}`);//, files);
emu.factoryReset();
console.log("Uploading...");
emu.tx("g.clear()\n");
command += `load("${appId}.app.js")\n`;
appLog = "";
emu.tx(command);
console.log("Done.");
emu.tx("Bangle.setLCDMode();clearInterval();clearTimeout();\n");
emu.stopIdle();
return emu.writeScreenshot(imageFn, { errorIfBlank : true }).then(() => console.log("X")).catch( err => {
console.log("Error", err);
2021-10-26 11:40:08 +00:00
});
});
}
var screenshots = [];
apploader.init({
EMULATOR : EMULATOR,
DEVICEID : DEVICEID
});
// wait until loaded...
emu.init({
EMULATOR : EMULATOR,
DEVICEID : DEVICEID
}).then(function() {
2021-10-26 11:40:08 +00:00
if (singleAppId) {
console.log("Single Screenshot");
getThumbnail(singleAppId, "screenshots/"+singleAppId+"-"+EMULATOR+".png");
2021-10-26 11:40:08 +00:00
return;
}
console.log("Screenshot ALL");
var appList = apploader.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();
appList.forEach(app => {
2021-10-26 11:40:08 +00:00
promise = promise.then(() => {
var imageFile = "screenshots/"+app.id+"-"+EMULATOR+".png";
return getThumbnail(app.id, imageFile).then(ok => {
2021-10-26 11:40:08 +00:00
screenshots.push({
id : app.id,
url : imageFile,
version: app.version
});
});
2021-10-26 11:40:08 +00:00
});
});
promise.then(function() {
console.log("Complete!");
require("fs").writeFileSync("screenshots.json", JSON.stringify(screenshots,null,2));
console.log("Errored Apps", erroredApps);
2021-10-26 11:40:08 +00:00
});
});