// visionA Local — splash / bootstrap // 職責:等 Go server 起來,拿到 URL 後跳轉到 Next.js 主 UI import { GetServerStatus, GetServerURL } from './wailsjs/go/main/App.js'; const statusEl = document.getElementById('status'); const errorEl = document.getElementById('error'); const POLL_INTERVAL_MS = 500; const MAX_WAIT_MS = 60_000; const startTime = Date.now(); async function poll() { if (Date.now() - startTime > MAX_WAIT_MS) { showError('伺服器啟動逾時(60 秒),請檢查 log 或重新啟動應用程式。'); return; } try { const status = await GetServerStatus(); if (status && status.lastError) { showError('伺服器啟動失敗:' + status.lastError); return; } if (status && status.running && status.url) { statusEl.textContent = '啟動完成,載入主介面...'; window.location.replace(status.url + '/'); return; } const url = await GetServerURL(); if (url) { statusEl.textContent = '啟動完成,載入主介面...'; window.location.replace(url + '/'); return; } } catch (e) { // binding 尚未就緒時會 throw,忽略繼續輪詢 } setTimeout(poll, POLL_INTERVAL_MS); } function showError(msg) { statusEl.hidden = true; errorEl.textContent = msg; errorEl.hidden = false; } // 等 Wails runtime 就緒再開始輪詢 if (window.runtime) { poll(); } else { window.addEventListener('load', () => setTimeout(poll, 200)); }