function escapeHtml(text) { return text.replace(/[&<>"]/g, (char) => { if (char === "&") return "&"; if (char === "<") return "<"; if (char === ">") return ">"; return """; }); } function time(at) { return new Date(at).toLocaleTimeString("zh-CN", { hour12: false }); } function checkRow(check) { return `
  • ${check.pass ? "PASS" : "FAIL"} ${escapeHtml(check.label)} ${escapeHtml(check.detail)}
  • `; } function schemeRow(row) { return ` ${escapeHtml(row.name)} ${escapeHtml(row.feed)} ${escapeHtml(row.updates)} ${escapeHtml(row.limits)} `; } function feedButton(row, active) { return ``; } export function mountApp(root) { root.innerHTML = `

    自动更新决策台

    feed 解析 · 版本决策 · 提示状态机 · 不安装替换
    只决策 · 不安装 —

    四类更新方案

    —
    方案feed更新方限制

    检查与决策

    —
    当前版本 —

    提示状态只影响 UI,不会触发下载或安装。

    Feed 预览

    —
    
              

    官方服务门槛

    update.electronjs.org

      需要公开 GitHub 仓库 + GitHub Releases;仅 macOS/Windows; macOS 需签名;不支持 Linux。

      决策自检

      —

        活动

        解析 / 决策
          `; const score = root.querySelector('[data-testid="score"]'); const schemeCount = root.querySelector('[data-testid="scheme-count"]'); const schemesEl = root.querySelector('[data-testid="schemes"]'); const feedButtons = root.querySelector('[data-testid="feed-buttons"]'); const currentVersion = root.querySelector('[data-testid="current-version"]'); const decisionState = root.querySelector('[data-testid="decision-state"]'); const decisionEl = root.querySelector('[data-testid="decision"]'); const promptActions = root.querySelector('[data-testid="prompt-actions"]'); const promptNote = root.querySelector('[data-testid="prompt-note"]'); const feedLabel = root.querySelector('[data-testid="feed-label"]'); const feedRaw = root.querySelector('[data-testid="feed-raw"]'); const eligibilityEl = root.querySelector('[data-testid="eligibility"]'); const checksEl = root.querySelector('[data-testid="checks"]'); const checkCount = root.querySelector('[data-testid="check-count"]'); const eventsEl = root.querySelector('[data-testid="events"]'); let state = null; let selectedFeed = "mac"; let prompt = "idle"; function feed() { return state?.feeds.find((row) => row.id === selectedFeed); } function renderSchemes() { if (!state) return; if (schemesEl) schemesEl.innerHTML = state.schemes.map(schemeRow).join(""); if (schemeCount) schemeCount.textContent = `${state.schemes.length} 类方案`; } function renderFeed() { if (!state) return; const row = feed(); if (feedButtons) { feedButtons.innerHTML = state.feeds .map((item) => feedButton(item, item.id === selectedFeed)) .join(""); for (const item of state.feeds) { root .querySelector(`[data-testid="feed-${item.id}"]`) ?.addEventListener("click", () => { selectedFeed = item.id; prompt = "idle"; renderFeed(); renderDecision(); }); } } if (currentVersion) currentVersion.textContent = state.currentVersion; if (feedLabel) feedLabel.textContent = row?.label ?? "—"; if (feedRaw) feedRaw.textContent = (row?.raw ?? "").slice(0, 520); if (decisionState) { decisionState.textContent = row?.decision.status ?? "—"; decisionState.className = `muted small status-${row?.decision.status ?? "none"}`; } } function renderDecision() { const row = feed(); if (!row) return; const decision = row.decision; if (decisionEl) { const tag = decision.status === "update" ? '有更新' : decision.status === "none" ? '已是最新' : 'feed 错误'; decisionEl.innerHTML = `
          ${tag} ${escapeHtml(decision.current)} → ${escapeHtml(decision.latest || "—")} ${escapeHtml(decision.reason)}

          ${escapeHtml(decision.notes || "无 release notes")}

          `; } if (promptActions) { promptActions.innerHTML = decision.status === "update" ? ` ` : ``; const later = root.querySelector('[data-testid="action-later"]'); const skip = root.querySelector('[data-testid="action-skip"]'); const download = root.querySelector('[data-testid="action-download"]'); const check = root.querySelector('[data-testid="action-check"]'); later?.addEventListener("click", () => { prompt = "deferred"; updatePromptNote(); }); skip?.addEventListener("click", () => { prompt = "skipped"; updatePromptNote(); }); download?.addEventListener("click", () => { prompt = "downloading"; updatePromptNote(); }); check?.addEventListener("click", () => { prompt = "idle"; updatePromptNote(); }); } updatePromptNote(); } function updatePromptNote() { if (!promptNote) return; const label = prompt === "deferred" ? "已推迟:下次启动再提示(仅 UI 状态)" : prompt === "skipped" ? "已忽略此版本:不再提示该版本(仅 UI 状态)" : prompt === "downloading" ? "模拟下载中:不会写入磁盘,也不会安装(仅 UI 状态)" : "提示状态只影响 UI,不会触发下载或安装。"; promptNote.textContent = label; promptNote.className = `muted small prompt-note ${prompt === "idle" ? "" : "active"}`; } function renderEligibility() { if (!eligibilityEl) return; const rows = [ ["公开 GitHub 仓库", true, "必需"], ["GitHub Releases", true, "必需"], ["macOS + 签名", true, "可用"], ["Windows", true, "可用"], ["Linux", false, "不支持"], ["私有仓库", false, "不支持"], ]; eligibilityEl.innerHTML = rows .map(([label, ok, note]) => `
        • ${ok ? "可" : "否"} ${escapeHtml(label)} ${escapeHtml(note)}
        • `) .join(""); } function renderChecks() { if (!state) return; if (checksEl) checksEl.innerHTML = state.checks.map(checkRow).join(""); if (checkCount) { const passed = state.checks.filter((check) => check.pass).length; checkCount.textContent = `${passed}/${state.checks.length} 通过`; } if (score) { score.textContent = `${state.score} / 100`; score.className = `pill ${state.score === 100 ? "ok-pill" : "bad-pill"}`; } } function renderEvents() { if (!eventsEl || !state) return; eventsEl.innerHTML = state.events.length === 0 ? `
        • 暂无活动
        • ` : state.events .slice(0, 8) .map((row) => `
        • ${time(row.at)} ${escapeHtml(row.kind)} ${escapeHtml(row.detail)}
        • `) .join(""); } function render(next) { state = next; renderSchemes(); renderFeed(); renderDecision(); renderEligibility(); renderChecks(); renderEvents(); } void window.api.updates.snapshot().then(render); window.api.updates.onEvent(() => { void window.api.updates.snapshot().then(render); }); root .querySelector('[data-testid="refresh"]') ?.addEventListener("click", async () => { render(await window.api.updates.refresh()); }); window.__prepareShots = async (stage) => { document.body.dataset.shot = stage; render(await window.api.updates.refresh()); if (stage === "available") { selectedFeed = "mac"; prompt = "idle"; renderFeed(); renderDecision(); document .querySelector(".decision-card") ?.scrollIntoView({ block: "start" }); } else if (stage === "limits") { selectedFeed = "invalid"; prompt = "idle"; renderFeed(); renderDecision(); document .querySelector(".eligibility-card") ?.scrollIntoView({ block: "start" }); } else { selectedFeed = "mac"; prompt = "idle"; renderFeed(); renderDecision(); document .querySelector(".schemes-card") ?.scrollIntoView({ block: "start" }); } }; window.__demo = async () => { const next = await window.api.updates.snapshot(); state = next; const find = (id) => next.feeds.find((row) => row.id === id); return { score: next.score, checks: next.checks.length, passed: next.checks.filter((check) => check.pass).length, schemes: next.schemes.length, feeds: next.feeds.length, macStatus: find("mac")?.decision.status ?? "", macLatest: find("mac")?.decision.latest ?? "", winStatus: find("win")?.decision.status ?? "", winLatest: find("win")?.decision.latest ?? "", noneStatus: find("none")?.decision.status ?? "", invalidStatus: find("invalid")?.decision.status ?? "", noInstall: next.checks.find((check) => check.id === "no-install")?.pass ?? false, }; }; } //# sourceMappingURL=App.js.map