Merge pull request #1124 from nebbishhacker/sanitycheck

sanitycheck: Error on incorrectly sized js icons
pull/1126/head
Gordon Williams 2021-12-17 08:32:20 +00:00 committed by GitHub
commit bbfaf5009c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,7 @@
*/ */
var fs = require("fs"); var fs = require("fs");
var heatshrink = require("../core/lib/heatshrink");
var acorn; var acorn;
try { try {
acorn = require("acorn"); acorn = require("acorn");
@ -59,6 +60,7 @@ const STORAGE_KEYS = ['name', 'url', 'content', 'evaluate', 'noOverwite', 'suppo
const DATA_KEYS = ['name', 'wildcard', 'storageFile', 'url', 'content', 'evaluate']; const DATA_KEYS = ['name', 'wildcard', 'storageFile', 'url', 'content', 'evaluate'];
const FORBIDDEN_FILE_NAME_CHARS = /[,;]/; // used as separators in appid.info const FORBIDDEN_FILE_NAME_CHARS = /[,;]/; // used as separators in appid.info
const VALID_DUPLICATES = [ '.tfmodel', '.tfnames' ]; const VALID_DUPLICATES = [ '.tfmodel', '.tfnames' ];
const GRANDFATHERED_ICONS = ["hebrew_calendar", "fontclock", "slidingtext", "solarclock", "sweepclock", "matrixclock", "speedo", "s7clk", "mmonday", "bclock", "snek", "dane", "fclock", "digiclock", "astral", "alpinenav", "slomoclock", "tapelauncher", "arrow", "doztime", "swiperclocklaunch", "pebble", "rebble"];
function globToRegex(pattern) { function globToRegex(pattern) {
const ESCAPE = '.*+-?^${}()|[]\\'; const ESCAPE = '.*+-?^${}()|[]\\';
@ -175,6 +177,23 @@ apps.forEach((app,appIdx) => {
for (const key in file) { for (const key in file) {
if (!STORAGE_KEYS.includes(key)) ERROR(`App ${app.id} file ${file.name} has unknown key ${key}`); if (!STORAGE_KEYS.includes(key)) ERROR(`App ${app.id} file ${file.name} has unknown key ${key}`);
} }
// warn if JS icon is the wrong size
if (file.name == app.id+".img") {
let icon;
let match = fileContents.match(/E\.toArrayBuffer\(atob\(\"([^"]*)\"\)\)/);
if (match) icon = Buffer.from(match[1], 'base64');
else {
match = fileContents.match(/require\(\"heatshrink\"\)\.decompress\(\s*atob\(\s*\"([^"]*)\"\s*\)\s*\)/);
if (match) icon = heatshrink.decompress(Buffer.from(match[1], 'base64'));
else ERROR(`JS icon ${file.name} does not match the pattern 'require("heatshrink").decompress(atob("..."))'`);
}
if (match) {
if (icon[0] != 48 || icon[1] != 48) {
if (GRANDFATHERED_ICONS.includes(app.id)) WARN(`JS icon ${file.name} should be 48x48px but is instead ${icon[0]}x${icon[1]}px`);
else ERROR(`JS icon ${file.name} should be 48x48px but is instead ${icon[0]}x${icon[1]}px`);
}
}
}
}); });
let dataNames = []; let dataNames = [];
(app.data||[]).forEach((data)=>{ (app.data||[]).forEach((data)=>{