From c89a3b7333997115d08df70e7f7501da6332f8a0 Mon Sep 17 00:00:00 2001 From: jackyu66git Date: Sun, 3 May 2026 19:42:06 +0800 Subject: [PATCH] fix: loadTrades before chart init + try-catch for CDN failure - Reorder init(): loadTrades() runs first, charts second - Wrap chart init in try-catch so UI survives CDN issues - Update start.sh to detect changes in embedded .html/.js/.css --- start.sh | 5 +++-- web/static/app.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/start.sh b/start.sh index 855a5b7..e9b594c 100755 --- a/start.sh +++ b/start.sh @@ -29,8 +29,9 @@ if ss -tlnp 2>/dev/null | grep -q ":$PORT "; then exit 1 fi -# 编译(如果源码有变更) -if [ ! -x "$BIN" ] || [ "$(find . -name '*.go' -newer "$BIN" 2>/dev/null | head -1)" ]; then +# 编译(如果源码或嵌入文件有变更) +WEB_FILES=$(find web/static -name '*.html' -o -name '*.js' -o -name '*.css' 2>/dev/null) +if [ ! -x "$BIN" ] || [ -n "$(find . -name '*.go' $WEB_FILES -newer "$BIN" 2>/dev/null | head -1)" ]; then echo "[start] 编译新二进制..." go build -o "$BIN" . 2>&1 fi diff --git a/web/static/app.js b/web/static/app.js index 9f835f6..70c1446 100644 --- a/web/static/app.js +++ b/web/static/app.js @@ -610,10 +610,10 @@ window.closeTradeDetail = closeTradeDetail; // ---- Init ---- function init() { connectSSE(); - initPriceChart(); - initSpreadChart(); - loadTrades(); + loadTrades(); // run before charts in case Chart CDN is slow setInterval(loadTrades, 10000); + try { initPriceChart(); } catch(e) { console.warn('Price chart init failed:', e); } + try { initSpreadChart(); } catch(e) { console.warn('Spread chart init failed:', e); } } if (document.readyState === 'loading') {