dsh-gufa-code 1.2.5 → 1.3.1

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/README.md CHANGED
@@ -67,16 +67,18 @@ dsh plugin add dsh-gufa-code
67
67
  - **会话弹窗里可以直接切换工作区**:点弹窗右上角的工作区名,选任意工作区后下方会话列表随之切换,点会话即打开(IDE 项目同时切到该工作区),不用再先切左侧工作区;
68
68
  - 会话里的文件链接、diff 标签页属于 DSH 右侧栏,被覆盖层挡住时点「打开完整对话」即可查看。
69
69
 
70
- ### 桌面悬浮层(实验功能,macOS arm64)
71
-
72
- - IDE 标题栏点「显示器」图标 → 屏幕上出现一个**无边框、半透明(0.55)、永远置顶**的独立悬浮窗,里面就是古法编程;
73
- - 顶部 22px 拖动条移动窗口(右键 = 悬浮层菜单),窗口大小/位置会记住;
74
- - 菜单栏「古法」图标:
75
- - **跟随 App 窗口…**:选一个正在运行的 App 窗口,悬浮层自动对齐并实时跟随它的位置/大小(需要授予「屏幕录制」权限——只读窗口尺寸,不录屏);
76
- - **停止跟随**:恢复自由拖动;
77
- - **切换点击穿透**:穿透后鼠标直接操作下层 App(全局快捷键 ⌃⌥⌘G 随时切回);
78
- - **关闭悬浮层**。
79
- - 限制:目前仅 macOS arm64;跟随多显示器时按主屏坐标换算;helper 未签名(本地 ad-hoc 签名),分发前需要正式签名/notarize。
70
+ ### 摸鱼模式 / 桌面悬浮层(实验功能,macOS arm64)
71
+
72
+ - **进入摸鱼**:IDE 标题栏点「显示器」图标 → 弹出 **App 窗口列表**(图标 + App 名 + 窗口标题 + 窗口尺寸,和投屏列表类似)→ 选中一个窗口,古法编程会:
73
+ - 把该 App 切到前台(主窗口自动被盖住,等于「隐藏主窗口」);
74
+ - 以**无边框、半透明(0.55)、永远置顶**的独立悬浮窗出现,并**自动吸附**到该窗口:位置、大小完全一致,窗口移动/缩放时实时跟随。
75
+ - **悬浮层交互**:
76
+ - 顶部 22px 拖动条移动窗口(右键 = 摸鱼菜单),窗口大小/位置会记住;
77
+ - 全局快捷键 **⌃⌥⌘G**:切换点击穿透(穿透后鼠标直接操作下面的 App,再按一次切回来);
78
+ - 菜单栏「古法」图标 / 拖动条右键:**退出摸鱼**(关闭悬浮层并把主窗口唤回前台);
79
+ - 在悬浮层里再点「显示器」图标 = 退出摸鱼。
80
+ - 选择器底部还有「自由悬浮(不吸附)」:不绑定窗口,自己拖拽缩放。
81
+ - 限制:目前仅 macOS arm64;多显示器按主屏坐标换算;helper 未正式签名(本地 ad-hoc 签名),分发前需要签名/notarize。
80
82
 
81
83
  ### 外观
82
84
 
@@ -97,6 +99,11 @@ node scripts/test-editor.mjs
97
99
  # 修改 host/*.js 后无需重启(请求级热重载);修改 client 后重新构建并刷新页面
98
100
  ```
99
101
 
102
+ > 加新功能/新浮层前先看 [`docs/KNOWN-PITFALLS.md`](docs/KNOWN-PITFALLS.md)(层级、TCC 权限、Monaco worker 三个坑)。
103
+
104
+ ```sh
105
+ ```
106
+
100
107
  ## License
101
108
 
102
109
  MIT
package/client.js CHANGED
@@ -1056,6 +1056,8 @@ html[data-gufa-float] #root .gufa-overlay-root *,
1056
1056
  html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
1057
1057
  /* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
1058
1058
  html[data-gufa-ide] .dsh-pet-root{z-index:2147483400!important}
1059
+ /* 古法自己的弹窗/菜单打开时:整个覆盖层临时抬到右侧停靠会话(z-index 2147483040)之上 */
1060
+ html[data-gufa-popup] .gufa-overlay-root{z-index:2147483300!important}
1059
1061
  /* 外部弹窗(DSH 设置等)打开时:停靠会话与桌宠降到弹窗之下,保证弹窗完整可点可关 */
1060
1062
  html[data-gufa-external-modal] [data-gufa-dock]{z-index:2!important}
1061
1063
  html[data-gufa-external-modal] .dsh-pet-root{z-index:2!important}
@@ -1122,6 +1124,24 @@ html[data-gufa-ide] [role="dialog"] {
1122
1124
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1123
1125
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1124
1126
  .gufa-session-group .gufa-session-row{margin-left:10px}
1127
+ /* 摸鱼模式:App 窗口选择器 */
1128
+ .gufa-float-backdrop{position:fixed;inset:0;z-index:2147483200;display:flex;align-items:center;justify-content:center;
1129
+ background:rgba(0,0,0,0.42);padding:24px;box-sizing:border-box}
1130
+ .gufa-float-picker{width:min(660px,92vw);max-height:min(640px,82vh);display:flex;flex-direction:column;
1131
+ background:var(--gufa-layer);border:1px solid var(--gufa-border-strong);border-radius:12px;overflow:hidden;
1132
+ box-shadow:0 24px 60px rgba(0,0,0,0.45)}
1133
+ .gufa-float-list{display:flex;flex-direction:column;gap:4px;padding:8px 10px;overflow:auto;min-height:120px}
1134
+ .gufa-float-row{display:flex;align-items:center;gap:10px;width:100%;padding:7px 10px;border:0;border-radius:9px;
1135
+ background:transparent;color:var(--gufa-text);font:inherit;text-align:left;cursor:pointer}
1136
+ .gufa-float-row:hover{background:var(--gufa-hover)}
1137
+ .gufa-float-row:disabled{opacity:0.55;cursor:default}
1138
+ .gufa-float-icon{width:26px;height:26px;object-fit:contain;flex:0 0 auto;border-radius:5px}
1139
+ .gufa-float-meta{display:flex;flex-direction:column;gap:1px;min-width:0;flex:1 1 auto}
1140
+ .gufa-float-owner{font-size:12.5px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1141
+ .gufa-float-title{font-size:11px;color:var(--gufa-text-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1142
+ .gufa-float-size{flex:0 0 auto;font-size:10.5px;color:var(--gufa-text-dim);font-variant-numeric:tabular-nums}
1143
+ .gufa-float-permission{padding:16px}
1144
+ .gufa-float-permission-title{font-size:13px;font-weight:600;margin-bottom:6px}
1125
1145
  .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1126
1146
  color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1127
1147
  .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
@@ -8089,6 +8109,64 @@ G.installDialogLayerWatch = function installDialogLayerWatch(ctx) {
8089
8109
  }
8090
8110
 
8091
8111
 
8112
+ /* ─────────────────────── 59-popup-layer.js ─────────────────────── */
8113
+ /**
8114
+ * 59-popup-layer:弹窗/菜单层级修正。
8115
+ *
8116
+ * 背景(踩坑记录,见 docs/KNOWN-PITFALLS.md):
8117
+ * 古法编程的界面都在 `.gufa-overlay-root`(z-index:1)这个层叠上下文里,而右侧停靠的
8118
+ * 官方会话根节点是 body 级 fixed、z-index 2147483040。任何在 root 内部弹出的
8119
+ * modal / menu / popover,如果只设自己的 z-index,都会被困在 root 的上下文里,
8120
+ * 被停靠会话盖住(表现为「弹窗被右侧聊天挡一半、点不到关闭」)。
8121
+ *
8122
+ * 修法:检测 root 内是否出现 popup,出现时给 html 加 `data-gufa-popup`,
8123
+ * 由 CSS 把整个 overlay root 临时抬到停靠会话之上。
8124
+ */
8125
+
8126
+ G.installPopupLayerWatch = function installPopupLayerWatch(ctx) {
8127
+ if (typeof document === 'undefined') return () => {}
8128
+ const ATTR = 'data-gufa-popup'
8129
+ const SELECTOR = [
8130
+ '[role="menu"]',
8131
+ '[role="listbox"]',
8132
+ '[role="dialog"]',
8133
+ '.gufa-modal',
8134
+ '.gufa-float-backdrop',
8135
+ '.gufa-branch-dialog-backdrop',
8136
+ '.gufa-session-backdrop',
8137
+ '.gufa-shortcuts-backdrop',
8138
+ ].join(',')
8139
+
8140
+ const sync = () => {
8141
+ try {
8142
+ const root = document.querySelector('.gufa-root')
8143
+ const popup = root === null ? null : root.querySelector(SELECTOR)
8144
+ const open = popup !== null
8145
+ if ((document.documentElement.getAttribute(ATTR) === '1') === open) return
8146
+ if (open) document.documentElement.setAttribute(ATTR, '1')
8147
+ else document.documentElement.removeAttribute(ATTR)
8148
+ } catch {
8149
+ /* ignore */
8150
+ }
8151
+ }
8152
+
8153
+ let observer = null
8154
+ try {
8155
+ observer = new MutationObserver(sync)
8156
+ observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'style', 'data-state', 'aria-hidden'] })
8157
+ } catch {
8158
+ observer = null
8159
+ }
8160
+ sync()
8161
+ const timer = window.setInterval(sync, 400)
8162
+ return () => {
8163
+ if (observer !== null) observer.disconnect()
8164
+ window.clearInterval(timer)
8165
+ document.documentElement.removeAttribute(ATTR)
8166
+ }
8167
+ }
8168
+
8169
+
8092
8170
  /* ─────────────────────── 60-dock.js ─────────────────────── */
8093
8171
  /**
8094
8172
  * 60-dock:把官方 DSH 会话面板「停靠」进古法编程右侧的 AI 栏。
@@ -9436,6 +9514,8 @@ G.GufaApp = function GufaApp(props) {
9436
9514
  const [sessionsOpen, setSessionsOpen] = useState(false)
9437
9515
  const [floatRunning, setFloatRunning] = useState(false)
9438
9516
  const [floatBusy, setFloatBusy] = useState(false)
9517
+ /* 摸鱼窗口选择器:null | {status:'loading'|'ready'|'permission'|'error', windows:[], error:''} */
9518
+ const [floatPicker, setFloatPicker] = useState(null)
9439
9519
  /* 会话弹窗里选中的工作区(null = 跟随当前 IDE 项目) */
9440
9520
  const [sessionWorkspacePath, setSessionWorkspacePath] = useState(null)
9441
9521
  const [sessionWorkspacePicker, setSessionWorkspacePicker] = useState(false)
@@ -10108,25 +10188,78 @@ G.GufaApp = function GufaApp(props) {
10108
10188
  return () => { cancelled = true }
10109
10189
  }, [])
10110
10190
 
10111
- const toggleFloatWindow = useCallback(async () => {
10191
+ /* 退出摸鱼:关掉悬浮层(helper 会把主窗口唤回前台) */
10192
+ const stopFloatWindow = useCallback(async () => {
10112
10193
  if (floatBusy) return
10113
10194
  setFloatBusy(true)
10114
10195
  try {
10115
- if (floatRunning) {
10116
- await G.api('float.stop')
10117
- setFloatRunning(false)
10118
- setBanner('悬浮层已关闭')
10196
+ await G.api('float.stop')
10197
+ setFloatRunning(false)
10198
+ setBanner('已退出摸鱼:主窗口已恢复')
10199
+ } catch (error) {
10200
+ setBanner(G.errorText(error))
10201
+ } finally {
10202
+ setFloatBusy(false)
10203
+ }
10204
+ }, [floatBusy])
10205
+
10206
+ /* 拉取可吸附的 App 窗口列表(摸鱼列表) */
10207
+ const openFloatPicker = useCallback(async () => {
10208
+ if (floatBusy) return
10209
+ setFloatPicker({ status: 'loading', windows: [], error: '' })
10210
+ try {
10211
+ const value = await G.api('float.windows')
10212
+ if (value?.ok === true && Array.isArray(value.windows)) {
10213
+ setFloatPicker({ status: 'ready', windows: value.windows, error: '' })
10214
+ } else if (value?.ok === false && value?.permission === 'screen-recording') {
10215
+ setFloatPicker({ status: 'permission', windows: [], error: '' })
10119
10216
  } else {
10120
- const value = await G.api('float.start')
10121
- setFloatRunning(value?.running === true)
10122
- setBanner('悬浮层已启动:屏幕上的半透明窗口,菜单栏「古法」可切换点击穿透')
10217
+ setFloatPicker({ status: 'error', windows: [], error: '没有读到可吸附的窗口' })
10123
10218
  }
10219
+ } catch (error) {
10220
+ setFloatPicker({ status: 'error', windows: [], error: G.errorText(error) })
10221
+ }
10222
+ }, [floatBusy])
10223
+
10224
+ /* 选中某个 App 窗口 → 启动悬浮层并吸附它 */
10225
+ const startFloatForWindow = useCallback(async (target) => {
10226
+ if (floatBusy || target === null || target === undefined) return
10227
+ setFloatBusy(true)
10228
+ try {
10229
+ const value = await G.api('float.start', {
10230
+ follow: { windowNumber: Number(target.windowNumber) || 0, pid: Number(target.pid) || 0 },
10231
+ })
10232
+ setFloatRunning(value?.running === true)
10233
+ setFloatPicker(null)
10234
+ const name = typeof target.owner === 'string' && target.owner !== '' ? target.owner : '所选窗口'
10235
+ setBanner(`摸鱼模式已开启:已吸附 ${name};⌃⌥⌘G 切换点击穿透,菜单栏「古法」可退出`)
10124
10236
  } catch (error) {
10125
10237
  setBanner(G.errorText(error))
10126
10238
  } finally {
10127
10239
  setFloatBusy(false)
10128
10240
  }
10129
- }, [floatBusy, floatRunning])
10241
+ }, [floatBusy])
10242
+
10243
+ /* 自由悬浮(不吸附窗口) */
10244
+ const startFloatFree = useCallback(async () => {
10245
+ if (floatBusy) return
10246
+ setFloatBusy(true)
10247
+ try {
10248
+ const value = await G.api('float.start')
10249
+ setFloatRunning(value?.running === true)
10250
+ setFloatPicker(null)
10251
+ setBanner('悬浮层已启动(自由悬浮)')
10252
+ } catch (error) {
10253
+ setBanner(G.errorText(error))
10254
+ } finally {
10255
+ setFloatBusy(false)
10256
+ }
10257
+ }, [floatBusy])
10258
+
10259
+ const toggleFloatWindow = useCallback(() => {
10260
+ if (floatRequested === true || floatRunning) void stopFloatWindow()
10261
+ else void openFloatPicker()
10262
+ }, [floatRequested, floatRunning, stopFloatWindow, openFloatPicker])
10130
10263
 
10131
10264
  /* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
10132
10265
  * ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
@@ -11038,7 +11171,7 @@ G.GufaApp = function GufaApp(props) {
11038
11171
  }, h(G.Icon, { name: 'image', size: 16 }))
11039
11172
  : null,
11040
11173
  h(G.IconButton, {
11041
- title: floatRunning ? '关闭桌面悬浮层' : '打开桌面悬浮层(半透明置顶窗口)',
11174
+ title: floatRequested === true || floatRunning ? '退出摸鱼(关闭悬浮层,回主窗口)' : '进入摸鱼模式:选择一个 App 吸附并悬浮',
11042
11175
  'data-active': floatRunning ? '' : undefined,
11043
11176
  disabled: floatBusy,
11044
11177
  onClick: () => void toggleFloatWindow(),
@@ -11364,6 +11497,80 @@ G.GufaApp = function GufaApp(props) {
11364
11497
  ),
11365
11498
  /* 弹窗 */
11366
11499
  modal === null ? null : renderModal(),
11500
+ floatPicker !== null
11501
+ ? h(
11502
+ 'div',
11503
+ {
11504
+ className: 'gufa-float-backdrop',
11505
+ onMouseDown: (event) => { if (event.target === event.currentTarget) setFloatPicker(null) },
11506
+ },
11507
+ h(
11508
+ 'div',
11509
+ { className: 'gufa-float-picker', role: 'dialog', 'aria-modal': 'true', 'aria-label': '选择要摸鱼的 App' },
11510
+ h(
11511
+ 'div',
11512
+ { className: 'gufa-modal-head' },
11513
+ h(G.Icon, { name: 'monitor', size: 15 }),
11514
+ h('span', { style: { flex: '1 1 auto' } }, '摸鱼模式:选择要吸附的 App'),
11515
+ h(G.IconButton, { title: t('common.close'), onClick: () => setFloatPicker(null) }, h(G.Icon, { name: 'close', size: 14 })),
11516
+ ),
11517
+ floatPicker.status === 'loading'
11518
+ ? h('div', { className: 'gufa-graph-loading', style: { height: 90 } }, h(G.Spinner), '正在读取窗口列表…')
11519
+ : floatPicker.status === 'permission'
11520
+ ? h(
11521
+ 'div',
11522
+ { className: 'gufa-float-permission' },
11523
+ h('div', { className: 'gufa-float-permission-title' }, '需要「屏幕录制」权限'),
11524
+ h('div', { className: 'gufa-hint' }, '摸鱼列表需要读取其他 App 的窗口尺寸(只读尺寸,不录屏)。请在「系统设置 → 隐私与安全性 → 屏幕录制」里勾选 **DeepSeek Harness**(若列表只显示自己,请重启一次 DeepSeek Harness 让权限生效),然后点「重试」。'),
11525
+ h(
11526
+ 'div',
11527
+ { className: 'gufa-row', style: { gap: 8, marginTop: 12 } },
11528
+ h(G.Button, { primary: true, onClick: () => void G.api('float.openPrivacy').catch(() => {}) }, '打开系统设置'),
11529
+ h(G.Button, { onClick: () => void openFloatPicker() }, '重试'),
11530
+ ),
11531
+ )
11532
+ : floatPicker.status === 'error'
11533
+ ? h('div', { className: 'gufa-float-permission' }, h('div', { className: 'gufa-error-banner' }, floatPicker.error))
11534
+ : floatPicker.windows.length === 0
11535
+ ? h('div', { className: 'gufa-hint', style: { padding: 16 } }, '没有可吸附的窗口')
11536
+ : h(
11537
+ 'div',
11538
+ { className: 'gufa-float-list gufa-scroll' },
11539
+ floatPicker.windows.map((win, index) =>
11540
+ h(
11541
+ 'button',
11542
+ {
11543
+ key: `${win.pid}:${win.windowNumber}:${index}`,
11544
+ type: 'button',
11545
+ className: 'gufa-float-row',
11546
+ title: `${win.owner} — ${win.title}`,
11547
+ disabled: floatBusy,
11548
+ onClick: () => void startFloatForWindow(win),
11549
+ },
11550
+ win.icon !== undefined && win.icon !== ''
11551
+ ? h('img', { className: 'gufa-float-icon', src: `data:image/png;base64,${win.icon}`, alt: '' })
11552
+ : h(G.Icon, { name: 'monitor', size: 26 }),
11553
+ h(
11554
+ 'span',
11555
+ { className: 'gufa-float-meta' },
11556
+ h('span', { className: 'gufa-float-owner' }, win.owner !== '' ? win.owner : '未知 App'),
11557
+ h('span', { className: 'gufa-float-title' }, win.title !== '' ? win.title : '(无标题窗口)'),
11558
+ ),
11559
+ h('span', { className: 'gufa-float-size' }, `${Math.round(win.width)}×${Math.round(win.height)}`),
11560
+ ),
11561
+ ),
11562
+ ),
11563
+ h(
11564
+ 'div',
11565
+ { className: 'gufa-modal-foot' },
11566
+ h(G.IconButton, { title: '刷新列表', onClick: () => void openFloatPicker() }, h(G.Icon, { name: 'refresh', size: 14 })),
11567
+ h('span', { style: { flex: '1 1 auto' } }),
11568
+ h(G.Button, { onClick: () => void startFloatFree() }, '自由悬浮(不吸附)'),
11569
+ h(G.Button, { onClick: () => setFloatPicker(null) }, t('common.close')),
11570
+ ),
11571
+ ),
11572
+ )
11573
+ : null,
11367
11574
  sessionsOpen ? renderSessionsDialog() : null,
11368
11575
  shortcutsOpen ? renderShortcutsDialog() : null,
11369
11576
  )
@@ -11985,6 +12192,16 @@ const GUFA_PLUGIN = {
11985
12192
  window.setTimeout(cleanStaleSidebarLayouts, 1500)
11986
12193
  window.setTimeout(cleanStaleSidebarLayouts, 5000)
11987
12194
 
12195
+ // 弹窗/菜单打开时把覆盖层整体抬到右侧停靠会话之上(否则会被盖住)
12196
+ try {
12197
+ if (typeof G.installPopupLayerWatch === 'function') {
12198
+ const disposePopupWatch = G.installPopupLayerWatch(ctx)
12199
+ if (typeof disposePopupWatch === 'function') ctx.effect(() => disposePopupWatch, 'gufa-code: popup layer watch')
12200
+ }
12201
+ } catch (error) {
12202
+ console.error('[gufa-code] 安装弹窗层级监听失败', error)
12203
+ }
12204
+
11988
12205
  // 外部弹窗(设置等)打开时降低停靠层,避免遮挡弹窗导致关不掉
11989
12206
  try {
11990
12207
  if (typeof G.installDialogLayerWatch === 'function') {
@@ -13,9 +13,14 @@
13
13
  #import <WebKit/WebKit.h>
14
14
  #import <CoreGraphics/CoreGraphics.h>
15
15
  #import <Carbon/Carbon.h>
16
+ #import <signal.h>
16
17
 
17
18
  static const EventHotKeyID GufaToggleHotKey = {'gufa', 1};
18
19
 
20
+ /* SIGTERM 时先把主窗口(DeepSeek Harness)唤回前台,再退出,实现「退出摸鱼」 */
21
+ static void GufaInstallTermHandler(void);
22
+ static BOOL GufaRowsHaveForeignWindows(NSArray<NSDictionary *> *rows);
23
+
19
24
  @class GufaAppDelegate;
20
25
 
21
26
  static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
@@ -34,7 +39,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
34
39
  NSFontAttributeName: [NSFont systemFontOfSize:10 weight:NSFontWeightMedium],
35
40
  NSForegroundColorAttributeName: [NSColor colorWithCalibratedWhite:1.0 alpha:0.6],
36
41
  };
37
- NSString *label = @"古法编程 · 悬浮层(拖动移动 · 右键菜单 · ⌃⌥⌘G 切穿透)";
42
+ NSString *label = @"古法编程 · 摸鱼中(拖动移动 · 右键菜单 · ⌃⌥⌘G 切穿透)";
38
43
  NSSize size = [label sizeWithAttributes:attrs];
39
44
  NSPoint origin = NSMakePoint(floor((self.bounds.size.width - size.width) / 2.0), floor((self.bounds.size.height - size.height) / 2.0));
40
45
  [label drawAtPoint:origin withAttributes:attrs];
@@ -86,6 +91,10 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
86
91
  @property (nonatomic, strong) NSMutableArray<NSDictionary *> *windowCandidates;
87
92
  - (void)loadWebContent;
88
93
  - (void)registerToggleHotKey;
94
+ - (void)activateTargetApp;
95
+ - (void)beginningFollowFromOptions;
96
+ - (void)exitMoyu:(id)sender;
97
+ - (void)restoreMainWindow;
89
98
  - (void)toggleClickThrough:(id)sender;
90
99
  - (void)resetFrame:(id)sender;
91
100
  - (void)quitApp:(id)sender;
@@ -114,9 +123,36 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
114
123
  [self buildWindow];
115
124
  [self buildStatusItem];
116
125
  [self registerToggleHotKey];
126
+ [self activateTargetApp];
127
+ [self beginningFollowFromOptions];
117
128
  [self loadWebContent];
118
129
  }
119
130
 
131
+ /** 吸附目标 App:把它切到前台,主窗口就自然被盖住了(等价于「隐藏主窗口」的观感)。 */
132
+ - (void)activateTargetApp {
133
+ NSDictionary *follow = self.options[@"follow"];
134
+ NSNumber *pid = [follow isKindOfClass:[NSDictionary class]] ? follow[@"pid"] : nil;
135
+ if (![pid isKindOfClass:[NSNumber class]]) return;
136
+ NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier:(pid_t)pid.intValue];
137
+ if (app == nil) return;
138
+ [app activateWithOptions:NSApplicationActivateAllWindows];
139
+ }
140
+
141
+ /** 启动就进入「吸附跟随」模式(摸鱼列表选好窗口后直接启动)。 */
142
+ - (void)beginningFollowFromOptions {
143
+ NSDictionary *follow = self.options[@"follow"];
144
+ if (![follow isKindOfClass:[NSDictionary class]]) return;
145
+ NSNumber *number = follow[@"windowNumber"];
146
+ NSNumber *pid = follow[@"pid"];
147
+ if (![number isKindOfClass:[NSNumber class]] || ![pid isKindOfClass:[NSNumber class]]) return;
148
+ self.followWindowNumber = number.intValue;
149
+ self.followOwnerPID = (pid_t)pid.intValue;
150
+ self.following = YES;
151
+ [self startFollowTimer];
152
+ [self applyFollowFrame];
153
+ self.statusItem.button.title = @"古法·摸鱼";
154
+ }
155
+
120
156
  - (void)parseOptions {
121
157
  NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;
122
158
  if (args.count < 2) return;
@@ -202,7 +238,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
202
238
  [menu addItemWithTitle:@"切换点击穿透(⌃⌥⌘G)" action:@selector(toggleClickThrough:) keyEquivalent:@""].target = self;
203
239
  [menu addItemWithTitle:@"重置窗口位置和大小" action:@selector(resetFrame:) keyEquivalent:@""].target = self;
204
240
  [menu addItem:[NSMenuItem separatorItem]];
205
- [menu addItemWithTitle:@"关闭悬浮层" action:@selector(quitApp:) keyEquivalent:@""].target = self;
241
+ [menu addItemWithTitle:@"退出摸鱼(关闭悬浮层,回主窗口)" action:@selector(exitMoyu:) keyEquivalent:@""].target = self;
206
242
  self.mainMenu = menu;
207
243
  self.statusItem.menu = menu;
208
244
  /* buildWindow 先于 buildStatusItem 执行,这里补挂右键菜单 */
@@ -292,14 +328,9 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
292
328
  }
293
329
 
294
330
  - (void)chooseFollowWindow:(id)sender {
295
- if (!CGPreflightScreenCaptureAccess()) {
296
- CGRequestScreenCaptureAccess();
297
- [self showPermissionGuide];
298
- return;
299
- }
300
331
  NSArray<NSDictionary *> *rows = [self visibleWindows];
301
- /* 只有一个窗口 = 权限没生效,仍是我们自己 */
302
- if (rows.count == 0) {
332
+ if (rows.count == 0 || !GufaRowsHaveForeignWindows(rows)) {
333
+ CGRequestScreenCaptureAccess();
303
334
  [self showPermissionGuide];
304
335
  return;
305
336
  }
@@ -405,16 +436,39 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
405
436
  [self saveFrame];
406
437
  }
407
438
 
408
- - (void)quitApp:(id)sender {
439
+ /* 退出摸鱼:恢复主窗口(DeepSeek Harness)到前台,然后关掉悬浮层 */
440
+ - (void)exitMoyu:(id)sender {
441
+ [self restoreMainWindow];
409
442
  [self stopFollowTimer];
410
443
  [self saveFrame];
411
444
  [NSApp terminate:nil];
412
445
  }
413
446
 
447
+ - (void)restoreMainWindow {
448
+ NSArray<NSRunningApplication *> *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.deepseek.dsh"];
449
+ for (NSRunningApplication *app in apps) {
450
+ [app activateWithOptions:NSApplicationActivateAllWindows];
451
+ }
452
+ }
453
+
414
454
  - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return YES; }
415
455
 
416
456
  @end
417
457
 
458
+ /* SIGTERM(Host 的 float.stop)→ 先恢复主窗口再退出,避免「摸鱼退出后主窗口不在前台」 */
459
+ static void GufaInstallTermHandler(void) {
460
+ signal(SIGTERM, SIG_IGN);
461
+ dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
462
+ dispatch_source_set_event_handler(source, ^{
463
+ NSArray<NSRunningApplication *> *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.deepseek.dsh"];
464
+ for (NSRunningApplication *app in apps) {
465
+ [app activateWithOptions:NSApplicationActivateAllWindows];
466
+ }
467
+ [NSApp terminate:nil];
468
+ });
469
+ dispatch_resume(source);
470
+ }
471
+
418
472
  static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) {
419
473
  (void)nextHandler;
420
474
  (void)event;
@@ -423,8 +477,102 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
423
477
  return noErr;
424
478
  }
425
479
 
480
+ /* ── 窗口列表模式:gufa-float --list-windows ─────────────────────── */
481
+
482
+ static NSArray<NSDictionary *> *GufaEnumerateWindows(void) {
483
+ NSMutableArray<NSDictionary *> *rows = [NSMutableArray array];
484
+ CFArrayRef list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
485
+ if (list == NULL) return rows;
486
+ NSInteger count = CFArrayGetCount(list);
487
+ pid_t selfPid = NSProcessInfo.processInfo.processIdentifier;
488
+ NSMutableDictionary<NSNumber *, NSData *> *iconCache = [NSMutableDictionary dictionary];
489
+ for (NSInteger i = 0; i < count && rows.count < 60; i++) {
490
+ NSDictionary *info = (__bridge NSDictionary *)CFArrayGetValueAtIndex(list, i);
491
+ NSNumber *layer = info[(id)kCGWindowLayer];
492
+ if (![layer isKindOfClass:[NSNumber class]] || layer.intValue != 0) continue;
493
+ NSNumber *pid = info[(id)kCGWindowOwnerPID];
494
+ if (![pid isKindOfClass:[NSNumber class]] || pid.intValue == selfPid) continue;
495
+ NSNumber *number = info[(id)kCGWindowNumber];
496
+ NSDictionary *bounds = info[(id)kCGWindowBounds];
497
+ if (number == nil || bounds == nil) continue;
498
+ CGRect rect = CGRectZero;
499
+ if (!CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)bounds, &rect)) continue;
500
+ if (rect.size.width < 200 || rect.size.height < 140) continue;
501
+ NSString *owner = info[(id)kCGWindowOwnerName];
502
+ NSString *title = info[(id)kCGWindowName];
503
+ NSData *iconData = iconCache[pid];
504
+ if (iconData == nil) {
505
+ iconData = NSData.data;
506
+ NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier:(pid_t)pid.intValue];
507
+ NSImage *icon = app.icon;
508
+ if (icon != nil) {
509
+ NSImage *resized = [[NSImage alloc] initWithSize:NSMakeSize(32, 32)];
510
+ [resized lockFocus];
511
+ [icon drawInRect:NSMakeRect(0, 0, 32, 32) fromRect:NSZeroRect operation:NSCompositingOperationCopy fraction:1.0 respectFlipped:YES hints:nil];
512
+ [resized unlockFocus];
513
+ NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:resized.TIFFRepresentation];
514
+ NSData *png = [rep representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
515
+ if (png != nil) iconData = png;
516
+ }
517
+ iconCache[pid] = iconData;
518
+ }
519
+ [rows addObject:@{
520
+ @"windowNumber": number,
521
+ @"pid": pid,
522
+ @"owner": owner != nil ? owner : @"",
523
+ @"title": title != nil ? title : @"",
524
+ @"width": @(rect.size.width),
525
+ @"height": @(rect.size.height),
526
+ @"icon": [iconData base64EncodedStringWithOptions:0] ?: @"",
527
+ }];
528
+ }
529
+ CFRelease(list);
530
+ return rows;
531
+ }
532
+
533
+ static void GufaPrintPermissionResult(void) {
534
+ NSDictionary *out = @{@"ok": @NO, @"permission": @"screen-recording"};
535
+ NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
536
+ if (json != nil) fwrite(json.bytes, 1, json.length, stdout);
537
+ fputc('\n', stdout);
538
+ }
539
+
540
+ /** 没权限时 CGWindowList 只返回「自己这个 App」的窗口;据此判断权限,而不是信 CGPreflight。 */
541
+ static BOOL GufaRowsHaveForeignWindows(NSArray<NSDictionary *> *rows) {
542
+ NSString *own = NSProcessInfo.processInfo.processName;
543
+ for (NSDictionary *row in rows) {
544
+ NSString *owner = row[@"owner"];
545
+ if ([owner isKindOfClass:[NSString class]] && owner.length > 0
546
+ && ![owner isEqualToString:@"DeepSeek Harness"] && ![owner isEqualToString:own]) {
547
+ return YES;
548
+ }
549
+ }
550
+ return NO;
551
+ }
552
+
553
+ static int GufaListWindowsMode(void) {
554
+ NSArray<NSDictionary *> *rows = GufaEnumerateWindows();
555
+ if (rows.count == 0 || !GufaRowsHaveForeignWindows(rows)) {
556
+ /* 触发一次系统授权提示(授权后重新点「重试」即可) */
557
+ CGRequestScreenCaptureAccess();
558
+ GufaPrintPermissionResult();
559
+ return 2;
560
+ }
561
+ NSDictionary *out = @{@"ok": @YES, @"windows": rows};
562
+ NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
563
+ fwrite(json.bytes, 1, json.length, stdout);
564
+ fputc('\n', stdout);
565
+ return 0;
566
+ }
567
+
426
568
  int main(int argc, const char *argv[]) {
569
+ if (argc > 1 && strcmp(argv[1], "--list-windows") == 0) {
570
+ @autoreleasepool {
571
+ return GufaListWindowsMode();
572
+ }
573
+ }
427
574
  @autoreleasepool {
575
+ GufaInstallTermHandler();
428
576
  [NSApplication sharedApplication];
429
577
  [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
430
578
  GufaAppDelegate *delegate = [[GufaAppDelegate alloc] init];
@@ -0,0 +1,39 @@
1
+ # 已知坑(踩过的,别再踩)
2
+
3
+ > 这份清单记录已经犯过、并且容易再犯的错误。加新功能前先扫一遍。
4
+
5
+ ## 1. 古法编程里的浮层会被右侧停靠会话盖住(反复踩)
6
+
7
+ **现象**:弹窗/菜单只显示一半;关闭按钮点不到;列表被右侧「古法 AI」聊天栏压住;点击穿透的弹窗挡在聊天栏下面。
8
+
9
+ **原因**:
10
+ - 古法编程的所有界面都在 `.gufa-overlay-root` 里,它是 `z-index:1` 的层叠上下文;
11
+ - 右侧停靠的官方会话根节点是 **body 级** `position:fixed; z-index:2147483040`;
12
+ - 所以 root 内弹窗自己的 `z-index` 写多大都没用,出不了 root 的层叠上下文,必然被会话盖住。
13
+
14
+ **正确做法(三选一)**:
15
+ 1. 古法自己的弹窗/菜单:打开时把 root 抬起来 —— 现有 `59-popup-layer.js` 会自动检测 root 内出现的
16
+ `[role=menu] / [role=dialog] / [role=listbox] / .gufa-modal / .gufa-float-backdrop` 等,
17
+ 给 `<html>` 加 `data-gufa-popup`,CSS 把 `.gufa-overlay-root` 抬到 `z-index:2147483300`;
18
+ 新增全屏浮层时**必须**把它的类名加进 `59-popup-layer.js` 的 SELECTOR。
19
+ 2. 外部(DSH 官方)弹窗:`59-dialog-layer.js` 检测 body 级 `[role="dialog"][aria-modal="true"]`,
20
+ 加 `data-gufa-external-modal`,CSS 把停靠会话降到 `z-index:2`。
21
+ 3. 任何新浮层提交前:**在有右侧会话打开的情况下**实测它是否完整可见、可关闭。
22
+
23
+ **禁止**:只在浮层自身上写一个很高的 `z-index` 就交付。
24
+
25
+ ## 2. macOS 屏幕录制权限 + 悬浮层 helper
26
+
27
+ - helper 每次重新编译(代码签名变化)后,TCC 里旧的「屏幕录制」授权可能失效;
28
+ - `CGPreflightScreenCaptureAccess()` **不可靠**:可能返回 true,但 `CGWindowListCopyWindowInfo`
29
+ 只返回自己 App 的窗口(表现为摸鱼列表里只有 DeepSeek Harness 自己);
30
+ - 判断权限要**看列表内容**:是否出现非 `DeepSeek Harness` 的 owner(helper 里 `GufaRowsHaveForeignWindows`);
31
+ - 授权对象是 **DeepSeek Harness**(helper 以它作为 responsible app 继承权限);
32
+ 授权后如果列表仍只显示自己,**重启一次 DeepSeek Harness** 再试。
33
+
34
+ ## 3. Monaco worker:dsh-app:// 下不能 importScripts 相对路径
35
+
36
+ - 现象:Git diff 永远没有红绿、`getLineChanges()` 一直为空;
37
+ - 原因:页面源是 `dsh-app://`,Monaco 默认 blob worker 里 `importScripts('/gufa-code/...')` 是非法 URL;
38
+ - 修法:worker 用同源 `vendor/monaco/vs/worker-bootstrap.js` 作为入口,里面只做
39
+ `MonacoEnvironment.baseUrl` + `importScripts(workerMain.js)`;**不要**先加载 AMD `loader.js`(模块系统冲突)。
package/host/dev.js CHANGED
@@ -3,7 +3,8 @@
3
3
  * 旧版本 Host(没有本方法)会让 api('dev.version') 返回 not-found,客户端据此提示重启 Harness。
4
4
  */
5
5
  import { appendFileSync, existsSync } from 'node:fs'
6
- import { spawn } from 'node:child_process'
6
+ import { execFile, spawn } from 'node:child_process'
7
+ import { promisify } from 'node:util'
7
8
  import { dirname, join } from 'node:path'
8
9
  import { fileURLToPath } from 'node:url'
9
10
  import { ApiError } from './context.js'
@@ -12,6 +13,7 @@ const DEBUG_LOG_PATH = '/tmp/gufa-code-debug.log'
12
13
  const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
13
14
  /* 悬浮层子进程放在 globalThis:host 模块热重载后仍能持有同一个句柄 */
14
15
  const floatState = globalThis.__gufaFloatState ?? (globalThis.__gufaFloatState = { child: null, startedAt: 0 })
16
+ const runFile = promisify(execFile)
15
17
 
16
18
  /** 查找当前平台编译好的悬浮层 helper(P0 只支持 macOS)。 */
17
19
  function floatBinaryPath() {
@@ -50,11 +52,59 @@ export function register(router, env) {
50
52
  binary: floatBinaryPath(),
51
53
  }))
52
54
 
53
- router.method('float.start', async () => {
55
+ /** 列出可吸附的 App 窗口(spawn helper 的 --list-windows 模式,JSON 输出)。 */
56
+ router.method('float.windows', async () => {
57
+ if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
58
+ const binary = floatBinaryPath()
59
+ if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建,请先运行 scripts/build-float-macos.sh', 500)
60
+ let stdout = ''
61
+ try {
62
+ const result = await runFile(binary, ['--list-windows'], { timeout: 10_000, maxBuffer: 8 * 1024 * 1024 })
63
+ stdout = String(result.stdout ?? '')
64
+ } catch (error) {
65
+ stdout = String(error && error.stdout || '')
66
+ }
67
+ const line = stdout.trim().split('\n').filter(Boolean).pop() ?? ''
68
+ let parsed = null
69
+ try {
70
+ parsed = JSON.parse(line)
71
+ } catch {
72
+ parsed = null
73
+ }
74
+ if (parsed === null) throw new ApiError('list-failed', '读取窗口列表失败(helper 无输出)', 500)
75
+ return parsed
76
+ })
77
+
78
+ router.method('float.openPrivacy', async () => {
79
+ if (process.platform !== 'darwin') return { ok: false }
80
+ try {
81
+ spawn('open', ['x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture'], { detached: true, stdio: 'ignore' }).unref()
82
+ return { ok: true }
83
+ } catch {
84
+ return { ok: false }
85
+ }
86
+ })
87
+
88
+ router.method('float.start', async (body) => {
54
89
  if (process.platform !== 'darwin') throw new ApiError('unsupported', '桌面悬浮层目前只支持 macOS', 400)
55
90
  const binary = floatBinaryPath()
56
91
  if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建,请先运行 scripts/build-float-macos.sh', 500)
57
- if (floatRunning()) return { running: true, pid: floatState.child.pid }
92
+ const follow = body !== null && typeof body === 'object' && body.follow !== null && typeof body.follow === 'object'
93
+ ? { windowNumber: Number(body.follow.windowNumber) || 0, pid: Number(body.follow.pid) || 0 }
94
+ : null
95
+ if (follow !== null && follow.windowNumber > 0) {
96
+ /* 切换摸鱼目标:先关掉旧悬浮层再起一个新的 */
97
+ if (floatRunning()) {
98
+ try {
99
+ floatState.child.kill('SIGTERM')
100
+ } catch {
101
+ /* ignore */
102
+ }
103
+ await new Promise((resolve) => setTimeout(resolve, 500))
104
+ }
105
+ } else if (floatRunning()) {
106
+ return { running: true, pid: floatState.child.pid }
107
+ }
58
108
  let webServer
59
109
  let connection
60
110
  try {
@@ -68,7 +118,7 @@ export function register(router, env) {
68
118
  }
69
119
  const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
70
120
  const authUrl = connection.authenticatedUrl(`${base}/`)
71
- const payload = JSON.stringify({ authUrl, appUrl: `${base}/` })
121
+ const payload = JSON.stringify({ authUrl, appUrl: `${base}/`, follow: follow !== null && follow.windowNumber > 0 ? follow : undefined })
72
122
  let child
73
123
  try {
74
124
  child = spawn(binary, [payload], { detached: true, stdio: 'ignore' })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.2.5",
3
+ "version": "1.3.1",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -1048,6 +1048,8 @@ html[data-gufa-float] #root .gufa-overlay-root *,
1048
1048
  html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
1049
1049
  /* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
1050
1050
  html[data-gufa-ide] .dsh-pet-root{z-index:2147483400!important}
1051
+ /* 古法自己的弹窗/菜单打开时:整个覆盖层临时抬到右侧停靠会话(z-index 2147483040)之上 */
1052
+ html[data-gufa-popup] .gufa-overlay-root{z-index:2147483300!important}
1051
1053
  /* 外部弹窗(DSH 设置等)打开时:停靠会话与桌宠降到弹窗之下,保证弹窗完整可点可关 */
1052
1054
  html[data-gufa-external-modal] [data-gufa-dock]{z-index:2!important}
1053
1055
  html[data-gufa-external-modal] .dsh-pet-root{z-index:2!important}
@@ -1114,6 +1116,24 @@ html[data-gufa-ide] [role="dialog"] {
1114
1116
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1115
1117
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1116
1118
  .gufa-session-group .gufa-session-row{margin-left:10px}
1119
+ /* 摸鱼模式:App 窗口选择器 */
1120
+ .gufa-float-backdrop{position:fixed;inset:0;z-index:2147483200;display:flex;align-items:center;justify-content:center;
1121
+ background:rgba(0,0,0,0.42);padding:24px;box-sizing:border-box}
1122
+ .gufa-float-picker{width:min(660px,92vw);max-height:min(640px,82vh);display:flex;flex-direction:column;
1123
+ background:var(--gufa-layer);border:1px solid var(--gufa-border-strong);border-radius:12px;overflow:hidden;
1124
+ box-shadow:0 24px 60px rgba(0,0,0,0.45)}
1125
+ .gufa-float-list{display:flex;flex-direction:column;gap:4px;padding:8px 10px;overflow:auto;min-height:120px}
1126
+ .gufa-float-row{display:flex;align-items:center;gap:10px;width:100%;padding:7px 10px;border:0;border-radius:9px;
1127
+ background:transparent;color:var(--gufa-text);font:inherit;text-align:left;cursor:pointer}
1128
+ .gufa-float-row:hover{background:var(--gufa-hover)}
1129
+ .gufa-float-row:disabled{opacity:0.55;cursor:default}
1130
+ .gufa-float-icon{width:26px;height:26px;object-fit:contain;flex:0 0 auto;border-radius:5px}
1131
+ .gufa-float-meta{display:flex;flex-direction:column;gap:1px;min-width:0;flex:1 1 auto}
1132
+ .gufa-float-owner{font-size:12.5px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1133
+ .gufa-float-title{font-size:11px;color:var(--gufa-text-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1134
+ .gufa-float-size{flex:0 0 auto;font-size:10.5px;color:var(--gufa-text-dim);font-variant-numeric:tabular-nums}
1135
+ .gufa-float-permission{padding:16px}
1136
+ .gufa-float-permission-title{font-size:13px;font-weight:600;margin-bottom:6px}
1117
1137
  .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1118
1138
  color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1119
1139
  .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * 59-popup-layer:弹窗/菜单层级修正。
3
+ *
4
+ * 背景(踩坑记录,见 docs/KNOWN-PITFALLS.md):
5
+ * 古法编程的界面都在 `.gufa-overlay-root`(z-index:1)这个层叠上下文里,而右侧停靠的
6
+ * 官方会话根节点是 body 级 fixed、z-index 2147483040。任何在 root 内部弹出的
7
+ * modal / menu / popover,如果只设自己的 z-index,都会被困在 root 的上下文里,
8
+ * 被停靠会话盖住(表现为「弹窗被右侧聊天挡一半、点不到关闭」)。
9
+ *
10
+ * 修法:检测 root 内是否出现 popup,出现时给 html 加 `data-gufa-popup`,
11
+ * 由 CSS 把整个 overlay root 临时抬到停靠会话之上。
12
+ */
13
+
14
+ G.installPopupLayerWatch = function installPopupLayerWatch(ctx) {
15
+ if (typeof document === 'undefined') return () => {}
16
+ const ATTR = 'data-gufa-popup'
17
+ const SELECTOR = [
18
+ '[role="menu"]',
19
+ '[role="listbox"]',
20
+ '[role="dialog"]',
21
+ '.gufa-modal',
22
+ '.gufa-float-backdrop',
23
+ '.gufa-branch-dialog-backdrop',
24
+ '.gufa-session-backdrop',
25
+ '.gufa-shortcuts-backdrop',
26
+ ].join(',')
27
+
28
+ const sync = () => {
29
+ try {
30
+ const root = document.querySelector('.gufa-root')
31
+ const popup = root === null ? null : root.querySelector(SELECTOR)
32
+ const open = popup !== null
33
+ if ((document.documentElement.getAttribute(ATTR) === '1') === open) return
34
+ if (open) document.documentElement.setAttribute(ATTR, '1')
35
+ else document.documentElement.removeAttribute(ATTR)
36
+ } catch {
37
+ /* ignore */
38
+ }
39
+ }
40
+
41
+ let observer = null
42
+ try {
43
+ observer = new MutationObserver(sync)
44
+ observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'style', 'data-state', 'aria-hidden'] })
45
+ } catch {
46
+ observer = null
47
+ }
48
+ sync()
49
+ const timer = window.setInterval(sync, 400)
50
+ return () => {
51
+ if (observer !== null) observer.disconnect()
52
+ window.clearInterval(timer)
53
+ document.documentElement.removeAttribute(ATTR)
54
+ }
55
+ }
@@ -157,6 +157,8 @@ G.GufaApp = function GufaApp(props) {
157
157
  const [sessionsOpen, setSessionsOpen] = useState(false)
158
158
  const [floatRunning, setFloatRunning] = useState(false)
159
159
  const [floatBusy, setFloatBusy] = useState(false)
160
+ /* 摸鱼窗口选择器:null | {status:'loading'|'ready'|'permission'|'error', windows:[], error:''} */
161
+ const [floatPicker, setFloatPicker] = useState(null)
160
162
  /* 会话弹窗里选中的工作区(null = 跟随当前 IDE 项目) */
161
163
  const [sessionWorkspacePath, setSessionWorkspacePath] = useState(null)
162
164
  const [sessionWorkspacePicker, setSessionWorkspacePicker] = useState(false)
@@ -829,25 +831,78 @@ G.GufaApp = function GufaApp(props) {
829
831
  return () => { cancelled = true }
830
832
  }, [])
831
833
 
832
- const toggleFloatWindow = useCallback(async () => {
834
+ /* 退出摸鱼:关掉悬浮层(helper 会把主窗口唤回前台) */
835
+ const stopFloatWindow = useCallback(async () => {
833
836
  if (floatBusy) return
834
837
  setFloatBusy(true)
835
838
  try {
836
- if (floatRunning) {
837
- await G.api('float.stop')
838
- setFloatRunning(false)
839
- setBanner('悬浮层已关闭')
839
+ await G.api('float.stop')
840
+ setFloatRunning(false)
841
+ setBanner('已退出摸鱼:主窗口已恢复')
842
+ } catch (error) {
843
+ setBanner(G.errorText(error))
844
+ } finally {
845
+ setFloatBusy(false)
846
+ }
847
+ }, [floatBusy])
848
+
849
+ /* 拉取可吸附的 App 窗口列表(摸鱼列表) */
850
+ const openFloatPicker = useCallback(async () => {
851
+ if (floatBusy) return
852
+ setFloatPicker({ status: 'loading', windows: [], error: '' })
853
+ try {
854
+ const value = await G.api('float.windows')
855
+ if (value?.ok === true && Array.isArray(value.windows)) {
856
+ setFloatPicker({ status: 'ready', windows: value.windows, error: '' })
857
+ } else if (value?.ok === false && value?.permission === 'screen-recording') {
858
+ setFloatPicker({ status: 'permission', windows: [], error: '' })
840
859
  } else {
841
- const value = await G.api('float.start')
842
- setFloatRunning(value?.running === true)
843
- setBanner('悬浮层已启动:屏幕上的半透明窗口,菜单栏「古法」可切换点击穿透')
860
+ setFloatPicker({ status: 'error', windows: [], error: '没有读到可吸附的窗口' })
844
861
  }
862
+ } catch (error) {
863
+ setFloatPicker({ status: 'error', windows: [], error: G.errorText(error) })
864
+ }
865
+ }, [floatBusy])
866
+
867
+ /* 选中某个 App 窗口 → 启动悬浮层并吸附它 */
868
+ const startFloatForWindow = useCallback(async (target) => {
869
+ if (floatBusy || target === null || target === undefined) return
870
+ setFloatBusy(true)
871
+ try {
872
+ const value = await G.api('float.start', {
873
+ follow: { windowNumber: Number(target.windowNumber) || 0, pid: Number(target.pid) || 0 },
874
+ })
875
+ setFloatRunning(value?.running === true)
876
+ setFloatPicker(null)
877
+ const name = typeof target.owner === 'string' && target.owner !== '' ? target.owner : '所选窗口'
878
+ setBanner(`摸鱼模式已开启:已吸附 ${name};⌃⌥⌘G 切换点击穿透,菜单栏「古法」可退出`)
879
+ } catch (error) {
880
+ setBanner(G.errorText(error))
881
+ } finally {
882
+ setFloatBusy(false)
883
+ }
884
+ }, [floatBusy])
885
+
886
+ /* 自由悬浮(不吸附窗口) */
887
+ const startFloatFree = useCallback(async () => {
888
+ if (floatBusy) return
889
+ setFloatBusy(true)
890
+ try {
891
+ const value = await G.api('float.start')
892
+ setFloatRunning(value?.running === true)
893
+ setFloatPicker(null)
894
+ setBanner('悬浮层已启动(自由悬浮)')
845
895
  } catch (error) {
846
896
  setBanner(G.errorText(error))
847
897
  } finally {
848
898
  setFloatBusy(false)
849
899
  }
850
- }, [floatBusy, floatRunning])
900
+ }, [floatBusy])
901
+
902
+ const toggleFloatWindow = useCallback(() => {
903
+ if (floatRequested === true || floatRunning) void stopFloatWindow()
904
+ else void openFloatPicker()
905
+ }, [floatRequested, floatRunning, stopFloatWindow, openFloatPicker])
851
906
 
852
907
  /* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
853
908
  * ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
@@ -1759,7 +1814,7 @@ G.GufaApp = function GufaApp(props) {
1759
1814
  }, h(G.Icon, { name: 'image', size: 16 }))
1760
1815
  : null,
1761
1816
  h(G.IconButton, {
1762
- title: floatRunning ? '关闭桌面悬浮层' : '打开桌面悬浮层(半透明置顶窗口)',
1817
+ title: floatRequested === true || floatRunning ? '退出摸鱼(关闭悬浮层,回主窗口)' : '进入摸鱼模式:选择一个 App 吸附并悬浮',
1763
1818
  'data-active': floatRunning ? '' : undefined,
1764
1819
  disabled: floatBusy,
1765
1820
  onClick: () => void toggleFloatWindow(),
@@ -2085,6 +2140,80 @@ G.GufaApp = function GufaApp(props) {
2085
2140
  ),
2086
2141
  /* 弹窗 */
2087
2142
  modal === null ? null : renderModal(),
2143
+ floatPicker !== null
2144
+ ? h(
2145
+ 'div',
2146
+ {
2147
+ className: 'gufa-float-backdrop',
2148
+ onMouseDown: (event) => { if (event.target === event.currentTarget) setFloatPicker(null) },
2149
+ },
2150
+ h(
2151
+ 'div',
2152
+ { className: 'gufa-float-picker', role: 'dialog', 'aria-modal': 'true', 'aria-label': '选择要摸鱼的 App' },
2153
+ h(
2154
+ 'div',
2155
+ { className: 'gufa-modal-head' },
2156
+ h(G.Icon, { name: 'monitor', size: 15 }),
2157
+ h('span', { style: { flex: '1 1 auto' } }, '摸鱼模式:选择要吸附的 App'),
2158
+ h(G.IconButton, { title: t('common.close'), onClick: () => setFloatPicker(null) }, h(G.Icon, { name: 'close', size: 14 })),
2159
+ ),
2160
+ floatPicker.status === 'loading'
2161
+ ? h('div', { className: 'gufa-graph-loading', style: { height: 90 } }, h(G.Spinner), '正在读取窗口列表…')
2162
+ : floatPicker.status === 'permission'
2163
+ ? h(
2164
+ 'div',
2165
+ { className: 'gufa-float-permission' },
2166
+ h('div', { className: 'gufa-float-permission-title' }, '需要「屏幕录制」权限'),
2167
+ h('div', { className: 'gufa-hint' }, '摸鱼列表需要读取其他 App 的窗口尺寸(只读尺寸,不录屏)。请在「系统设置 → 隐私与安全性 → 屏幕录制」里勾选 **DeepSeek Harness**(若列表只显示自己,请重启一次 DeepSeek Harness 让权限生效),然后点「重试」。'),
2168
+ h(
2169
+ 'div',
2170
+ { className: 'gufa-row', style: { gap: 8, marginTop: 12 } },
2171
+ h(G.Button, { primary: true, onClick: () => void G.api('float.openPrivacy').catch(() => {}) }, '打开系统设置'),
2172
+ h(G.Button, { onClick: () => void openFloatPicker() }, '重试'),
2173
+ ),
2174
+ )
2175
+ : floatPicker.status === 'error'
2176
+ ? h('div', { className: 'gufa-float-permission' }, h('div', { className: 'gufa-error-banner' }, floatPicker.error))
2177
+ : floatPicker.windows.length === 0
2178
+ ? h('div', { className: 'gufa-hint', style: { padding: 16 } }, '没有可吸附的窗口')
2179
+ : h(
2180
+ 'div',
2181
+ { className: 'gufa-float-list gufa-scroll' },
2182
+ floatPicker.windows.map((win, index) =>
2183
+ h(
2184
+ 'button',
2185
+ {
2186
+ key: `${win.pid}:${win.windowNumber}:${index}`,
2187
+ type: 'button',
2188
+ className: 'gufa-float-row',
2189
+ title: `${win.owner} — ${win.title}`,
2190
+ disabled: floatBusy,
2191
+ onClick: () => void startFloatForWindow(win),
2192
+ },
2193
+ win.icon !== undefined && win.icon !== ''
2194
+ ? h('img', { className: 'gufa-float-icon', src: `data:image/png;base64,${win.icon}`, alt: '' })
2195
+ : h(G.Icon, { name: 'monitor', size: 26 }),
2196
+ h(
2197
+ 'span',
2198
+ { className: 'gufa-float-meta' },
2199
+ h('span', { className: 'gufa-float-owner' }, win.owner !== '' ? win.owner : '未知 App'),
2200
+ h('span', { className: 'gufa-float-title' }, win.title !== '' ? win.title : '(无标题窗口)'),
2201
+ ),
2202
+ h('span', { className: 'gufa-float-size' }, `${Math.round(win.width)}×${Math.round(win.height)}`),
2203
+ ),
2204
+ ),
2205
+ ),
2206
+ h(
2207
+ 'div',
2208
+ { className: 'gufa-modal-foot' },
2209
+ h(G.IconButton, { title: '刷新列表', onClick: () => void openFloatPicker() }, h(G.Icon, { name: 'refresh', size: 14 })),
2210
+ h('span', { style: { flex: '1 1 auto' } }),
2211
+ h(G.Button, { onClick: () => void startFloatFree() }, '自由悬浮(不吸附)'),
2212
+ h(G.Button, { onClick: () => setFloatPicker(null) }, t('common.close')),
2213
+ ),
2214
+ ),
2215
+ )
2216
+ : null,
2088
2217
  sessionsOpen ? renderSessionsDialog() : null,
2089
2218
  shortcutsOpen ? renderShortcutsDialog() : null,
2090
2219
  )
@@ -256,6 +256,16 @@ const GUFA_PLUGIN = {
256
256
  window.setTimeout(cleanStaleSidebarLayouts, 1500)
257
257
  window.setTimeout(cleanStaleSidebarLayouts, 5000)
258
258
 
259
+ // 弹窗/菜单打开时把覆盖层整体抬到右侧停靠会话之上(否则会被盖住)
260
+ try {
261
+ if (typeof G.installPopupLayerWatch === 'function') {
262
+ const disposePopupWatch = G.installPopupLayerWatch(ctx)
263
+ if (typeof disposePopupWatch === 'function') ctx.effect(() => disposePopupWatch, 'gufa-code: popup layer watch')
264
+ }
265
+ } catch (error) {
266
+ console.error('[gufa-code] 安装弹窗层级监听失败', error)
267
+ }
268
+
259
269
  // 外部弹窗(设置等)打开时降低停靠层,避免遮挡弹窗导致关不掉
260
270
  try {
261
271
  if (typeof G.installDialogLayerWatch === 'function') {