From 41b3224e3f0854e8ec760157f732b4727f6801e1 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 26 Aug 2021 13:51:31 +0100 Subject: [PATCH] boot +0.29: Update boot0 to avoid code block (faster execution) + Fix issues where 'Uncaught Error: Function not found' could happen with multiple .boot.js --- apps.json | 2 +- apps/boot/ChangeLog | 2 ++ apps/boot/bootupdate.js | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps.json b/apps.json index b7cfffa37..61eb7cfd1 100644 --- a/apps.json +++ b/apps.json @@ -4,7 +4,7 @@ "tags": "tool,system,b2", "type":"bootloader", "icon": "bootloader.png", - "version":"0.28", + "version":"0.29", "description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings", "storage": [ {"name":".boot0","url":"boot0.js"}, diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index 4a8c62d59..d3ec47139 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -27,3 +27,5 @@ 0.26: Remove buzz in setUI polyfill (#750) 0.27: Update polyfill for most recent changes 0.28: Fix double clock load after settings are changed +0.29: Update boot0 to avoid code block (faster execution) + Fix issues where 'Uncaught Error: Function not found' could happen with multiple .boot.js diff --git a/apps/boot/bootupdate.js b/apps/boot/bootupdate.js index 4c4efed29..199bff6e3 100644 --- a/apps/boot/bootupdate.js +++ b/apps/boot/bootupdate.js @@ -6,7 +6,7 @@ var s = require('Storage').readJSON('setting.json',1)||{}; var isB2 = process.env.HWVERSION; // Is Bangle.js 2 var boot = ""; var CRC = E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\.boot\.js/)); -boot += `if (E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\.boot\.js/))!=${CRC}) { eval(require('Storage').read('bootupdate.js'));} else {\n`; +boot += `if (E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\.boot\.js/))!=${CRC}) { eval(require('Storage').read('bootupdate.js')); throw "Storage Updated!"}\n`; boot += `E.setFlags({pretokenise:1});\n`; if (s.ble!==false) { if (s.HID) { // Human interface device @@ -133,9 +133,11 @@ else if (mode=="updown") { } // Append *.boot.js files require('Storage').list(/\.boot\.js/).forEach(bootFile=>{ - boot += "//"+bootFile+"\n"+require('Storage').read(bootFile)+"\n"; + // we add a semicolon so if the file is wrapped in (function(){ ... }() + // with no semicolon we don't end up with (function(){ ... }()(function(){ ... }() + // which would cause an error! + boot += require('Storage').read(bootFile)+";\n"; }); -boot += "}\n";// initial 'if' require('Storage').write('.boot0',boot); delete boot; E.showMessage("Reloading...");