function escape(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 });
}
const VIEW_META = [
{ id: "inbox", label: "收件箱", glyph: "I", hint: "消息与通知" },
{ id: "tasks", label: "任务", glyph: "T", hint: "后台任务" },
{ id: "settings", label: "设置", glyph: "S", hint: "系统集成" },
];
const INBOX = [
{
from: "构建机器人",
subject: "夜间构建 #482 已完成",
at: "09:41",
tag: "CI",
},
{ from: "Alice", subject: "请确认本周发布清单", at: "09:18", tag: "发布" },
{ from: "监控", subject: "API 延迟恢复正常", at: "08:52", tag: "告警" },
];
const TASKS = [
{ title: "打包 macOS 通用版", due: "今天 18:00", status: "进行中" },
{ title: "整理第五篇截图", due: "明天", status: "排队" },
{ title: "回归测试深链接", due: "周四", status: "排队" },
{ title: "更新发布说明", due: "周五", status: "待确认" },
];
const SETTINGS = [
{ key: "启动时隐藏窗口", value: "跟随 --hidden 参数" },
{ key: "通知", value: "系统通知 + 应用内活动" },
{ key: "更新通道", value: "stable" },
{ key: "工作区", value: "~/work/xwrt" },
];
export function mountApp(root) {
root.innerHTML = `
Deep Link
xwrt-hub://open?view=…&id=…
尚未打开链接
系统集成
第五篇能力汇总
—
`;
const countsEl = root.querySelector('[data-testid="counts"]');
const viewNav = root.querySelector('[data-testid="view-nav"]');
const viewPanel = root.querySelector('[data-testid="view-panel"]');
const activityEl = root.querySelector('[data-testid="activity"]');
const linkInput = root.querySelector('[data-testid="link-input"]');
const linkResult = root.querySelector('[data-testid="link-result"]');
const integrationEl = root.querySelector('[data-testid="integration"]');
const autoToggle = root.querySelector('[data-testid="auto-toggle"]');
const autoState = root.querySelector('[data-testid="auto-state"]');
const trayMenuEl = root.querySelector('[data-testid="tray-menu"]');
const residentPill = root.querySelector('[data-testid="resident-pill"]');
let state = null;
let autoDesired = false;
let autoInitialized = false;
function renderNav() {
if (!state || !viewNav)
return;
if (countsEl) {
countsEl.textContent = `${Object.values(state.counts).reduce((sum, n) => sum + n, 0)} 项`;
}
viewNav.innerHTML = VIEW_META.map((item) => `
`).join("");
}
function renderView() {
if (!state || !viewPanel)
return;
if (state.activeView === "inbox") {
viewPanel.innerHTML = `
收件箱
${INBOX.map((item) => `-
${item.from.slice(0, 1)}
${item.subject}${item.from} · ${item.at}
${item.tag}
`).join("")}
`;
}
else if (state.activeView === "tasks") {
viewPanel.innerHTML = `
任务
${TASKS.map((item) => `-
${item.title}截止 ${item.due}
${item.status}
`).join("")}
`;
}
else {
viewPanel.innerHTML = `
设置
${SETTINGS.map((item) => `-
${item.key}${item.value}
`).join("")}
`;
}
}
function renderLink() {
if (!state || !linkResult)
return;
const link = state.lastLink;
if (!link) {
linkResult.innerHTML = `尚未打开链接`;
return;
}
linkResult.innerHTML = `
${link.ok ? "OK" : link.reason}
${link.source} · ${time(link.at)}
${escape(link.raw)}
${link.ok ? `view=${link.view}${link.id ? ` · id=${link.id}` : ""}` : "链接被拒绝,窗口仍然打开以便修正"}
`;
}
function renderIntegration() {
if (!state || !integrationEl)
return;
const info = state.integration;
if (residentPill) {
residentPill.textContent = state.window.visible
? "窗口可见"
: "托盘驻留中";
residentPill.className = `pill ${state.window.visible ? "" : "warn"}`;
}
const rows = [
[
"托盘",
info.trayCreated ? `已创建 · ${info.trayMenuItems} 项` : "未创建",
info.trayCreated,
],
[
"全局快捷键",
`${info.shortcutAccelerator} · ${info.shortcutRegistered ? "已注册" : "冲突"}`,
info.shortcutRegistered,
],
[
"通知",
info.notificationSupported
? `支持 · ${info.lastNotification || "未发送"}`
: "不支持",
info.notificationSupported,
],
[
"单实例",
info.singleInstance ? "锁已获取" : "锁失败",
info.singleInstance,
],
[
"协议",
info.protocolRegistered ? "已注册 xwrt-hub" : "开发态模拟",
info.protocolRegistered,
],
[
"开机自启",
`${info.openAtLogin} · ${info.autostartStatus || "unknown"}`,
info.openAtLogin,
],
["打包", info.packaged ? "打包产物" : "开发态", info.packaged],
];
integrationEl.innerHTML = rows
.map(([label, value, ok]) => `
${label}
${escape(value)}
`)
.join("");
}
function renderTray() {
if (!state || !trayMenuEl)
return;
trayMenuEl.innerHTML = state.trayMenu
.map((item) => `
${item.type === "checkbox" ? (item.checked ? "✓" : "○") : ""}
${escape(item.label)}
${escape(item.id)}
`)
.join("");
}
function renderActivity() {
if (!state || !activityEl)
return;
activityEl.innerHTML =
state.activity.length === 0
? `暂无活动`
: state.activity
.slice(0, 7)
.map((row) => `
${time(row.at)}
${escape(row.kind)}
${escape(row.detail)}
`)
.join("");
}
function render(next) {
state = next;
if (!autoInitialized) {
autoInitialized = true;
autoDesired = next.integration.openAtLogin;
}
if (autoToggle)
autoToggle.checked = autoDesired;
if (autoState) {
autoState.textContent = `系统:openAtLogin=${next.integration.openAtLogin} · status=${next.integration.autostartStatus || "unknown"}`;
}
renderNav();
renderView();
renderLink();
renderIntegration();
renderTray();
renderActivity();
}
void window.api.hub.snapshot().then(render);
const unsubscribe = window.api.hub.onEvent(() => {
void window.api.hub.snapshot().then(render);
});
viewNav?.addEventListener("click", async (event) => {
const button = event.target.closest("[data-view]");
const view = button?.dataset.view;
if (view)
render(await window.api.hub.setView(view));
});
const openLink = async (source) => {
const url = linkInput?.value ?? "";
render(await window.api.hub.openLink(url, source));
};
root
.querySelector('[data-testid="open-link"]')
?.addEventListener("click", () => void openLink("manual"));
root
.querySelector('[data-testid="second-link"]')
?.addEventListener("click", () => void openLink("second-instance"));
const samples = {
inbox: "xwrt-hub://open?view=inbox",
tasks: "xwrt-hub://open?view=tasks&id=42",
"bad-view": "xwrt-hub://open?view=admin",
"bad-scheme": "https://example.com/open?view=tasks",
};
root
.querySelectorAll("[data-sample]")
.forEach((button) => {
button.addEventListener("click", async () => {
const key = button.dataset.sample ?? "";
if (linkInput)
linkInput.value = samples[key] ?? "";
render(await window.api.hub.openLink(samples[key] ?? "", "manual"));
});
});
root
.querySelector('[data-testid="hide"]')
?.addEventListener("click", async () => {
render(await window.api.hub.hide());
});
root
.querySelector('[data-testid="quit"]')
?.addEventListener("click", () => {
void window.api.hub.quit();
});
root
.querySelector('[data-testid="notify"]')
?.addEventListener("click", async () => {
render(await window.api.hub.notify("XWRT 指挥台", "任务 #42 已完成;点击回跳到任务列表"));
});
root
.querySelector('[data-testid="refresh"]')
?.addEventListener("click", async () => {
render(await window.api.hub.refresh());
});
autoToggle?.addEventListener("change", () => {
autoDesired = autoToggle.checked;
if (autoState) {
autoState.textContent = `待应用:openAtLogin=${autoDesired}(尚未写系统)`;
}
});
root
.querySelector('[data-testid="auto-preview"]')
?.addEventListener("click", async () => {
render(await window.api.hub.setAutostart(autoDesired, true));
});
root
.querySelector('[data-testid="auto-apply"]')
?.addEventListener("click", async () => {
render(await window.api.hub.setAutostart(autoDesired, false));
});
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
window.__prepareShots = async (stage) => {
document.body.dataset.shot = stage;
await window.api.hub.show();
await sleep(200);
if (stage === "hub") {
render(await window.api.hub.setView("inbox"));
return;
}
if (stage === "deeplink") {
if (linkInput)
linkInput.value = "xwrt-hub://open?view=tasks&id=42";
render(await window.api.hub.openLink("xwrt-hub://open?view=tasks&id=42", "second-instance"));
return;
}
if (linkInput)
linkInput.value = "xwrt-hub://open?view=inbox";
await window.api.hub.openLink("xwrt-hub://open?view=inbox", "manual");
render(await window.api.hub.setView("settings"));
};
window.__smoke = async () => {
const api = window.api.hub;
const first = await api.snapshot();
await api.setView("tasks");
const manual = await api.openLink("xwrt-hub://open?view=tasks&id=42", "manual");
const badScheme = await api.openLink("https://example.com/open?view=tasks", "manual");
const badView = await api.openLink("xwrt-hub://open?view=admin", "manual");
const second = await api.openLink("xwrt-hub://open?view=tasks&id=42", "second-instance");
await api.hide();
await sleep(120);
const hidden = await api.snapshot();
await api.show();
await sleep(120);
const shown = await api.snapshot();
await api.closeToTray();
await sleep(180);
const closed = await api.snapshot();
await api.show();
await sleep(120);
const restored = await api.snapshot();
const notified = await api.notify("XWRT 指挥台", "smoke 测试通知:任务 #42 已完成");
const beforeAuto = (await api.snapshot()).integration.openAtLogin;
const preview = await api.setAutostart(!beforeAuto, true);
const final = await api.refresh();
unsubscribe();
return {
platform: first.platform,
singleInstance: first.integration.singleInstance,
tray: first.integration.trayCreated,
trayItems: first.integration.trayMenuItems,
shortcut: first.integration.shortcutRegistered,
notificationSupported: first.integration.notificationSupported,
notification: notified.integration.lastNotification,
validView: manual.lastLink?.view ?? "",
validId: manual.lastLink?.id ?? "",
validSource: second.lastLink?.source ?? "",
badScheme: badScheme.lastLink?.reason ?? "",
badView: badView.lastLink?.reason ?? "",
hidden: !hidden.window.visible,
shown: shown.window.visible,
closedToTray: !closed.window.visible,
restored: restored.window.visible,
autostartBefore: beforeAuto,
autostartAfter: preview.integration.openAtLogin,
autostartUnchanged: beforeAuto === preview.integration.openAtLogin,
events: final.activity.length,
counts: Object.values(final.counts).reduce((sum, n) => sum + n, 0),
};
};
}
//# sourceMappingURL=App.js.map