@michengai/dsh-codex-ui 2.0.11 → 2.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -69,13 +69,16 @@ window.__ModuleLoader__.load({
69
69
  //#endregion
70
70
  //#region src/business-api.ts
71
71
  const CODEX_UI_API_BASE = "/api/michengai/dsh-codex-ui";
72
+ /** 请求重启时携带一次性令牌的请求头(客户端与 Host 共用)。 */
73
+ const CODEX_UI_RESTART_HEADER = "x-dcu-restart-key";
72
74
  const CODEX_UI_API_ENDPOINTS = Object.freeze({
73
75
  dependencies: `${CODEX_UI_API_BASE}/dependencies`,
74
76
  settingsSkin: `${CODEX_UI_API_BASE}/settings-skin`,
75
77
  composer: `${CODEX_UI_API_BASE}/composer`,
76
78
  sidebar: `${CODEX_UI_API_BASE}/sidebar`,
77
79
  sections: `${CODEX_UI_API_BASE}/sections`,
78
- theme: `${CODEX_UI_API_BASE}/theme`
80
+ theme: `${CODEX_UI_API_BASE}/theme`,
81
+ desktopMenu: `${CODEX_UI_API_BASE}/desktop-menu`
79
82
  });
80
83
  //#endregion
81
84
  //#region src/dependencies.ts
@@ -2575,6 +2578,11 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card {
2575
2578
  nameKey: "about.feature.theme.name",
2576
2579
  descKey: "about.feature.theme"
2577
2580
  },
2581
+ {
2582
+ id: "desktop-menu",
2583
+ nameKey: "about.feature.desktopMenu.name",
2584
+ descKey: "about.feature.desktopMenu"
2585
+ },
2578
2586
  {
2579
2587
  id: "dependencies",
2580
2588
  nameKey: "about.feature.dependencies.name",
@@ -3115,7 +3123,7 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3115
3123
  "about.feedback": "问题反馈",
3116
3124
  "about.checkUpdate": "检查更新",
3117
3125
  "about.checking": "正在检查更新…",
3118
- "about.description": "输入框增强、全屏设置工作台美化与生态插件管理。",
3126
+ "about.description": "输入框增强、全屏设置工作台美化、桌面窗口菜单与生态插件管理。",
3119
3127
  "about.features": "包含子插件与功能",
3120
3128
  "about.feature.composer.name": "输入框增强 (Composer)",
3121
3129
  "about.feature.composer": "终端风格输入历史(↑/↓)快捷召回、自适应宽度调节与会话建议卡片",
@@ -3129,6 +3137,23 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3129
3137
  "about.feature.theme": "内置 Codex 经典黑白与 Catppuccin 色盘,支持悬浮云母磨砂质感",
3130
3138
  "about.feature.dependencies.name": "配套生态管理 (Dependencies)",
3131
3139
  "about.feature.dependencies": "深度集成 DSH 官方与第三方生态插件集中管理与一键批量更新",
3140
+ "about.feature.desktopMenu.name": "桌面窗口菜单 (Desktop Menus)",
3141
+ "about.feature.desktopMenu": "在系统原生菜单栏追加帮助入口,并提供页面刷新与重启",
3142
+ "desktopMenu.help": "帮助",
3143
+ "desktopMenu.help.reloadPage": "刷新页面",
3144
+ "desktopMenu.help.restartAppHost": "重启应用与 Host",
3145
+ "desktopMenu.help.restartConfirm": "将退出并重新打开 DeepSeek Harness,正在运行的任务会被中断。继续?",
3146
+ "desktopMenu.restart.quitting": "正在退出并重新打开 DeepSeek Harness…",
3147
+ "desktopMenu.restart.relaunched": "已重新启动。",
3148
+ "desktopMenu.restart.cancelled": "应用没有退出,本次重启已取消。",
3149
+ "desktopMenu.restart.launchFailed": "应用已退出,但没能自动重新打开,请手动启动。",
3150
+ "desktopMenu.restart.timeout": "没有在预期时间内完成重启,请确认应用是否还在。",
3151
+ "desktopMenu.restart.busy": "已有重启正在进行中,请稍候。",
3152
+ "desktopMenu.restart.failed": "重启失败",
3153
+ "desktopMenu.restart.unreachable": "连不上宿主,重启通道不可用。",
3154
+ "desktopMenu.restart.unsupportedDesktopOnly": "当前不是桌面版,无法重启应用。",
3155
+ "desktopMenu.restart.unsupportedMissingApp": "找不到 DeepSeek Harness 的可执行文件,无法重启。",
3156
+ "desktopMenu.restart.close": "关闭",
3132
3157
  "about.dependencies": "配套管理插件",
3133
3158
  "about.dependenciesDescription": "每个配套插件均支持独立按需安装与一键批量同步升级。",
3134
3159
  "about.loading": "正在读取依赖安装状态…",
@@ -3284,7 +3309,7 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3284
3309
  "about.feedback": "Issues",
3285
3310
  "about.checkUpdate": "Check for updates",
3286
3311
  "about.checking": "Checking…",
3287
- "about.description": "Input enhancement, fullscreen settings workbench skin, and ecosystem plugin management.",
3312
+ "about.description": "Input enhancement, fullscreen settings workbench skin, desktop titlebar menu, and ecosystem plugin management.",
3288
3313
  "about.features": "Built-in Sub-plugins & Capabilities",
3289
3314
  "about.feature.composer.name": "Composer Enhancements",
3290
3315
  "about.feature.composer": "Terminal-style input history (↑/↓), adaptive width resizing, and starter suggestions",
@@ -3298,6 +3323,23 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3298
3323
  "about.feature.theme": "Built-in Codex dark/light & Catppuccin palettes with floating mica glassmorphism",
3299
3324
  "about.feature.dependencies.name": "Companion Dependencies",
3300
3325
  "about.feature.dependencies": "Integrated management, live healthcheck, and one-click updates for DSH plugins",
3326
+ "about.feature.desktopMenu.name": "Desktop Window Menus",
3327
+ "about.feature.desktopMenu": "Adds a Help entry to the native menubar with page reload and restart",
3328
+ "desktopMenu.help": "Help",
3329
+ "desktopMenu.help.reloadPage": "Reload Page",
3330
+ "desktopMenu.help.restartAppHost": "Restart App and Host",
3331
+ "desktopMenu.help.restartConfirm": "DeepSeek Harness will close and reopen; running tasks will be interrupted. Continue?",
3332
+ "desktopMenu.restart.quitting": "Closing and reopening DeepSeek Harness…",
3333
+ "desktopMenu.restart.relaunched": "Restarted.",
3334
+ "desktopMenu.restart.cancelled": "The app did not exit; this restart was cancelled.",
3335
+ "desktopMenu.restart.launchFailed": "The app exited but could not be reopened automatically.",
3336
+ "desktopMenu.restart.timeout": "The restart did not finish in time; please check the app.",
3337
+ "desktopMenu.restart.busy": "A restart is already in progress. Please wait.",
3338
+ "desktopMenu.restart.failed": "Restart failed",
3339
+ "desktopMenu.restart.unreachable": "Cannot reach the Host; the restart channel is unavailable.",
3340
+ "desktopMenu.restart.unsupportedDesktopOnly": "This is not the desktop app, so it cannot be restarted.",
3341
+ "desktopMenu.restart.unsupportedMissingApp": "Cannot locate the DeepSeek Harness executable, so it cannot be restarted.",
3342
+ "desktopMenu.restart.close": "Close",
3301
3343
  "about.dependencies": "Companion management plugins",
3302
3344
  "about.dependenciesDescription": "Install or update each companion plugin individually, or synchronize all versions in one click.",
3303
3345
  "about.loading": "Loading dependency status…",
@@ -5757,7 +5799,7 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
5757
5799
  */
5758
5800
  const CODEX_UI_NAV_MARKER = "data-dcu-nav-icon";
5759
5801
  const NAV_ROW_SELECTOR = "[role=\"dialog\"] nav button, [data-shortcut-modal=\"settings\"] nav button";
5760
- const STYLE_ID$1 = "dcu-settings-nav-icon-style";
5802
+ const STYLE_ID$3 = "dcu-settings-nav-icon-style";
5761
5803
  const ICON_MASK_URL = `url("data:image/svg+xml,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\"><rect x=\"1.5\" y=\"2\" width=\"13\" height=\"12\" rx=\"2\" stroke=\"black\" stroke-width=\"1.3\" fill=\"none\"/><line x1=\"5.5\" y1=\"2\" x2=\"5.5\" y2=\"14\" stroke=\"black\" stroke-width=\"1.3\"/><line x1=\"5.5\" y1=\"5.5\" x2=\"14.5\" y2=\"5.5\" stroke=\"black\" stroke-width=\"1.3\"/></svg>")}")`;
5762
5804
  const NAV_ICON_CSS = `
5763
5805
  [${CODEX_UI_NAV_MARKER}="codex-ui"] > svg { display: none !important; }
@@ -5778,9 +5820,9 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
5778
5820
  }
5779
5821
  `;
5780
5822
  function ensureStyle(doc) {
5781
- if (doc.getElementById(STYLE_ID$1) !== null) return;
5823
+ if (doc.getElementById(STYLE_ID$3) !== null) return;
5782
5824
  const style = doc.createElement("style");
5783
- style.id = STYLE_ID$1;
5825
+ style.id = STYLE_ID$3;
5784
5826
  style.textContent = NAV_ICON_CSS;
5785
5827
  (doc.head ?? doc.documentElement).appendChild(style);
5786
5828
  }
@@ -5828,7 +5870,7 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
5828
5870
  doc.querySelectorAll(`[${CODEX_UI_NAV_MARKER}="codex-ui"]`).forEach((btn) => {
5829
5871
  btn.removeAttribute(CODEX_UI_NAV_MARKER);
5830
5872
  });
5831
- doc.getElementById(STYLE_ID$1)?.remove();
5873
+ doc.getElementById(STYLE_ID$3)?.remove();
5832
5874
  };
5833
5875
  }
5834
5876
  //#endregion
@@ -8193,7 +8235,7 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
8193
8235
  /** 追加在项目行菜单里的入口标记。 */
8194
8236
  const MENU_ITEM_ATTR = "data-dcu-ws-section-item";
8195
8237
  const HEADER_CLASS = "dcu-ws-section";
8196
- const STYLE_ID = "michengai-codex-ui-sections-styles";
8238
+ const STYLE_ID$2 = "michengai-codex-ui-sections-styles";
8197
8239
  /** 各分区的折叠状态(与本文件的分区数据分键存放)。 */
8198
8240
  const COLLAPSED_STORAGE_KEY = "michengai.codex-ui.workspace-sections-collapsed.v1";
8199
8241
  /**
@@ -8239,9 +8281,9 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
8239
8281
  `;
8240
8282
  /** 注入分区样式;已存在时复用(样式与组件生命周期解耦,卸载不摘除)。 */
8241
8283
  function injectStyles() {
8242
- if (document.getElementById(STYLE_ID) !== null) return;
8284
+ if (document.getElementById(STYLE_ID$2) !== null) return;
8243
8285
  const style = document.createElement("style");
8244
- style.id = STYLE_ID;
8286
+ style.id = STYLE_ID$2;
8245
8287
  style.textContent = SECTIONS_CSS;
8246
8288
  document.head.appendChild(style);
8247
8289
  }
@@ -9538,6 +9580,572 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
9538
9580
  return dispose;
9539
9581
  }
9540
9582
  //#endregion
9583
+ //#region src/client/desktop-menu/restart-client.ts
9584
+ /**
9585
+ * 「重启应用与 Host」的客户端通道与进度卡片。
9586
+ *
9587
+ * 页面只做三件事:问 Host 能不能重启(status,拿到一次性令牌)→ 带着令牌 POST →
9588
+ * 轮询阶段把实情显示出来。真正的退出与重开由 Host 侧生成的助手脚本完成。
9589
+ *
9590
+ * 为什么不在这里直接 location.reload:重载只换页面,插件宿主进程还在,装了新插件
9591
+ * 也不生效;真重启必须让整个应用退出再起来。
9592
+ */
9593
+ /** 与 checkDesktopMenuEnabled 相同的方式拼出端点地址(兼容 dsh-app:// 协议)。 */
9594
+ function endpointUrl(search) {
9595
+ const base = typeof document !== "undefined" && document.baseURI ? document.baseURI : "http://localhost";
9596
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
9597
+ const path = CODEX_UI_API_ENDPOINTS.desktopMenu.startsWith("/") ? CODEX_UI_API_ENDPOINTS.desktopMenu.slice(1) : CODEX_UI_API_ENDPOINTS.desktopMenu;
9598
+ return `${new URL(path, normalizedBase).href}${search}`;
9599
+ }
9600
+ /** 读一次重启状态;网络/协议不可用时返回 null(调用方据此报「通道不可用」)。 */
9601
+ async function fetchRestartStatus() {
9602
+ try {
9603
+ const response = await fetch(endpointUrl("?action=status"), {
9604
+ method: "GET",
9605
+ cache: "no-store",
9606
+ headers: { accept: "application/json" }
9607
+ });
9608
+ if (!response.ok) return null;
9609
+ const payload = await response.json();
9610
+ if (typeof payload?.token !== "string") return null;
9611
+ return payload;
9612
+ } catch {
9613
+ return null;
9614
+ }
9615
+ }
9616
+ /** 带着令牌请求重启。 */
9617
+ async function requestRestart(token) {
9618
+ try {
9619
+ const response = await fetch(endpointUrl("?action=restart"), {
9620
+ method: "POST",
9621
+ cache: "no-store",
9622
+ headers: {
9623
+ accept: "application/json",
9624
+ [CODEX_UI_RESTART_HEADER]: token
9625
+ }
9626
+ });
9627
+ const payload = await response.json().catch(() => ({}));
9628
+ if (response.ok && payload.ok === true) return { ok: true };
9629
+ return {
9630
+ ok: false,
9631
+ error: payload.error ?? `http-${response.status}`,
9632
+ detail: payload.detail,
9633
+ reason: payload.reason
9634
+ };
9635
+ } catch (error) {
9636
+ return {
9637
+ ok: false,
9638
+ error: error instanceof Error ? error.message : String(error)
9639
+ };
9640
+ }
9641
+ }
9642
+ const STYLE_ID$1 = "dcu-desktop-restart-style";
9643
+ const STYLES$1 = `
9644
+ .dcu-restart-toast {
9645
+ position: fixed;
9646
+ z-index: 10001;
9647
+ right: 20px;
9648
+ bottom: 20px;
9649
+ width: min(380px, calc(100vw - 40px));
9650
+ padding: 14px 16px;
9651
+ display: flex;
9652
+ flex-direction: column;
9653
+ gap: 8px;
9654
+ border-radius: var(--dsw-radius-md, 10px);
9655
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.1));
9656
+ background: var(--dsw-menu-surface-fill, var(--dsw-alias-surface-overlay, #1e1e22));
9657
+ backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
9658
+ -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
9659
+ box-shadow: var(--dsw-elevation-prominent, 0 14px 34px rgba(0, 0, 0, 0.36));
9660
+ color: var(--dsw-alias-label-primary, #fff);
9661
+ font-family: var(--dsw-font-family, sans-serif);
9662
+ font-size: 13px;
9663
+ line-height: 19px;
9664
+ animation: dcu-restart-in 120ms ease-out;
9665
+ }
9666
+
9667
+ @keyframes dcu-restart-in {
9668
+ from { opacity: 0; transform: translateY(6px); }
9669
+ to { opacity: 1; transform: translateY(0); }
9670
+ }
9671
+
9672
+ .dcu-restart-toast[data-tone="error"] {
9673
+ border-color: var(--dsw-alias-state-error-primary, #ff6b6b);
9674
+ }
9675
+
9676
+ .dcu-restart-toast-title {
9677
+ font-weight: 600;
9678
+ }
9679
+
9680
+ .dcu-restart-toast-body {
9681
+ color: var(--dsw-alias-label-secondary, #a1a1a6);
9682
+ overflow-wrap: anywhere;
9683
+ }
9684
+
9685
+ .dcu-restart-toast-action {
9686
+ align-self: flex-end;
9687
+ height: 26px;
9688
+ padding: 0 10px;
9689
+ border-radius: var(--dsw-radius-sm, 6px);
9690
+ border: 1px solid var(--dsw-alias-border-l2, rgba(255, 255, 255, 0.14));
9691
+ background: transparent;
9692
+ color: inherit;
9693
+ font: inherit;
9694
+ font-size: 12px;
9695
+ cursor: pointer;
9696
+ }
9697
+
9698
+ .dcu-restart-toast-action:hover {
9699
+ background: var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, 0.08));
9700
+ }
9701
+ `;
9702
+ function ensureStyles$1() {
9703
+ if (document.getElementById(STYLE_ID$1) !== null) return;
9704
+ const style = document.createElement("style");
9705
+ style.id = STYLE_ID$1;
9706
+ style.textContent = STYLES$1;
9707
+ document.head.append(style);
9708
+ }
9709
+ /**
9710
+ * 显示重启提示卡。
9711
+ * @param copy - 当前语言文案。
9712
+ */
9713
+ function showRestartToast(copy) {
9714
+ ensureStyles$1();
9715
+ const card = document.createElement("div");
9716
+ card.className = "dcu-restart-toast";
9717
+ card.setAttribute("role", "status");
9718
+ card.setAttribute("aria-live", "polite");
9719
+ const title = document.createElement("div");
9720
+ title.className = "dcu-restart-toast-title";
9721
+ const body = document.createElement("div");
9722
+ body.className = "dcu-restart-toast-body";
9723
+ const action = document.createElement("button");
9724
+ action.type = "button";
9725
+ action.className = "dcu-restart-toast-action";
9726
+ action.textContent = copy.close;
9727
+ action.hidden = true;
9728
+ action.addEventListener("click", () => {
9729
+ card.remove();
9730
+ });
9731
+ card.append(title, body, action);
9732
+ document.body.append(card);
9733
+ return { set(nextTitle, nextBody, tone = "info") {
9734
+ title.textContent = nextTitle;
9735
+ body.textContent = nextBody ?? "";
9736
+ body.hidden = nextBody === void 0 || nextBody === "";
9737
+ card.dataset.tone = tone;
9738
+ action.hidden = tone !== "error";
9739
+ } };
9740
+ }
9741
+ /**
9742
+ * 重启后盯住阶段:页面通常会在应用退出时被带走,所以这里只是尽量把结果说清楚。
9743
+ * @param toast - 提示卡。
9744
+ * @param copy - 文案。
9745
+ * @param pollMs - 轮询间隔。
9746
+ * @param limitMs - 最长观察时间。
9747
+ */
9748
+ function watchRestart(toast, copy, pollMs = 700, limitMs = 9e4) {
9749
+ const startedAt = Date.now();
9750
+ let timer;
9751
+ let stopped = false;
9752
+ const stop = () => {
9753
+ stopped = true;
9754
+ if (timer !== void 0) window.clearInterval(timer);
9755
+ };
9756
+ const tick = async () => {
9757
+ if (stopped) return;
9758
+ if (Date.now() - startedAt > limitMs) {
9759
+ stop();
9760
+ toast.set(copy.timeout, void 0, "error");
9761
+ return;
9762
+ }
9763
+ const status = await fetchRestartStatus();
9764
+ if (stopped) return;
9765
+ if (status === null) return;
9766
+ const phase = status.phase;
9767
+ if (phase === "quitting" || phase === "starting") {
9768
+ toast.set(copy.quitting);
9769
+ return;
9770
+ }
9771
+ if (phase === "relaunched") {
9772
+ stop();
9773
+ toast.set(copy.relaunched);
9774
+ return;
9775
+ }
9776
+ if (phase === "cancelled") {
9777
+ stop();
9778
+ toast.set(copy.cancelled, status.detail, "error");
9779
+ return;
9780
+ }
9781
+ if (phase === "launch-failed") {
9782
+ stop();
9783
+ toast.set(copy.launchFailed, status.detail, "error");
9784
+ }
9785
+ };
9786
+ timer = window.setInterval(() => {
9787
+ tick();
9788
+ }, pollMs);
9789
+ return stop;
9790
+ }
9791
+ //#endregion
9792
+ //#region src/client/desktop-menu/index.ts
9793
+ /** 「重启应用与 Host」的文案:全部来自本插件的词典,不在代码里写死语言。 */
9794
+ function restartCopy(translate) {
9795
+ return {
9796
+ quitting: translate("desktopMenu.restart.quitting", "Closing and reopening DeepSeek Harness…"),
9797
+ relaunched: translate("desktopMenu.restart.relaunched", "Restarted."),
9798
+ cancelled: translate("desktopMenu.restart.cancelled", "The app did not exit; this restart was cancelled."),
9799
+ launchFailed: translate("desktopMenu.restart.launchFailed", "The app exited but could not be reopened automatically."),
9800
+ timeout: translate("desktopMenu.restart.timeout", "The restart did not finish in time; please check the app."),
9801
+ close: translate("desktopMenu.restart.close", "Close"),
9802
+ failed: translate("desktopMenu.restart.failed", "Restart failed"),
9803
+ busy: translate("desktopMenu.restart.busy", "A restart is already in progress. Please wait.")
9804
+ };
9805
+ }
9806
+ /** 不可重启的原因代码 → 本地文案。 */
9807
+ function unsupportedText(translate, reason) {
9808
+ if (reason === "desktop-only") return translate("desktopMenu.restart.unsupportedDesktopOnly", "This is not the desktop app, so it cannot be restarted.");
9809
+ return translate("desktopMenu.restart.unsupportedMissingApp", "Cannot locate the DeepSeek Harness executable, so it cannot be restarted.");
9810
+ }
9811
+ const MENU_HOST_CLASS = "dcu-desktop-menu-popover";
9812
+ const STYLE_ID = "dcu-desktop-menu-style";
9813
+ const STYLES = `
9814
+ .${MENU_HOST_CLASS} {
9815
+ position: fixed;
9816
+ z-index: 10000;
9817
+ min-width: 200px;
9818
+ max-width: 320px;
9819
+ padding: 4px;
9820
+ display: flex;
9821
+ flex-direction: column;
9822
+ gap: 2px;
9823
+ border-radius: var(--dsw-radius-md, 8px);
9824
+ background: var(--dsw-menu-surface-fill, var(--dsw-alias-surface-overlay, #1e1e22));
9825
+ backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
9826
+ -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
9827
+ box-shadow: var(--dsw-elevation-prominent, 0 14px 34px rgba(0,0,0,0.36), 0 2px 8px rgba(0,0,0,0.24));
9828
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
9829
+ color: var(--dsw-alias-label-primary, #ffffff);
9830
+ font-family: var(--dsw-font-family, sans-serif);
9831
+ animation: dcu-menu-fade-in 100ms ease-out;
9832
+ outline: none;
9833
+ -webkit-app-region: no-drag;
9834
+ }
9835
+
9836
+ @keyframes dcu-menu-fade-in {
9837
+ from { opacity: 0; transform: translateY(-4px); }
9838
+ to { opacity: 1; transform: translateY(0); }
9839
+ }
9840
+
9841
+ .${MENU_HOST_CLASS} .dcu-menu-separator {
9842
+ height: 1px;
9843
+ margin: 4px 6px;
9844
+ background: var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
9845
+ }
9846
+
9847
+ .${MENU_HOST_CLASS} button.dcu-menu-item {
9848
+ display: flex;
9849
+ align-items: center;
9850
+ justify-content: space-between;
9851
+ gap: 12px;
9852
+ width: 100%;
9853
+ min-height: 28px;
9854
+ padding: 5px 8px;
9855
+ text-align: left;
9856
+ border: 0;
9857
+ border-radius: var(--dsw-radius-sm, 6px);
9858
+ background: transparent;
9859
+ color: inherit;
9860
+ font: inherit;
9861
+ font-size: 13px;
9862
+ line-height: 18px;
9863
+ cursor: pointer;
9864
+ outline: none;
9865
+ transition: background-color 100ms ease;
9866
+ user-select: none;
9867
+ -webkit-user-select: none;
9868
+ -webkit-app-region: no-drag;
9869
+ }
9870
+
9871
+ .${MENU_HOST_CLASS} button.dcu-menu-item:hover,
9872
+ .${MENU_HOST_CLASS} button.dcu-menu-item:focus-visible {
9873
+ background: var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, 0.08));
9874
+ }
9875
+
9876
+ .${MENU_HOST_CLASS} .dcu-menu-label {
9877
+ flex: 1 1 auto;
9878
+ white-space: nowrap;
9879
+ overflow: hidden;
9880
+ text-overflow: ellipsis;
9881
+ }
9882
+ `;
9883
+ function ensureStyles() {
9884
+ if (document.getElementById(STYLE_ID) !== null) return;
9885
+ const style = document.createElement("style");
9886
+ style.id = STYLE_ID;
9887
+ style.textContent = STYLES;
9888
+ document.head.append(style);
9889
+ }
9890
+ let activePopover = null;
9891
+ let activeAnchor = null;
9892
+ function closeActiveMenu(restoreFocus = false) {
9893
+ const anchor = activeAnchor;
9894
+ if (activePopover !== null) {
9895
+ activePopover.remove();
9896
+ activePopover = null;
9897
+ }
9898
+ if (activeAnchor !== null) {
9899
+ activeAnchor.setAttribute("aria-expanded", "false");
9900
+ activeAnchor = null;
9901
+ }
9902
+ if (restoreFocus && anchor && anchor.isConnected) anchor.focus();
9903
+ }
9904
+ function openDropdown(anchor, items, options = {}) {
9905
+ if (activeAnchor === anchor && activePopover !== null) {
9906
+ closeActiveMenu();
9907
+ return;
9908
+ }
9909
+ closeActiveMenu();
9910
+ ensureStyles();
9911
+ const rect = anchor.getBoundingClientRect();
9912
+ const popover = document.createElement("div");
9913
+ popover.className = MENU_HOST_CLASS;
9914
+ popover.setAttribute("role", "menu");
9915
+ popover.tabIndex = -1;
9916
+ for (const item of items) {
9917
+ if (item.separatorBefore) {
9918
+ const sep = document.createElement("div");
9919
+ sep.className = "dcu-menu-separator";
9920
+ sep.setAttribute("role", "separator");
9921
+ popover.append(sep);
9922
+ }
9923
+ const btn = document.createElement("button");
9924
+ btn.type = "button";
9925
+ btn.className = "dcu-menu-item";
9926
+ btn.setAttribute("role", "menuitem");
9927
+ const labelSpan = document.createElement("span");
9928
+ labelSpan.className = "dcu-menu-label";
9929
+ labelSpan.textContent = item.label;
9930
+ btn.append(labelSpan);
9931
+ btn.addEventListener("pointerdown", (e) => {
9932
+ e.stopPropagation();
9933
+ });
9934
+ btn.addEventListener("mousedown", (e) => {
9935
+ e.stopPropagation();
9936
+ });
9937
+ btn.addEventListener("click", (e) => {
9938
+ e.preventDefault();
9939
+ e.stopPropagation();
9940
+ closeActiveMenu();
9941
+ setTimeout(() => {
9942
+ try {
9943
+ Promise.resolve(item.action?.()).catch((err) => {
9944
+ console.error("Menu action error:", err);
9945
+ });
9946
+ } catch (err) {
9947
+ console.error("Menu action error:", err);
9948
+ }
9949
+ }, 10);
9950
+ });
9951
+ popover.append(btn);
9952
+ }
9953
+ document.body.append(popover);
9954
+ const popoverRect = popover.getBoundingClientRect();
9955
+ let left = rect.left;
9956
+ let top = rect.bottom + 2;
9957
+ if (left + popoverRect.width > window.innerWidth - 8) left = window.innerWidth - popoverRect.width - 8;
9958
+ if (left < 8) left = 8;
9959
+ if (top + popoverRect.height > window.innerHeight - 8) top = rect.top - popoverRect.height - 2;
9960
+ popover.style.left = `${Math.round(left)}px`;
9961
+ popover.style.top = `${Math.round(top)}px`;
9962
+ anchor.setAttribute("aria-expanded", "true");
9963
+ activePopover = popover;
9964
+ activeAnchor = anchor;
9965
+ const menuItems = Array.from(popover.querySelectorAll("button.dcu-menu-item"));
9966
+ const focusAt = (index) => {
9967
+ if (menuItems.length === 0) return;
9968
+ const clamped = Math.max(0, Math.min(index, menuItems.length - 1));
9969
+ menuItems[clamped].focus();
9970
+ };
9971
+ popover.addEventListener("keydown", (event) => {
9972
+ const current = menuItems.indexOf(document.activeElement);
9973
+ if (event.key === "ArrowDown") {
9974
+ event.preventDefault();
9975
+ focusAt(current < 0 ? 0 : current + 1);
9976
+ } else if (event.key === "ArrowUp") {
9977
+ event.preventDefault();
9978
+ focusAt(current < 0 ? menuItems.length - 1 : current - 1);
9979
+ } else if (event.key === "Home") {
9980
+ event.preventDefault();
9981
+ focusAt(0);
9982
+ } else if (event.key === "End") {
9983
+ event.preventDefault();
9984
+ focusAt(menuItems.length - 1);
9985
+ }
9986
+ });
9987
+ if (options.focusFirst === true && menuItems.length > 0) menuItems[0].focus();
9988
+ else popover.focus();
9989
+ }
9990
+ /**
9991
+ * 监听全局事件以支持点击外部或按 Esc 关闭菜单
9992
+ */
9993
+ let globalListenersInstalled = false;
9994
+ function ensureGlobalListeners() {
9995
+ if (globalListenersInstalled) return;
9996
+ globalListenersInstalled = true;
9997
+ document.addEventListener("pointerdown", (e) => {
9998
+ if (activePopover === null) return;
9999
+ const path = e.composedPath ? e.composedPath() : [];
10000
+ if (path.length > 0) {
10001
+ if (activePopover && path.includes(activePopover)) return;
10002
+ if (activeAnchor && path.includes(activeAnchor)) return;
10003
+ } else {
10004
+ const target = e.target;
10005
+ if (target && (activePopover.contains(target) || activeAnchor?.contains(target))) return;
10006
+ }
10007
+ closeActiveMenu();
10008
+ }, true);
10009
+ window.addEventListener("keydown", (e) => {
10010
+ if (e.key === "Escape" && activePopover !== null) closeActiveMenu(true);
10011
+ }, true);
10012
+ }
10013
+ /**
10014
+ * 检查桌面端窗口菜单子插件在 Host 侧是否启用
10015
+ */
10016
+ async function checkDesktopMenuEnabled() {
10017
+ try {
10018
+ const base = typeof document !== "undefined" && document.baseURI ? document.baseURI : "http://localhost";
10019
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
10020
+ const path = CODEX_UI_API_ENDPOINTS.desktopMenu.startsWith("/") ? CODEX_UI_API_ENDPOINTS.desktopMenu.slice(1) : CODEX_UI_API_ENDPOINTS.desktopMenu;
10021
+ const url = new URL(path, normalizedBase).href;
10022
+ const res = await fetch(url, { method: "GET" });
10023
+ if (!res.ok) return true;
10024
+ return (await res.json()).enabled !== false;
10025
+ } catch {
10026
+ return true;
10027
+ }
10028
+ }
10029
+ /**
10030
+ * 观察并在 Windows 桌面端的 data-windows-menu 宿主上注入【帮助】菜单。
10031
+ * 只追加一个入口,官方【应用】【编辑】保持原样。
10032
+ */
10033
+ function observeDesktopTitlebarMenus(translate = (_k, fallback) => fallback ?? "") {
10034
+ ensureGlobalListeners();
10035
+ let cleanedUp = false;
10036
+ let injectedHelpBtn = null;
10037
+ const getHelpItems = () => {
10038
+ const zh = document.documentElement.lang?.toLowerCase().startsWith("zh") ?? true;
10039
+ return [{
10040
+ id: "reload-page",
10041
+ label: translate("desktopMenu.help.reloadPage", zh ? "刷新页面" : "Reload Page"),
10042
+ action: () => {
10043
+ window.location.reload();
10044
+ }
10045
+ }, {
10046
+ id: "restart-host",
10047
+ label: translate("desktopMenu.help.restartAppHost", zh ? "重启应用与 Host" : "Restart App and Host"),
10048
+ action: async () => {
10049
+ const copy = restartCopy(translate);
10050
+ const status = await fetchRestartStatus();
10051
+ if (status === null) {
10052
+ showRestartToast(copy).set(copy.failed, translate("desktopMenu.restart.unreachable", "Cannot reach the Host; the restart channel is unavailable."), "error");
10053
+ return;
10054
+ }
10055
+ if (!status.canRestart) {
10056
+ showRestartToast(copy).set(copy.failed, unsupportedText(translate, status.reason), "error");
10057
+ return;
10058
+ }
10059
+ const confirmMsg = translate("desktopMenu.help.restartConfirm", "DeepSeek Harness will close and reopen; running tasks will be interrupted. Continue?");
10060
+ if (!window.confirm(confirmMsg)) return;
10061
+ const toast = showRestartToast(copy);
10062
+ toast.set(copy.quitting);
10063
+ const outcome = await requestRestart(status.token);
10064
+ if (!outcome.ok) {
10065
+ const detailText = outcome.error === "busy" ? copy.busy : outcome.reason ? unsupportedText(translate, outcome.reason) : outcome.detail ?? outcome.error ?? "unknown";
10066
+ toast.set(copy.failed, detailText, "error");
10067
+ return;
10068
+ }
10069
+ watchRestart(toast, copy);
10070
+ }
10071
+ }];
10072
+ };
10073
+ const mountMenus = () => {
10074
+ if (cleanedUp || typeof document === "undefined") return;
10075
+ const host = document.querySelector("[data-windows-menu]");
10076
+ if (!host || !host.shadowRoot) return;
10077
+ const shadow = host.shadowRoot;
10078
+ const bar = shadow.querySelector("[role=\"menubar\"]");
10079
+ if (!bar) return;
10080
+ if (Array.from(bar.querySelectorAll("button")).length === 0) return;
10081
+ if (!shadow.getElementById("dcu-desktop-menu-help")) {
10082
+ const helpBtn = document.createElement("button");
10083
+ helpBtn.type = "button";
10084
+ helpBtn.id = "dcu-desktop-menu-help";
10085
+ helpBtn.setAttribute("role", "menuitem");
10086
+ helpBtn.setAttribute("aria-haspopup", "menu");
10087
+ helpBtn.setAttribute("aria-expanded", "false");
10088
+ const setRovingFocus = (target) => {
10089
+ bar.querySelectorAll("button").forEach((btn) => {
10090
+ btn.tabIndex = btn === target ? 0 : -1;
10091
+ });
10092
+ target.focus();
10093
+ };
10094
+ helpBtn.tabIndex = -1;
10095
+ helpBtn.textContent = translate("desktopMenu.help", "帮助");
10096
+ helpBtn.addEventListener("click", (e) => {
10097
+ e.preventDefault();
10098
+ e.stopPropagation();
10099
+ openDropdown(helpBtn, getHelpItems());
10100
+ });
10101
+ helpBtn.addEventListener("keydown", (e) => {
10102
+ if (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") {
10103
+ e.preventDefault();
10104
+ e.stopPropagation();
10105
+ openDropdown(helpBtn, getHelpItems(), { focusFirst: true });
10106
+ return;
10107
+ }
10108
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
10109
+ e.preventDefault();
10110
+ e.stopPropagation();
10111
+ const official = Array.from(bar.querySelectorAll("button:not(#dcu-desktop-menu-help)"));
10112
+ const target = e.key === "ArrowLeft" ? official[official.length - 1] ?? official[0] : official[0];
10113
+ if (target) setRovingFocus(target);
10114
+ }
10115
+ });
10116
+ bar.addEventListener("keydown", (e) => {
10117
+ const target = e.target;
10118
+ if (!target || target === helpBtn) return;
10119
+ const official = Array.from(bar.querySelectorAll("button:not(#dcu-desktop-menu-help)"));
10120
+ if (official.length === 0) return;
10121
+ if (e.key === "ArrowRight" && target === official[official.length - 1]) {
10122
+ e.preventDefault();
10123
+ e.stopImmediatePropagation();
10124
+ setRovingFocus(helpBtn);
10125
+ } else if (e.key === "ArrowLeft" && target === official[0]) {
10126
+ e.preventDefault();
10127
+ e.stopImmediatePropagation();
10128
+ setRovingFocus(helpBtn);
10129
+ }
10130
+ }, true);
10131
+ bar.append(helpBtn);
10132
+ injectedHelpBtn = helpBtn;
10133
+ }
10134
+ };
10135
+ mountMenus();
10136
+ const observer = new MutationObserver(() => {
10137
+ mountMenus();
10138
+ });
10139
+ observer.observe(document.body, { childList: true });
10140
+ return () => {
10141
+ cleanedUp = true;
10142
+ observer.disconnect();
10143
+ closeActiveMenu();
10144
+ injectedHelpBtn?.remove();
10145
+ document.getElementById(STYLE_ID)?.remove();
10146
+ };
10147
+ }
10148
+ //#endregion
9541
10149
  //#region src/client/index.ts
9542
10150
  const inject = [
9543
10151
  "slots",
@@ -9546,7 +10154,8 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
9546
10154
  "conversation",
9547
10155
  "inputTriggers",
9548
10156
  "layout",
9549
- "uiWorkspace"
10157
+ "uiWorkspace",
10158
+ "workspaces"
9550
10159
  ];
9551
10160
  /** 浏览器客户端插件入口;保留官方原生侧边栏与工作区树,提供输入框增强、设置美化与生态关于页。 */
9552
10161
  function apply(ctx) {
@@ -9557,6 +10166,26 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
9557
10166
  const t = ctx.locale.bind(NS);
9558
10167
  ctx.effect(() => observeTheme(ctx), "michengai-codex-ui: theme & appearance");
9559
10168
  ctx.effect(() => observeSidebarNav(ctx), "michengai-codex-ui: sidebar navigation");
10169
+ ctx.effect(() => {
10170
+ let stop;
10171
+ let cancelled = false;
10172
+ checkDesktopMenuEnabled().then((enabled) => {
10173
+ if (cancelled || !enabled) return;
10174
+ const translate = (key, fallback) => {
10175
+ try {
10176
+ const value = t(key);
10177
+ return typeof value === "string" && value !== "" && value !== key ? value : fallback ?? key;
10178
+ } catch {
10179
+ return fallback ?? key;
10180
+ }
10181
+ };
10182
+ stop = observeDesktopTitlebarMenus(translate);
10183
+ });
10184
+ return () => {
10185
+ cancelled = true;
10186
+ stop?.();
10187
+ };
10188
+ }, "michengai-codex-ui: desktop titlebar menus");
9560
10189
  ctx.effect(() => {
9561
10190
  let stop;
9562
10191
  let cancelled = false;