From 1cc7674aa7f990f88644e78d9d19cd981ea34324 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 20 Oct 2021 20:48:38 +0100 Subject: [PATCH] Fix issue where re-running bootupdate could disable existing polyfills --- apps/boot/ChangeLog | 2 +- apps/boot/bootupdate.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index 4ce4dbe65..59d9e4c65 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -33,4 +33,4 @@ 0.31: Add polyfills for g.wrapString, g.imageMetrics, g.stringMetrics 0.32: Fix single quote error in g.wrapString polyfill improve g.stringMetrics polyfill - + Fix issue where re-running bootupdate could disable existing polyfills diff --git a/apps/boot/bootupdate.js b/apps/boot/bootupdate.js index a5ec01fa4..269a80831 100644 --- a/apps/boot/bootupdate.js +++ b/apps/boot/bootupdate.js @@ -81,9 +81,11 @@ if (s.quiet && s.qmTimeout) boot+=`Bangle.setLCDTimeout(${s.qmTimeout});\n`; if (s.passkey!==undefined && s.passkey.length==6) boot+=`NRF.setSecurity({passkey:${s.passkey}, mitm:1, display:1});\n`; if (s.whitelist) boot+=`NRF.on('connect', function(addr) { if (!(require('Storage').readJSON('setting.json',1)||{}).whitelist.includes(addr)) NRF.disconnect(); });\n`; // Pre-2v10 firmwares without a theme/setUI +delete g.theme; // deleting stops us getting confused by our own decl. builtins can't be deleted if (!g.theme) { boot += `g.theme={fg:-1,bg:0,fg2:-1,bg2:7,fgH:-1,bgH:0x02F7,dark:true};\n`; } +delete Bangle.setUI; // deleting stops us getting confused by our own decl. builtins can't be deleted if (!Bangle.setUI) { // assume this is just for F18 - Q3 should already have it boot += `Bangle.setUI=function(mode, cb) { if (Bangle.btnWatches) { @@ -131,6 +133,7 @@ else if (mode=="updown") { throw new Error("Unknown UI mode"); };\n`; } +delete g.imageMetrics; // deleting stops us getting confused by our own decl. builtins can't be deleted if (!g.imageMetrics) { // added in 2v11 - this is a limited functionality polyfill boot += `Graphics.prototype.imageMetrics=function(src) { if (src[0]) return {width:src[0],height:src[1]}; @@ -141,12 +144,14 @@ if (!g.imageMetrics) { // added in 2v11 - this is a limited functionality polyfi return {width:im.charCodeAt(0), height:im.charCodeAt(1)}; };\n`; } +delete g.stringMetrics; // deleting stops us getting confused by our own decl. builtins can't be deleted if (!g.stringMetrics) { // added in 2v11 - this is a limited functionality polyfill boot += `Graphics.prototype.stringMetrics=function(txt) { txt = txt.toString().split("\\n"); return {width:Math.max.apply(null,txt.map(x=>g.stringWidth(x))), height:this.getFontHeight()*txt.length}; };\n`; } +delete g.wrapString; // deleting stops us getting confused by our own decl. builtins can't be deleted if (!g.wrapString) { // added in 2v11 - this is a limited functionality polyfill boot += `Graphics.prototype.wrapString=function(str, maxWidth) { var lines = [];