An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover">
<style>
html {
overflow: hidden;
height: 100%;
}
body {
position: relative;
height: 100%;
margin: 0;
background: #1e1e1e;
font-size: 12px;
font-family: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", "Hiragino Sans GB", "Microsoft Yahei", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols";
}
#bootAppearance {
position: fixed;
z-index: 0;
inset: 0;
width: 100%;
height: 100%;
border: 0;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}
#bootAppearance.boot-appearance--loaded {
opacity: 1;
}
#bg {
position: relative;
z-index: 1;
width: 100%;
display: flex;
justify-content: space-around;
height: 100%;
pointer-events: none;
}
#bg svg {
width: 24vh;
height: 24vh;
align-self: center;
overflow: visible;
}
/* 斜向发光光带:内核进度到 15% 时由 .started 触发,从屏幕四周汇聚飞向 logo 区域,到位后淡出 */
#bg svg .streak {
opacity: 0;
transform-box: fill-box;
transform-origin: center;
}
#bg svg.started .streak {
animation: bootStreakConverge 1.6s cubic-bezier(0.33, 0, 0.2, 1) var(--delay, 0s) forwards,
bootStreakFade 0.5s ease 1.5s forwards;
}
@keyframes bootStreakConverge {
0% {
opacity: 0;
transform: translate(var(--dx, 0), var(--dy, 0));
}
20% {
opacity: 0.9;
}
100% {
opacity: 0.9;
transform: translate(0, 0);
}
}
@keyframes bootStreakFade {
to {
opacity: 0;
}
}
/* logo 碎片成型:光带汇聚末期柔和浮现,之后静止 */
#bg svg .logo path {
opacity: 0;
transform-box: fill-box;
transform-origin: center;
transform: scale(0.94);
}
#bg svg.started .logo path {
animation: bootLogoForm 0.75s cubic-bezier(0.22, 1, 0.36, 1) 1.25s forwards;
}
@keyframes bootLogoForm {
0% {
opacity: 0;
transform: scale(0.94);
}
100% {
opacity: 1;
transform: scale(1);
}
}
/* 倒下动画在光带汇聚后依次填充对应的折页区域。 */
#bg svg[data-boot-variant]:not([data-boot-variant="original"]) .logo path {
opacity: 1;
transform: none;
animation: none;
}
#bg svg[data-boot-variant]:not([data-boot-variant="original"]) .boot-reveal,
#bg svg[data-boot-variant]:not([data-boot-variant="original"]) .boot-reveal-base { opacity: 0; }
#bg svg[data-boot-variant]:not([data-boot-variant="original"]).started .streak {
animation: bootStreakConverge 1.35s cubic-bezier(.33, 0, .2, 1) var(--delay) forwards,
bootFall .4s cubic-bezier(.3, 0, .2, 1) var(--fall-delay) forwards;
}
#bg svg[data-boot-variant]:not([data-boot-variant="original"]).started .streaks > g:first-child {
animation: bootClipRed .01s 1.65s forwards;
}
#bg svg[data-boot-variant]:not([data-boot-variant="original"]).started .streaks > g:last-child {
animation: bootClipGray .01s 1.65s forwards;
}
#bg svg[data-boot-variant]:not([data-boot-variant="original"]).started .boot-reveal {
animation: bootReveal .3s ease-out var(--reveal-delay) forwards;
}
#bg svg[data-boot-variant]:not([data-boot-variant="original"]).started .boot-reveal-base {
animation: bootReveal .3s ease-in-out 2.2s forwards;
}
@keyframes bootClipRed { to { clip-path: url(#boot-logo-red); } }
@keyframes bootClipGray { to { clip-path: url(#boot-logo-gray); } }
@keyframes bootReveal { to { opacity: 1; } }
@keyframes bootFall {
0% { transform: rotate(0deg) translate(0, 0); opacity: .9; }
65% { transform: rotate(var(--fall-mid)) scaleX(1.6); opacity: .8; stroke-width: 20; }
100% { transform: rotate(var(--fall-end)) scaleX(2); opacity: 0; stroke-width: 28; }
}
@keyframes bootSwirl {
0% { opacity: 0; transform: rotate(180deg) translate(var(--dx, 0), var(--dy, 0)); }
20% { opacity: .9; }
100% { opacity: .9; transform: rotate(0deg) translate(0, 0); }
}
#bg svg[data-boot-variant]:not([data-boot-variant="original"]).started .streak {
animation-name: bootSwirl, bootFall;
}
/* 底部进度区,预留安全区域防止移动端手势条遮挡 */
#progressWrap {
position: absolute;
z-index: 2;
bottom: env(safe-area-inset-bottom);
width: 100%;
padding-bottom: env(safe-area-inset-bottom);
}
#progressTrack {
position: absolute;
height: 2px;
background-color: #2a2c2f;
width: 100%;
top: 0;
}
#progress {
position: absolute;
height: 2px;
background-color: #3b3e43;
box-shadow: 0 0 8px rgba(59, 62, 67, 0.6);
transition: width 0.6s cubic-bezier(0, 0, 0.2, 1);
top: 0;
width: 0;
}
#details {
color: #9aa0a6;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
padding: 8px;
height: 16px;
line-height: 16px;
}
</style>
</head>
<body>
<iframe id="bootAppearance" sandbox="" allow="autoplay" tabindex="-1" aria-hidden="true"></iframe>
<div id="bg">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
<g class="streaks"></g>
<g class="logo">
<path fill="#d23f31" d="M37.052 371.676l269.857-269.857v550.507l-269.857 269.857z"></path>
<path fill="#3b3e43" d="M306.909 101.818l205.091 205.091v550.507l-205.091-205.091z"></path>
<path fill="#d23f31" d="M512 306.909l205.091-205.091v550.507l-205.091 205.091z"></path>
<path fill="#3b3e43" d="M717.091 101.818l269.857 269.857v550.507l-269.857-269.857z"></path>
</g>
</svg>
</div>
<div id="progressWrap">
<div id="progressTrack"></div>
<div id="progress"></div>
<div id="details" role="status" aria-live="polite"></div>
</div>
<script>
// 每次启动选取一种动画;初始化后不会随进度消息改变。
const bootVariant = ["original", "left", "inward", "right"][Math.floor(Math.random() * 4)];
const bootAnimationDuration = bootVariant === "original" ? 2000 : 2500;
const setupBootVariant = (svg) => {
svg.dataset.bootVariant = bootVariant;
if (bootVariant === "original") return;
const ns = "http://www.w3.org/2000/svg";
const streaks = svg.querySelector(".streaks");
const lines = Array.from(streaks.querySelectorAll(".streak"));
const paths = Array.from(svg.querySelectorAll(".logo path"));
const defs = document.createElementNS(ns, "defs");
const gradient = document.createElementNS(ns, "radialGradient");
gradient.id = "boot-fragment-gradient";
[["0%", "1"], ["65%", "1"], ["100%", "0"]].forEach(([offset, opacity]) => {
const stop = document.createElementNS(ns, "stop");
stop.setAttribute("offset", offset);
stop.setAttribute("stop-color", "white");
stop.setAttribute("stop-opacity", opacity);
gradient.appendChild(stop);
});
defs.appendChild(gradient);
const redClip = document.createElementNS(ns, "clipPath");
const grayClip = document.createElementNS(ns, "clipPath");
redClip.id = "boot-logo-red";
grayClip.id = "boot-logo-gray";
paths.forEach((path, index) => (index % 2 ? grayClip : redClip).appendChild(path.cloneNode()));
defs.append(redClip, grayClip);
const mask = document.createElementNS(ns, "mask");
mask.id = "boot-fragment-mask";
mask.setAttribute("maskUnits", "userSpaceOnUse");
mask.setAttribute("x", "0"); mask.setAttribute("y", "0");
mask.setAttribute("width", "1024"); mask.setAttribute("height", "1024");
const base = document.createElementNS(ns, "rect");
base.setAttribute("width", "1024"); base.setAttribute("height", "1024");
base.setAttribute("fill", "white"); base.setAttribute("class", "boot-reveal-base");
mask.appendChild(base);
const redGroup = document.createElementNS(ns, "g");
const grayGroup = document.createElementNS(ns, "g");
redGroup.style.filter = "drop-shadow(0 0 4px rgba(210,63,49,.5))";
grayGroup.style.filter = "drop-shadow(0 0 4px rgba(130,135,143,.35))";
streaks.append(redGroup, grayGroup);
const edges = [
[37, 372, 307, 102], [37, 922, 307, 652], [307, 102, 512, 307], [307, 652, 512, 857],
[512, 307, 717, 102], [512, 857, 717, 652], [717, 102, 987, 372], [717, 652, 987, 922],
];
lines.forEach((line, index) => {
const edgeIndex = Math.floor(index / 16);
const i = index % 16;
const edge = edges[edgeIndex];
const t = (Math.floor(i / 4) + .5) / 4;
const x = edge[0] + (edge[2] - edge[0]) * t;
const y = edge[1] + (edge[3] - edge[1]) * t + (edgeIndex % 2 ? -1 : 1) * 550 * ((i % 4 + .5) / 8);
const position = bootVariant === "inward" ? Math.min(x, 1024 - x) / 512 : bootVariant === "right" ? (1024 - x) / 1024 : x / 1024;
const angle = bootVariant === "inward" ? (x < 512 ? 1 : -1) : bootVariant === "right" ? -1 : 1;
const delay = 1.65 + position * .45;
line.setAttribute("x1", String(x)); line.setAttribute("x2", String(x));
line.setAttribute("y1", String(y - 52)); line.setAttribute("y2", String(y));
line.style.filter = "";
line.style.setProperty("--delay", (Math.random() * .3) + "s");
line.style.setProperty("--fall-delay", delay + "s");
line.style.setProperty("--fall-mid", angle * 70 + "deg");
line.style.setProperty("--fall-end", angle * 90 + "deg");
(edgeIndex < 2 || edgeIndex >= 4 && edgeIndex < 6 ? redGroup : grayGroup).appendChild(line);
const spot = document.createElementNS(ns, "circle");
spot.setAttribute("cx", String(x)); spot.setAttribute("cy", String(y));
spot.setAttribute("r", "95"); spot.setAttribute("fill", "url(#boot-fragment-gradient)");
spot.setAttribute("class", "boot-reveal");
spot.style.setProperty("--reveal-delay", (delay + .1) + "s");
mask.appendChild(spot);
});
defs.appendChild(mask);
svg.prepend(defs);
paths.forEach(path => path.setAttribute("mask", "url(#boot-fragment-mask)"));
svg.appendChild(streaks);
};
const getSearch = (key) => {
return new URLSearchParams(window.location.search).get(key) || ''
}
const escapeBootAppearanceHTML = (value) => String(value).replace(/[&<>"']/g, (character) => ({
"&": "&",
"<": "<",
">": ">",
"\"": """,
"'": "'",
})[character]);
const getBootAppearanceColor = (value, fallback) => {
if (typeof value === "string" && /^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(value)) {
return value;
}
return fallback;
};
const getBootAppearanceResourceURL = (value, serverURL, resourceRootPath) => {
if (typeof value !== "string" || value === "") {
return "";
}
try {
const url = new URL(value, serverURL + "/");
if (url.origin !== serverURL || !url.pathname.startsWith(resourceRootPath)) {
return "";
}
return url.href;
} catch (error) {
return "";
}
};
const bootAppearancePreloadTimeout = 5000;
const preloadBootAppearanceImage = (url) => new Promise((resolve) => {
const image = new Image();
let settled = false;
const finish = (valid) => {
if (settled) {
return;
}
settled = true;
clearTimeout(timeout);
image.onload = null;
image.onerror = null;
image.removeAttribute("src");
resolve(valid);
};
const timeout = setTimeout(() => finish(false), bootAppearancePreloadTimeout);
image.decoding = "async";
image.onload = () => {
if (image.naturalWidth < 1 || image.naturalHeight < 1) {
finish(false);
return;
}
if (typeof image.decode !== "function") {
finish(true);
return;
}
image.decode().then(() => finish(true)).catch(() => finish(false));
};
image.onerror = () => finish(false);
image.src = url;
});
const preloadBootAppearanceVideo = (url) => new Promise((resolve) => {
const video = document.createElement("video");
let settled = false;
const finish = (valid) => {
if (settled) {
return;
}
settled = true;
clearTimeout(timeout);
video.onloadeddata = null;
video.onerror = null;
video.pause();
video.removeAttribute("src");
video.load();
video.remove();
resolve(valid);
};
const timeout = setTimeout(() => finish(false), bootAppearancePreloadTimeout);
video.preload = "auto";
video.muted = true;
video.defaultMuted = true;
video.playsInline = true;
video.setAttribute("playsinline", "");
video.style.cssText = "position:fixed;left:-9999px;width:1px;height:1px;opacity:0;pointer-events:none";
video.onloadeddata = () => finish(video.readyState >= 2 && video.videoWidth > 0 && video.videoHeight > 0);
video.onerror = () => finish(false);
document.body.appendChild(video);
video.src = url;
video.load();
});
const preloadBootAppearanceStyle = async (url) => {
if (!url) {
return true;
}
const abortController = new AbortController();
const timeout = setTimeout(() => abortController.abort(), bootAppearancePreloadTimeout);
try {
const response = await fetch(url, {cache: "no-store", signal: abortController.signal});
if (!response.ok) {
return false;
}
await response.text();
return true;
} catch (error) {
return false;
} finally {
clearTimeout(timeout);
}
};
const validateBootAppearanceResources = async (styleURL, imageURLs, videoURLs) => {
const validations = [preloadBootAppearanceStyle(styleURL)];
imageURLs.forEach((url) => validations.push(preloadBootAppearanceImage(url)));
videoURLs.forEach((url) => validations.push(preloadBootAppearanceVideo(url)));
const results = await Promise.all(validations);
return results.every((valid) => valid);
};
const applyBootAppearanceOfficialUI = (officialUI) => {
const logoEl = document.querySelector("#bg svg");
const detailsEl = document.getElementById("details");
const progressEl = document.getElementById("progress");
const progressTrackEl = document.getElementById("progressTrack");
if (logoEl) {
logoEl.style.display = officialUI?.showLogo === false ? "none" : "";
}
detailsEl.style.display = officialUI?.showDetails === false ? "none" : "";
detailsEl.style.color = getBootAppearanceColor(officialUI?.textColor, "#9aa0a6");
const progressColor = getBootAppearanceColor(officialUI?.progressColor, "#3b3e43");
progressEl.style.backgroundColor = progressColor;
progressEl.style.boxShadow = "0 0 8px " + progressColor;
progressTrackEl.style.backgroundColor = getBootAppearanceColor(officialUI?.trackColor, "#2a2c2f");
};
let bootAppearanceRequestID = 0;
const loadBootAppearance = (port, frontend) => {
const remoteOrigin = getSearch("remote");
if (remoteOrigin || getSearch("appearance") === "0" || getSearch("safe") === "1") {
return;
}
const normalizedPort = String(port);
if (!/^\d{1,5}$/.test(normalizedPort) || Number(normalizedPort) < 1 || Number(normalizedPort) > 65535) {
return;
}
const requestID = ++bootAppearanceRequestID;
const serverURL = "http://127.0.0.1:" + normalizedPort;
const request = async () => {
if (requestID !== bootAppearanceRequestID) {
return;
}
try {
const response = await fetch(serverURL + "/api/system/getBootAppearance", {cache: "no-store"});
if (!response.ok) {
if (response.status >= 500 && requestID === bootAppearanceRequestID) {
setTimeout(request, 100);
}
return;
}
const result = await response.json();
const appearance = result?.code === 0 ? result.data : undefined;
if (requestID !== bootAppearanceRequestID || !appearance?.enabled) {
return;
}
if (Array.isArray(appearance.frontends) && !appearance.frontends.includes(frontend)) {
return;
}
if (typeof appearance.provider !== "string" || typeof appearance.appearance !== "string") {
return;
}
const resourceRootPath = "/boot-appearance-assets/" + encodeURIComponent(appearance.provider) + "/" +
encodeURIComponent(appearance.appearance) + "/";
const resourceRootURL = serverURL + resourceRootPath;
const layerPositions = new Map([
["center", "center"],
["top", "center top"],
["right", "right center"],
["bottom", "center bottom"],
["left", "left center"],
["top-left", "left top"],
["top-right", "right top"],
["bottom-right", "right bottom"],
["bottom-left", "left bottom"],
]);
const layerFits = new Set(["contain", "cover", "fill", "none", "scale-down"]);
const layers = [];
const imageURLs = new Set();
const videoURLs = new Set();
let layersValid = true;
if (Array.isArray(appearance.layers)) {
appearance.layers.forEach((layer) => {
if (!layer || typeof layer.id !== "string" || layer.id.length > 64 ||
!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(layer.id)) {
layersValid = false;
return;
}
const src = getBootAppearanceResourceURL(layer.src, serverURL, resourceRootPath);
if (!src) {
layersValid = false;
return;
}
const fit = layerFits.has(layer.fit) ? layer.fit : "cover";
const position = layerPositions.get(layer.position) || "center";
const attributes = "class=\"boot-appearance__layer\" data-layer=\"" +
escapeBootAppearanceHTML(layer.id) + "\" style=\"object-fit: " + fit +
"; object-position: " + position + ";\"";
if (layer.type === "image") {
imageURLs.add(src);
layers.push("<img " + attributes + " src=\"" + escapeBootAppearanceHTML(src) +
"\" alt=\"\" draggable=\"false\">");
} else if (layer.type === "video") {
const poster = getBootAppearanceResourceURL(layer.poster, serverURL, resourceRootPath);
if (!poster) {
layersValid = false;
return;
}
imageURLs.add(poster);
videoURLs.add(src);
layers.push("<video " + attributes + " src=\"" + escapeBootAppearanceHTML(src) +
"\" poster=\"" + escapeBootAppearanceHTML(poster) +
"\" autoplay muted loop playsinline preload=\"auto\" disablepictureinpicture></video>");
} else {
layersValid = false;
}
});
}
const styleURL = getBootAppearanceResourceURL(appearance.style, serverURL, resourceRootPath);
if (!layersValid || (appearance.style && !styleURL)) {
return;
}
if (!await validateBootAppearanceResources(styleURL, imageURLs, videoURLs) ||
requestID !== bootAppearanceRequestID) {
return;
}
const backgroundColor = getBootAppearanceColor(appearance.backgroundColor, "#1e1e1e");
const escapedResourceRootURL = escapeBootAppearanceHTML(resourceRootURL);
const contentSecurityPolicy = "default-src 'none'; style-src 'unsafe-inline' " +
escapedResourceRootURL + "; img-src " + escapedResourceRootURL + "; media-src " +
escapedResourceRootURL + "; font-src 'none'; connect-src 'none'; frame-src 'none'; " +
"object-src 'none'; base-uri 'none'; form-action 'none'";
const styleLink = styleURL ? "<link rel=\"stylesheet\" href=\"" +
escapeBootAppearanceHTML(styleURL) + "\">" : "";
const iframeEl = document.getElementById("bootAppearance");
iframeEl.classList.remove("boot-appearance--loaded");
iframeEl.onload = () => {
if (requestID !== bootAppearanceRequestID) {
return;
}
applyBootAppearanceOfficialUI(appearance.officialUI);
iframeEl.classList.add("boot-appearance--loaded");
};
iframeEl.srcdoc = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\">" +
"<meta http-equiv=\"Content-Security-Policy\" content=\"" + contentSecurityPolicy + "\">" +
"<style>html,body{width:100%;height:100%;margin:0;overflow:hidden;background:" +
backgroundColor + ";}.boot-appearance__layer{position:absolute;inset:0;width:100%;height:100%;" +
"border:0;user-select:none;}</style>" + styleLink + "</head><body>" + layers.join("") +
"</body></html>";
} catch (error) {
// Electron 启动页可能早于内核 HTTP 服务加载,失败后短延迟重试且不阻塞启动进度。
if (requestID === bootAppearanceRequestID) {
setTimeout(request, 100);
}
}
};
request();
};
(async () => {
const v = getSearch('v')
const port = getSearch('port') || '6806'
const remoteOrigin = getSearch('remote')
const serverURL = remoteOrigin || 'http://127.0.0.1:' + port
const progressEl = document.getElementById('progress')
const detailsEl = document.getElementById('details')
const bootDetails = "v" + v + (remoteOrigin ? " Connecting to remote kernel..." : " Booting kernel...");
let previousExitWaiting = getSearch("previousExitWaiting");
detailsEl.textContent = previousExitWaiting || bootDetails;
if (!previousExitWaiting) {
loadBootAppearance(port, "desktop");
}
// 随机起始基数(15~25),等待内核进度时先平滑填充到此值
const baseProgress = 15 + Math.random() * 10
// 生成斜向发光光带,沿 logo 折页的斜边排布,汇聚到位时勾勒出 logo 形状
const streaksG = document.querySelector("#bg svg .streaks");
if (streaksG) {
const svgNS = "http://www.w3.org/2000/svg";
const edges = [
{x1: 37, y1: 372, x2: 307, y2: 102, color: "#d23f31"},
{x1: 37, y1: 922, x2: 307, y2: 652, color: "#d23f31"},
{x1: 307, y1: 102, x2: 512, y2: 307, color: "#3b3e43"},
{x1: 307, y1: 652, x2: 512, y2: 857, color: "#3b3e43"},
{x1: 512, y1: 307, x2: 717, y2: 102, color: "#d23f31"},
{x1: 512, y1: 857, x2: 717, y2: 652, color: "#d23f31"},
{x1: 717, y1: 102, x2: 987, y2: 372, color: "#3b3e43"},
{x1: 717, y1: 652, x2: 987, y2: 922, color: "#3b3e43"},
];
const perEdge = 16;
edges.forEach((e) => {
for (let i = 0; i < perEdge; i++) {
const t = (i + 0.5) / perEdge + (Math.random() - 0.5) * 0.08;
const ex = e.x1 + (e.x2 - e.x1) * t;
const ey = e.y1 + (e.y2 - e.y1) * t;
const len = 60 + Math.random() * 80;
const ux = (e.x2 - e.x1);
const uy = (e.y2 - e.y1);
const ul = Math.sqrt(ux * ux + uy * uy);
const sx = ex - ux / ul * len;
const sy = ey - uy / ul * len;
const line = document.createElementNS(svgNS, "line");
line.setAttribute("x1", sx);
line.setAttribute("y1", sy);
line.setAttribute("x2", ex);
line.setAttribute("y2", ey);
line.setAttribute("stroke", e.color);
line.setAttribute("stroke-width", 3 + Math.random() * 3);
line.setAttribute("stroke-linecap", "round");
line.setAttribute("class", "streak");
line.style.filter = "drop-shadow(0 0 4px rgba(210,63,49,.5))";
const angle = Math.random() * Math.PI * 2;
const dist = 600 + Math.random() * 800;
line.style.setProperty("--dx", Math.cos(angle) * dist + "px");
line.style.setProperty("--dy", Math.sin(angle) * dist + "px");
line.style.setProperty("--delay", (Math.random() * 0.4) + "s");
streaksG.appendChild(line);
}
});
}
setupBootVariant(document.querySelector("#bg svg"));
// 当前进度只增不减,避免内核首帧进度小于初始基数时进度条倒退回 0
let currentDisplay = 0
const bgSvg = document.querySelector("#bg svg")
let animStart = 0
const setProgress = (target) => {
if (target > currentDisplay) {
currentDisplay = target
progressEl.style.width = target + '%'
// 显示进度达到 15% 时触发 logo 汇聚动画
if (bgSvg && !bgSvg.classList.contains("started") && currentDisplay >= 15) {
bgSvg.classList.add("started")
animStart = Date.now()
}
}
}
// 先平滑填充到随机基数,延迟两帧确保浏览器先渲染 width:0 再触发过渡
requestAnimationFrame(() => {
requestAnimationFrame(() => {
setProgress(baseProgress)
})
})
let progressing = false
let progressSource;
let progressRetry;
const subscribe = () => {
if (previousExitWaiting || remoteOrigin || progressing) {
return;
}
const es = new EventSource(serverURL + '/api/system/bootProgressSSE')
progressSource = es;
es.onmessage = (event) => {
if (previousExitWaiting || progressSource !== es) {
return;
}
const progressData = JSON.parse(event.data)
// 内核进度按比例映射到 baseProgress~100 区间,从当前显示值继续递增
const display = baseProgress + progressData.progress * (100 - baseProgress) / 100
setProgress(display)
detailsEl.textContent = progressData.details
if (progressData.progress >= 100) {
progressing = true
es.close()
// 内核完成后尽快结束动画,把剩余动画快进到终态
if (animStart > 0) {
const animTotalMs = bootAnimationDuration
const elapsed = Date.now() - animStart
const remaining = animTotalMs - elapsed
if (remaining > 0) {
// 用极短的收尾时间(200ms)让动画快进到终态
const rate = remaining / 200
bgSvg.getAnimations({subtree: true}).forEach((a) => { a.playbackRate = rate })
}
}
}
}
es.onerror = () => {
es.close()
// 内核启动早期 HTTP 服务可能尚未就绪,EventSource 原生重连间隔较长(约 3s),
// 这里主动短延迟重连,保持与原轮询一致的快速重试语义
if (!progressing && !previousExitWaiting && progressSource === es) {
progressRetry = setTimeout(subscribe, 100);
}
}
}
// 等待上次退出时保留启动页和动画,暂停依赖新内核的请求,结束后在原页继续启动。
window.setPreviousExitWaiting = (message) => {
previousExitWaiting = message;
detailsEl.textContent = message || bootDetails;
clearTimeout(progressRetry);
progressSource?.close();
progressSource = undefined;
bootAppearanceRequestID++;
if (!message) {
loadBootAppearance(port, "desktop");
subscribe();
}
};
if (!remoteOrigin) {
subscribe()
}
})()
</script>
<script src="connectionEntry.js"></script>
</body>
</html>