Skip to content

Commit d7ee2ec

Browse files
authored
Merge pull request #4403 from NopeCharon/boot-widcache-trailing-comment
[boot] Don't break .widcache/.clkinfocache/.boot0 when a file ends in a comment
2 parents a677f00 + 8b40558 commit d7ee2ec

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎apps/boot/ChangeLog‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@
8282
0.69: Implement "Charge Vibration" option in Settings (was in widbat before)
8383
Allow fast load to clock if WIDGETS are not defined.
8484
Small tidyup to help reduce time spent executing JS in old .boot0 file
85+
0.70: Fix .boot0, .widcache and .clkinfocache breaking if a boot/widget/clockinfo file ends in a comment with no trailing newline (fix #3939)

‎apps/boot/bootupdate.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ let outputFileComplete = (dst,fn) => {
161161
// with no semicolon we don't end up with (function(){ ... }()(function(){ ... }()
162162
// which would cause an error!
163163
// we write:
164-
// "//"+bootFile+"\n"+require('Storage').read(bootFile)+";\n";
164+
// "//"+bootFile+"\n"+require('Storage').read(bootFile)+"\n;\n";
165165
// but we need to do this without ever loading everything into RAM as some
166166
// boot files seem to be getting pretty big now.
167-
outputFile(dst,fn,"",";\n");
167+
// The newline before the semicolon ensures that if the file ends in a
168+
// `// comment` with no trailing newline, the comment doesn't swallow it (#3939)
169+
outputFile(dst,fn,"","\n;\n");
168170
};
169171
fileOffset = boot.length + bootPost.length;
170172
bootFiles.forEach(fn=>outputFileComplete(undefined,fn)); // just get sizes
@@ -180,7 +182,8 @@ let widget = `// Made by bootupdate.js\nglobal.WIDGETS={};`, widgetPost = `var W
180182
Object.keys(W).sort((a,b)=>(0|W[b].sortorder)-(0|W[a].sortorder)).forEach(k=>WIDGETS[k]=W[k]);`; // sort
181183
if (DEBUG) widget+="var _tm=Date.now();";
182184
outputFileComplete = (dst,fn) => {
183-
outputFile(dst,fn,"try{",`}catch(e){print(${E.toJS(fn)},e,e.stack)}\n`);
185+
// newline before '}' in case the widget ends in a '// comment' (#3939)
186+
outputFile(dst,fn,"try{",`\n}catch(e){print(${E.toJS(fn)},e,e.stack)}\n`);
184187
};
185188
fileOffset = widget.length + widgetPost.length;
186189
widgetFiles.forEach(fn=>outputFileComplete(undefined,fn)); // just get sizes
@@ -197,7 +200,8 @@ let ci_exclude = (require("Storage").readJSON("clock_info.json", 1) || {}).exclu
197200
if (DEBUG) ci+="var _tm=Date.now();";
198201
outputFileComplete = (dst,fn) => {
199202
if (ci_exclude && ci_exclude[fn]) return;
200-
outputFile(dst,fn,"try{let fn=",`;let a=fn(),b=menu.find(x=>x.name===a.name);if(b)b.items=b.items.concat(a.items)else menu=menu.concat(a);}catch(e){print(${E.toJS(fn)},e,e.stack)}\n`);
203+
// newline before ';' in case the clockinfo ends in a '// comment' (#3939)
204+
outputFile(dst,fn,"try{let fn=",`\n;let a=fn(),b=menu.find(x=>x.name===a.name);if(b)b.items=b.items.concat(a.items)else menu=menu.concat(a);}catch(e){print(${E.toJS(fn)},e,e.stack)}\n`);
201205
};
202206
fileOffset = ci.length;
203207
ciFiles.forEach(fn=>outputFileComplete(undefined,fn)); // just get sizes

‎apps/boot/metadata.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "boot",
33
"name": "Bootloader",
4-
"version": "0.69",
4+
"version": "0.70",
55
"author": "ra100",
66
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
77
"icon": "bootloader.png",

0 commit comments

Comments
 (0)