From fdffa73102e42894f344bdccd4a8adab2e33de0b Mon Sep 17 00:00:00 2001 From: MangaValk Date: Thu, 15 Oct 2026 20:19:44 +0200 Subject: [PATCH] Fix the dynamic page list JSON (missing comma between pages) serializeJson() replaces the String's content, so the comma was lost and the web page could not load any list once a second page existed. Each list now loads on its own, so one failure doesn't empty the others. Co-Authored-By: Claude Opus 5.5 --- src/esp32/web/web_page.h | 6 ++++-- src/esp32/web/web_ui.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/esp32/web/web_page.h b/src/esp32/web/web_page.h index 740a1a9..f356943 100644 --- a/src/esp32/web/web_page.h +++ b/src/esp32/web/web_page.h @@ -181,7 +181,9 @@ function sysinfo(){if(!status)return;const r=[['Firmware',status.firmware],['Las ['Storage',status.storage.available?Math.round(status.storage.used/1024)+' of '+Math.round(status.storage.total/1024)+' KB used':'not available']]; $('sysinfo').innerHTML='';r.forEach(([k,v])=>{const a=document.createElement('label');a.textContent=k;const b=document.createElement('span');b.textContent=v;$('sysinfo').append(a,b)})} // pages, bitmaps and fonts -async function loadLists(){const[b,p,f]=await Promise.all([api('/api/bitmaps'),api('/api/pages'),api('/api/fonts')]); +// each list on its own: one that fails to load doesn't empty the others +async function getList(p,key){try{const j=await api(p);if(Array.isArray(j[key]))return j}catch(e){}msg('Could not load '+p,true);return{[key]:[]}} +async function loadLists(){const[b,p,f]=await Promise.all([getList('/api/bitmaps','bitmaps'),getList('/api/pages','pages'),getList('/api/fonts','fonts')]); bitmapList=b.bitmaps;pageList=p.pages;fontList=f.fonts;bitmapList.forEach(bm=>bm.bits=fromHex(bm.data));pageList.forEach(pg=>pg.bits=fromHex(pg.data)); $('storage').textContent=b.storage?'':'Storage not available: install the new flash layout (see README).'; const pages=$('pages'),offs=$('offpages'),bms=$('bitmaps'),dyn=$('dynpages');pages.innerHTML='';offs.innerHTML='';bms.innerHTML='';dyn.innerHTML=''; @@ -218,7 +220,7 @@ function newEl(t){return{type:t,x:t=='clock'?27:0,y:t=='clock'?5:0,align:'left', function peShow(title,name){$('pe_title').textContent=title;$('pe_name').value=name;$('pe').style.display='block';peData=null;peBuild();pePreview();$('pe').scrollIntoView({behavior:'smooth'})} function peOpen(pg,copy){pe={orig:copy?'':pg.name,page:JSON.parse(JSON.stringify(pg.page)),sel:-1,boxes:[],pos:[]};peShow(copy?'Copy of '+pg.name:'Edit '+pg.name,copy?'':pg.name)} function peNew(){pe={orig:'',page:{slots:[{start:'00:00',bitmap:''}],elements:[newEl('clock')]},sel:-1,boxes:[],pos:[]};peShow('New page','')} -function peClose(){pe=null;$('pe').style.display='none'} +function peClose(){pe=null;$('pe').style.display='none';$('t-pages').scrollIntoView({behavior:'smooth'})} function peBuild(){peSlots();peElems()} function field(label,input){return mk('label',{},label+' ',input)} function inp(o,k,type,props){const i=mk('input',Object.assign({type:type||'text',value:o[k]},props||{}));i.oninput=()=>{o[k]=type=='number'?Math.round(+i.value||0):i.value;pePreview()};return i} diff --git a/src/esp32/web/web_ui.cpp b/src/esp32/web/web_ui.cpp index 0ab0e5a..f7bf59a 100644 --- a/src/esp32/web/web_ui.cpp +++ b/src/esp32/web/web_ui.cpp @@ -288,8 +288,10 @@ static void handlePages() doc["builtin"] = info.builtin; doc["data"] = hex; pageToJson(*page, doc["page"].to()); - String item = first ? "" : ","; - serializeJson(doc, item); + String item; + serializeJson(doc, item); // replaces the string's content, so the comma is sent apart + if (!first) + server.sendContent(","); server.sendContent(item); first = false; }