import "./styles.css"; const state = { tab: "overview", info: null, }; const tabs = [ { id: "overview", label: "总览" }, { id: "processes", label: "进程" }, { id: "security", label: "安全边界" }, ]; function escapeHtml(value) { return value .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll('"', """); } function versionCard(label, value, testid) { return `
${escapeHtml(label)}
${escapeHtml(value)}
`; } function overview(info) { return `
${versionCard("Electron", info.electron, "info-electron")} ${versionCard("Node", info.node, "info-node")} ${versionCard("Chromium", info.chrome, "info-chrome")} ${versionCard("平台", `${info.platform} / ${info.arch}`, "info-platform")}

三层结构

主进程拥有 Node 与系统能力,创建窗口、调度 IPC
预加载脚本在隔离世界里执行,只暴露白名单 API
渲染进程每个窗口一个,跑 Chromium,负责界面
`; } function processes(info) { return `

真实进程

角色PID内存
主进程${info.mainPid}—
渲染进程${info.rendererPid}${info.memoryMB} MB

PID 来自 webContents.getOSProcessId() 与 process.pid,可在活动监视器里对照。

`; } function security() { const rows = [ ["contextIsolation", "true"], ["sandbox", "true"], ["nodeIntegration", "false"], ["webSecurity", "true"], ["webviewTag", "false"], ]; return `

webPreferences 默认值

${rows.map(([k, v]) => ``).join("")}
选项值
${k}${v}

渲染进程拿不到 require 与 ipcRenderer,只能调用 preload 暴露的白名单方法。

`; } function render() { const root = document.querySelector("#app"); if (!root) return; const info = state.info; const body = !info ? `

正在读取进程信息…

` : state.tab === "overview" ? overview(info) : state.tab === "processes" ? processes(info) : security(); root.innerHTML = `

Electron 是什么

桌面应用 = Chromium 渲染 + Node 运行时 + 主进程调度

${body}
`; for (const button of root.querySelectorAll("[data-tab]")) { button.addEventListener("click", () => { const tab = button.dataset.tab; if (tab === "overview" || tab === "processes" || tab === "security") { state.tab = tab; render(); } }); } } async function boot() { state.info = await window.api.info(); render(); window.__setTab = (tab) => { state.tab = tab; render(); }; window.__snapshot = () => ({ tab: state.tab, electron: state.info?.electron, rendererPid: state.info?.rendererPid, }); } void boot(); //# sourceMappingURL=renderer.js.map