dsh-gufa-code 1.3.48 → 1.3.50

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.
Files changed (30) hide show
  1. package/README.md +13 -5
  2. package/client.js +1 -1
  3. package/desktop/float/PLATFORM-PROTOCOL.md +120 -0
  4. package/desktop/float/bin/README.md +12 -0
  5. package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
  6. package/desktop/float/bin/gufa-float-macos-universal +0 -0
  7. package/desktop/float/bin/gufa-float-macos-x64 +0 -0
  8. package/desktop/float/bin/linux-x64/gufa-float-linux +0 -0
  9. package/desktop/float/bin/win-x64/gufa-float-win.exe +0 -0
  10. package/desktop/float/linux/Makefile +85 -0
  11. package/desktop/float/linux/README-LINUX.md +206 -0
  12. package/desktop/float/linux/json.c +498 -0
  13. package/desktop/float/linux/json.h +56 -0
  14. package/desktop/float/linux/log.c +48 -0
  15. package/desktop/float/linux/log.h +19 -0
  16. package/desktop/float/linux/main.c +1184 -0
  17. package/desktop/float/linux/x11.c +608 -0
  18. package/desktop/float/linux/x11.h +118 -0
  19. package/desktop/float/win/CMakeLists.txt +159 -0
  20. package/desktop/float/win/README-WIN.md +184 -0
  21. package/desktop/float/win/json.h +505 -0
  22. package/desktop/float/win/main.cpp +1935 -0
  23. package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
  24. package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
  25. package/docs/MODES.md +7 -0
  26. package/host/dev.js +254 -55
  27. package/package.json +1 -1
  28. package/scripts/build-float-linux.sh +15 -0
  29. package/scripts/build-float-macos.sh +43 -14
  30. package/scripts/build-float-win.ps1 +33 -0
@@ -7,8 +7,8 @@
7
7
  <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
8
8
  <key>CFBundleExecutable</key><string>gufa-float</string>
9
9
  <key>CFBundlePackageType</key><string>APPL</string>
10
- <key>CFBundleShortVersionString</key><string>1.3.1</string>
11
- <key>CFBundleVersion</key><string>1.3.1</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.48</string>
11
+ <key>CFBundleVersion</key><string>1.3.48</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
package/docs/MODES.md CHANGED
@@ -33,6 +33,13 @@
33
33
  - 退出摸鱼:悬浮窗把「项目 / 打开的标签页 / UI 布局 / 当前会话」写回 Host,然后优雅退出并恢复显示主窗口;
34
34
  主窗口重新获得焦点时自动取回并应用这些状态(项目 → 标签页 → 会话)。
35
35
 
36
+ ## 摸鱼模式跨平台实现
37
+
38
+ - helper 与 Host 的通信协议统一在 `desktop/float/PLATFORM-PROTOCOL.md`(argv JSON + controlPath 控制文件 + ciProbe 冒烟)。
39
+ - macOS:`desktop/float/GufaFloat.m`(已可用,universal arm64+x86_64);Windows:`desktop/float/win/`(Win32 + WebView2,首版不透明);Linux:`desktop/float/linux/`(X11 + GTK3/WebKit2GTK,仅 X11)。
40
+ - 后两者由 `.github/workflows/build-float.yml` 在 CI 编译 + ciProbe 冒烟,产物放到 `desktop/float/bin/{win-x64,linux-x64}/` 随 npm 包发布;真机交互仍在验收。
41
+ - Host 端 `host/dev.js` 的 `float.*` API 已按平台分支:darwin 用 .app + AX;win32/linux 用原生 helper + controlPath 退出,用 PowerShell/wmctrl 列窗口。
42
+
36
43
  ## 摸鱼模式现行限制
37
44
 
38
45
  - 只在独立悬浮窗实例里生效;主窗口永远走古法编程模式;
package/host/dev.js CHANGED
@@ -26,17 +26,58 @@ const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
26
26
  const floatState = globalThis.__gufaFloatState ?? (globalThis.__gufaFloatState = { child: null, startedAt: 0 })
27
27
  const runFile = promisify(execFile)
28
28
 
29
- /** 查找当前平台编译好的悬浮层 helper(P0 只支持 macOS)。 */
29
+ /** 查找当前平台编译好的悬浮层 helper。 */
30
30
  function floatBinaryPath() {
31
- const arch = process.arch === 'arm64' ? 'arm64' : 'x64'
32
- const candidates = [`gufa-float-macos-${arch}`, 'gufa-float-macos-arm64', 'gufa-float-macos-x64']
33
- for (const name of candidates) {
34
- const full = join(PLUGIN_ROOT, 'desktop', 'float', 'bin', name)
31
+ const root = join(PLUGIN_ROOT, 'desktop', 'float', 'bin')
32
+ let candidates = []
33
+ if (process.platform === 'darwin') {
34
+ const arch = process.arch === 'arm64' ? 'arm64' : 'x64'
35
+ candidates = [
36
+ join(root, `gufa-float-macos-${arch}`),
37
+ join(root, 'gufa-float-macos-universal'),
38
+ join(root, 'gufa-float-macos-arm64'),
39
+ join(root, 'gufa-float-macos-x64'),
40
+ ]
41
+ } else if (process.platform === 'win32') {
42
+ candidates = [
43
+ join(root, 'win-x64', 'gufa-float-win.exe'),
44
+ join(root, 'gufa-float-win.exe'),
45
+ ]
46
+ } else if (process.platform === 'linux') {
47
+ candidates = [
48
+ join(root, 'linux-x64', 'gufa-float-linux'),
49
+ join(root, 'linux-x64', 'gufa-float-linux-x64'),
50
+ join(root, 'gufa-float-linux'),
51
+ ]
52
+ }
53
+ for (const full of candidates) {
35
54
  if (existsSync(full)) return full
36
55
  }
37
56
  return null
38
57
  }
39
58
 
59
+ /** 当前平台是否支持摸鱼悬浮层(helper 未构建时返回原因)。 */
60
+ function floatSupportStatus() {
61
+ const binary = floatBinaryPath()
62
+ if (process.platform !== 'darwin' && process.platform !== 'win32' && process.platform !== 'linux') {
63
+ return { supported: false, reason: 'unsupported-platform', platform: process.platform, binary: null }
64
+ }
65
+ if (binary === null) {
66
+ return {
67
+ supported: false,
68
+ reason: 'missing-helper',
69
+ platform: process.platform,
70
+ binary: null,
71
+ hint: process.platform === 'darwin'
72
+ ? '运行 ./scripts/build-float-macos.sh 构建悬浮层'
73
+ : (process.platform === 'win32'
74
+ ? '按 desktop/float/win/README-WIN.md 用 CMake + WebView2 SDK 构建(CI windows job 会产出 gufa-float-win.exe)'
75
+ : '运行 ./scripts/build-float-linux.sh(或 CI 的 linux job 构建产物)'),
76
+ }
77
+ }
78
+ return { supported: true, reason: '', platform: process.platform, binary }
79
+ }
80
+
40
81
  function floatRunning() {
41
82
  return floatState.child !== null && floatState.child.exitCode === null && floatState.child.signalCode === null
42
83
  }
@@ -56,11 +97,17 @@ export function register(router, env) {
56
97
 
57
98
 
58
99
 
59
- /* ── 桌面悬浮层 / 摸鱼模式(macOS) ────────────────────────────────
60
- * 通过 .app bundle 启动 helper:TCC(屏幕录制)按 bundle 身份授权,
61
- * 用户在「系统设置 → 隐私与安全性 → 屏幕录制」里添加「古法编程悬浮层.app」即可。
100
+ /* ── 桌面悬浮层 / 摸鱼模式(跨平台:macOS / Windows / Linux) ─────────
101
+ * helper 协议见 desktop/float/PLATFORM-PROTOCOL.md:
102
+ * - Host 用 spawn(binary, [payloadJson]) 启动 helper;
103
+ * - 退出统一走 controlPath 控制文件(helper 自己恢复 DSH 主窗口后退出);
104
+ * - float.windows 统一返回 { ok, accessibility, apps:[{pid,owner,title,bundleId,windowNumber,icon}] }。
62
105
  */
106
+ const isMac = process.platform === 'darwin'
107
+ const isWin = process.platform === 'win32'
108
+ const isLinux = process.platform === 'linux'
63
109
  const appBundlePath = () => {
110
+ if (!isMac) return null
64
111
  const candidates = [
65
112
  join(PLUGIN_ROOT, 'desktop', 'float', '古法编程悬浮层.app'),
66
113
  join(PLUGIN_ROOT, 'desktop', 'float', 'GufaFloat.app'),
@@ -70,38 +117,77 @@ export function register(router, env) {
70
117
  }
71
118
  return null
72
119
  }
73
- const floatProcessPatterns = ['gufa-float-macos-', '古法编程悬浮层.app/Contents/MacOS/gufa-float']
120
+ const floatProcessPatterns = isMac
121
+ ? ['gufa-float-macos-', '古法编程悬浮层.app/Contents/MacOS/gufa-float']
122
+ : (isWin ? ['gufa-float-win'] : ['gufa-float-linux'])
74
123
 
124
+ /** 列出本插件的 helper 进程(优先用自己 spawn 的 child,再加系统进程扫描兜底)。 */
75
125
  const listFloatPids = async () => {
76
126
  const pids = new Set()
77
- for (const pattern of floatProcessPatterns) {
127
+ const tracked = floatState.child !== null && floatState.child.exitCode === null ? floatState.child.pid : null
128
+ if (Number.isFinite(tracked) && tracked > 0) pids.add(tracked)
129
+ if (isMac || isLinux) {
130
+ for (const pattern of floatProcessPatterns) {
131
+ try {
132
+ const { stdout } = await runFile('pgrep', ['-f', pattern], { timeout: 3000 })
133
+ for (const line of String(stdout ?? '').split('\n')) {
134
+ const pid = Number(line.trim())
135
+ if (Number.isFinite(pid) && pid > 0) pids.add(pid)
136
+ }
137
+ } catch {
138
+ /* 没匹配到 */
139
+ }
140
+ }
141
+ } else if (isWin) {
142
+ const alive = []
143
+ for (const pid of pids) {
144
+ try { process.kill(pid, 0); alive.push(pid) } catch { /* 已退出 */ }
145
+ }
146
+ pids.clear()
147
+ for (const pid of alive) pids.add(pid)
78
148
  try {
79
- const { stdout } = await runFile('pgrep', ['-f', pattern], { timeout: 3000 })
149
+ const { stdout } = await runFile('tasklist', ['/FI', 'IMAGENAME eq gufa-float-win.exe', '/FO', 'CSV', '/NH'], { timeout: 5000 })
80
150
  for (const line of String(stdout ?? '').split('\n')) {
81
- const pid = Number(line.trim())
82
- if (Number.isFinite(pid) && pid > 0) pids.add(pid)
151
+ const match = /^"([^"]+)","(\d+)"/.exec(line.trim())
152
+ if (match !== null) {
153
+ const pid = Number(match[2])
154
+ if (Number.isFinite(pid) && pid > 0) pids.add(pid)
155
+ }
83
156
  }
84
157
  } catch {
85
- /* 没匹配到 */
158
+ /* tasklist 不可用:只用 child pid */
86
159
  }
87
160
  }
88
161
  return [...pids]
89
162
  }
90
163
  const floatRunningAsync = async () => (await listFloatPids()).length > 0
91
164
 
92
- const openApp = (args) => new Promise((resolve, reject) => {
93
- const app = appBundlePath()
94
- if (app === null) {
95
- reject(new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500))
96
- return
165
+ /** 强制退出/异常兜底:把 DSH 主窗口恢复显示并前置(正常情况下 helper 自己会恢复)。 */
166
+ const restoreDshWindowFallback = async () => {
167
+ try {
168
+ if (isMac) {
169
+ spawn('/usr/bin/osascript', ['-e', 'tell application "System Events" to set visible of process "DeepSeek Harness" to true'], { detached: true, stdio: 'ignore' }).unref()
170
+ spawn('open', ['-b', 'com.deepseek.dsh'], { detached: true, stdio: 'ignore' }).unref()
171
+ } else if (isWin) {
172
+ const ps = [
173
+ "$sig = '[DllImport(\"user32.dll\")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport(\"user32.dll\")] public static extern bool SetForegroundWindow(IntPtr hWnd);'",
174
+ '$t = Add-Type -MemberDefinition $sig -Name Win32F -Namespace GufaF -PassThru',
175
+ "Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 -and $_.ProcessName -like '*DeepSeek*' } | ForEach-Object { [void]$t::ShowWindow($_.MainWindowHandle, 5); [void]$t::SetForegroundWindow($_.MainWindowHandle) }",
176
+ ].join('\n')
177
+ spawn('powershell', ['-NoProfile', '-NonInteractive', '-Command', ps], { detached: true, stdio: 'ignore' }).unref()
178
+ } else if (isLinux) {
179
+ for (const [command, args] of [['wmctrl', ['-a', 'DeepSeek Harness']], ['xdotool', ['search', '--name', 'DeepSeek Harness', 'windowactivate']]]) {
180
+ try {
181
+ spawn(command, args, { detached: true, stdio: 'ignore' }).unref()
182
+ } catch {
183
+ /* ignore */
184
+ }
185
+ }
186
+ }
187
+ } catch {
188
+ /* ignore */
97
189
  }
98
- const child = spawn('open', ['-n', app, '--args', ...args], { detached: true, stdio: 'ignore' })
99
- child.once('error', reject)
100
- child.once('exit', (code) => {
101
- if (code === 0) resolve()
102
- else reject(new ApiError('open-failed', `悬浮层启动失败(open exit ${code})`, 500))
103
- })
104
- })
190
+ }
105
191
 
106
192
  const killFloat = async () => {
107
193
  const pids = await listFloatPids()
@@ -117,35 +203,40 @@ export function register(router, env) {
117
203
  } catch {
118
204
  /* ignore */
119
205
  }
120
- const deadline = Date.now() + 4000
206
+ const deadline = Date.now() + 6000
121
207
  while (Date.now() < deadline) {
122
208
  if ((await listFloatPids()).length === 0) break
123
209
  await new Promise((resolve) => setTimeout(resolve, 150))
124
210
  }
125
211
  }
126
- /* 兜底:还在就 SIGTERM/SIGKILL;被强杀时用 osascript 把 DSH 主窗口恢复显示 */
212
+ /* 兜底:还在就强杀;被强杀时用平台命令把 DSH 主窗口恢复显示 */
127
213
  let forced = false
128
214
  for (const pid of await listFloatPids()) {
129
215
  forced = true
130
- try { process.kill(pid, 'SIGTERM') } catch { /* ignore */ }
131
- }
132
- await new Promise((resolve) => setTimeout(resolve, 400))
133
- for (const pid of await listFloatPids()) {
134
- forced = true
135
- try { process.kill(pid, 'SIGKILL') } catch { /* ignore */ }
136
- }
137
- if (forced) {
138
216
  try {
139
- spawn('/usr/bin/osascript', ['-e', 'tell application "System Events" to set visible of process "DeepSeek Harness" to true'], { detached: true, stdio: 'ignore' }).unref()
217
+ if (isWin) {
218
+ spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { detached: true, stdio: 'ignore' }).unref()
219
+ } else {
220
+ process.kill(pid, 'SIGTERM')
221
+ }
140
222
  } catch {
141
223
  /* ignore */
142
224
  }
225
+ }
226
+ await new Promise((resolve) => setTimeout(resolve, 500))
227
+ for (const pid of await listFloatPids()) {
228
+ forced = true
143
229
  try {
144
- spawn('open', ['-b', 'com.deepseek.dsh'], { detached: true, stdio: 'ignore' }).unref()
230
+ if (isWin) {
231
+ spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { detached: true, stdio: 'ignore' }).unref()
232
+ } else {
233
+ process.kill(pid, 'SIGKILL')
234
+ }
145
235
  } catch {
146
236
  /* ignore */
147
237
  }
148
238
  }
239
+ if (forced) await restoreDshWindowFallback()
149
240
  try {
150
241
  if (typeof floatState.controlPath === 'string' && floatState.controlPath !== '') await rm(floatState.controlPath, { force: true })
151
242
  } catch {
@@ -155,32 +246,135 @@ export function register(router, env) {
155
246
  floatState.child = null
156
247
  }
157
248
 
249
+ /** macOS:用 .app 身份启动 helper(列表接口的兜底路线,能继承/单独授权辅助功能)。 */
250
+ const openApp = (args) => new Promise((resolve, reject) => {
251
+ const app = appBundlePath()
252
+ if (app === null) {
253
+ reject(new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500))
254
+ return
255
+ }
256
+ const child = spawn('open', ['-n', app, '--args', ...args], { detached: true, stdio: 'ignore' })
257
+ child.once('error', reject)
258
+ child.once('exit', (code) => {
259
+ if (code === 0) resolve()
260
+ else reject(new ApiError('open-failed', `悬浮层启动失败(open exit ${code})`, 500))
261
+ })
262
+ })
263
+
264
+ /** Windows:PowerShell 枚举有主窗口的进程。 */
265
+ const listFloatWindowsWin = async () => {
266
+ const script = [
267
+ '$rows = @();',
268
+ "Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 -and $_.MainWindowTitle -ne '' } | ForEach-Object { $rows += [pscustomobject]@{ pid = $_.Id; owner = $_.ProcessName; title = $_.MainWindowTitle; bundleId = ''; windowNumber = [int64]$_.MainWindowHandle; frontmost = 0 } };",
269
+ "ConvertTo-Json -InputObject ([pscustomobject]@{ ok = $true; accessibility = $true; apps = @($rows) }) -Compress -Depth 5",
270
+ ].join('\n')
271
+ const { stdout } = await runFile('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], { timeout: 20_000, maxBuffer: 8 * 1024 * 1024 })
272
+ let parsed = null
273
+ try { parsed = JSON.parse(String(stdout ?? '').trim()) } catch { parsed = null }
274
+ if (parsed === null || parsed.ok !== true) throw new ApiError('list-failed', '读取 Windows 窗口列表失败', 500)
275
+ let apps = parsed.apps
276
+ if (!Array.isArray(apps)) apps = apps === null || apps === undefined ? [] : [apps]
277
+ apps = apps.filter((row) => row !== null && typeof row === 'object' && Number(row.pid) > 0 && typeof row.title === 'string' && row.title !== '')
278
+ return { ok: true, accessibility: true, apps }
279
+ }
280
+
281
+ /** Linux(X11):优先用 helper 自己的 --list-windows(X11 直读,无需 wmctrl),失败再退回 wmctrl。 */
282
+ const listFloatWindowsLinux = async () => {
283
+ const support = floatSupportStatus()
284
+ if (support.supported && typeof support.binary === 'string') {
285
+ const outPath = join(tmpdir(), `gufa-float-win-list-${process.pid}-${Date.now()}.json`)
286
+ try {
287
+ await runFile(support.binary, ['--list-windows', '--out', outPath], { timeout: 12_000 })
288
+ const raw = await readFile(outPath, 'utf8')
289
+ const parsed = JSON.parse(raw.trim())
290
+ if (parsed !== null && parsed.ok === true && Array.isArray(parsed.apps)) {
291
+ await rm(outPath, { force: true }).catch(() => {})
292
+ return { ok: true, accessibility: true, apps: parsed.apps }
293
+ }
294
+ } catch {
295
+ /* helper 不支持/失败:退回 wmctrl */
296
+ }
297
+ try { await rm(outPath, { force: true }) } catch { /* ignore */ }
298
+ }
299
+ let stdout = ''
300
+ try {
301
+ ({ stdout } = await runFile('wmctrl', ['-lp'], { timeout: 6000 }))
302
+ } catch {
303
+ throw new ApiError('missing-tool', 'Linux 下列出窗口失败:请重新构建 helper,或安装 wmctrl(sudo apt install wmctrl)', 500)
304
+ }
305
+ const apps = []
306
+ const seen = new Set()
307
+ for (const line of String(stdout ?? '').split('\n')) {
308
+ const match = /^0x[0-9a-fA-F]+\s+\d+\s+(\d+)\s+(.*)$/.exec(line.trim())
309
+ if (match === null) continue
310
+ const pid = Number(match[1])
311
+ const title = match[2].trim()
312
+ if (!Number.isFinite(pid) || pid <= 0 || title === '') continue
313
+ const key = `${pid}:${title}`
314
+ if (seen.has(key)) continue
315
+ seen.add(key)
316
+ let owner = String(pid)
317
+ try {
318
+ owner = readFileSync(`/proc/${pid}/comm`, 'utf8').trim() || owner
319
+ } catch {
320
+ /* ignore */
321
+ }
322
+ apps.push({ pid, owner, title, bundleId: owner, windowNumber: apps.length + 1, frontmost: 0 })
323
+ }
324
+ return { ok: true, accessibility: true, apps }
325
+ }
326
+
158
327
  router.method('float.status', async () => {
328
+ const support = floatSupportStatus()
159
329
  const running = await floatRunningAsync()
160
330
  return {
161
- supported: process.platform === 'darwin' && appBundlePath() !== null,
331
+ supported: support.supported,
162
332
  platform: process.platform,
333
+ reason: support.reason,
334
+ hint: support.hint,
163
335
  running,
164
336
  pid: running ? (await listFloatPids())[0] ?? null : null,
165
- app: appBundlePath(),
337
+ app: isMac ? appBundlePath() : support.binary,
166
338
  }
167
339
  })
168
340
 
169
- /** 在 Finder 里显示悬浮层 App,便于用户在「屏幕录制」里手动添加。 */
341
+ /** 打开 helper 所在位置(macOS 在 Finder 显示 App;Windows 在资源管理器选中 exe;Linux 打开目录)。 */
170
342
  router.method('float.revealHelper', async () => {
171
- const app = appBundlePath()
172
- if (app === null) throw new ApiError('missing-helper', '悬浮层 App 未构建', 500)
343
+ const support = floatSupportStatus()
344
+ if (isMac) {
345
+ const app = appBundlePath()
346
+ if (app === null) throw new ApiError('missing-helper', '悬浮层 App 未构建', 500)
347
+ try {
348
+ spawn('open', ['-R', app], { detached: true, stdio: 'ignore' }).unref()
349
+ return { ok: true, app }
350
+ } catch {
351
+ return { ok: false, app }
352
+ }
353
+ }
354
+ if (!support.supported) throw new ApiError('missing-helper', support.hint ?? '悬浮层程序未构建', 500)
173
355
  try {
174
- spawn('open', ['-R', app], { detached: true, stdio: 'ignore' }).unref()
175
- return { ok: true, app }
356
+ if (isWin) spawn('explorer', ['/select,', support.binary], { detached: true, stdio: 'ignore' }).unref()
357
+ else spawn('xdg-open', [dirname(support.binary)], { detached: true, stdio: 'ignore' }).unref()
358
+ return { ok: true, app: support.binary }
176
359
  } catch {
177
- return { ok: false, app }
360
+ return { ok: false, app: support.binary }
178
361
  }
179
362
  })
180
363
 
181
- /** 列出可吸附的 App 窗口(通过 .app 身份启动 helper,输出到临时文件)。 */
364
+ /** 列出可吸附的 App 窗口(三平台统一返回 {ok, accessibility, apps})。 */
182
365
  router.method('float.windows', async () => {
183
- if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
366
+ const support = floatSupportStatus()
367
+ if (!support.supported) {
368
+ const message = support.reason === 'unsupported-platform'
369
+ ? '摸鱼模式暂不支持当前平台'
370
+ : (support.hint ?? '悬浮层程序未构建')
371
+ throw new ApiError('unsupported', message, 400)
372
+ }
373
+ if (!isMac) {
374
+ const list = isWin ? await listFloatWindowsWin() : await listFloatWindowsLinux()
375
+ debugLog(`float-windows platform=${process.platform} apps=${list.apps.length}`)
376
+ return list
377
+ }
184
378
  if (appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
185
379
  const binary = floatBinaryPath()
186
380
  const outPath = join(tmpdir(), `gufa-float-windows-${process.pid}-${Date.now()}.json`)
@@ -203,7 +397,6 @@ export function register(router, env) {
203
397
  }
204
398
  }
205
399
  try {
206
- /* 路线 A:直接从 Host 进程 spawn(responsible app = DeepSeek Harness,可继承 DSH 的屏幕录制授权) */
207
400
  if (binary !== null) {
208
401
  try {
209
402
  await runFile(binary, ['--list-windows', '--out', outPath], { timeout: 12_000 })
@@ -215,7 +408,6 @@ export function register(router, env) {
215
408
  if (parsed !== null && parsed.ok === true) return parsed
216
409
  try { await rm(outPath, { force: true }) } catch { /* ignore */ }
217
410
  }
218
- /* 路线 B:通过 .app 身份启动(用户给「古法编程悬浮层.app」单独授权) */
219
411
  await openApp(['--list-windows', '--out', outPath])
220
412
  const parsed = await readResult()
221
413
  debugLog(`float-windows route=app ok=${String(parsed !== null && parsed.ok === true)} permission=${String(parsed !== null ? parsed.permission : 'none')}`)
@@ -231,7 +423,7 @@ export function register(router, env) {
231
423
  })
232
424
 
233
425
  router.method('float.openPrivacy', async () => {
234
- if (process.platform !== 'darwin') return { ok: false }
426
+ if (!isMac) return { ok: false }
235
427
  try {
236
428
  spawn('open', ['x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility'], { detached: true, stdio: 'ignore' }).unref()
237
429
  return { ok: true }
@@ -241,8 +433,14 @@ export function register(router, env) {
241
433
  })
242
434
 
243
435
  router.method('float.start', async (body) => {
244
- if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
245
- if (appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
436
+ const support = floatSupportStatus()
437
+ if (!support.supported) {
438
+ const message = support.reason === 'unsupported-platform'
439
+ ? '摸鱼模式暂不支持当前平台'
440
+ : (support.hint ?? '悬浮层程序未构建')
441
+ throw new ApiError('unsupported', message, 400)
442
+ }
443
+ if (isMac && appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
246
444
  const follow = body !== null && typeof body === 'object' && body.follow !== null && typeof body.follow === 'object'
247
445
  ? {
248
446
  pid: Number(body.follow.pid) || 0,
@@ -264,7 +462,7 @@ export function register(router, env) {
264
462
  const authUrl = connection.authenticatedUrl(`${base}/`)
265
463
  const state = body !== null && typeof body === 'object' && body.state !== null && typeof body.state === 'object' ? body.state : null
266
464
  try {
267
- debugLog(`float-start-state project=${String(state !== null && state.projectRoot) } tabs=${state !== null && Array.isArray(state.tabs) ? state.tabs.length : 'none'} active=${state !== null && typeof state.activePath === 'string' ? state.activePath : 'none'} ui=${state !== null && state.ui !== null && typeof state.ui === 'object' ? JSON.stringify(state.ui) : 'none'} session=${state !== null && typeof state.sessionId === 'string' ? state.sessionId : 'none'}`)
465
+ debugLog(`float-start-state platform=${process.platform} project=${String(state !== null && state.projectRoot) } tabs=${state !== null && Array.isArray(state.tabs) ? state.tabs.length : 'none'} active=${state !== null && typeof state.activePath === 'string' ? state.activePath : 'none'} ui=${state !== null && state.ui !== null && typeof state.ui === 'object' ? JSON.stringify(state.ui) : 'none'} session=${state !== null && typeof state.sessionId === 'string' ? state.sessionId : 'none'}`)
268
466
  } catch {
269
467
  /* ignore */
270
468
  }
@@ -279,12 +477,13 @@ export function register(router, env) {
279
477
  state: state ?? undefined,
280
478
  alpha: Number.isFinite(alphaPref) && alphaPref >= 20 && alphaPref <= 100 ? Math.round(alphaPref) : undefined,
281
479
  build: PLUGIN_VERSION,
480
+ ownerPid: process.ppid,
282
481
  controlPath,
283
482
  })
284
483
  floatState.controlPath = controlPath
285
484
  const binary = floatBinaryPath()
286
485
  if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建', 500)
287
- const child = spawn(binary, [payload], { detached: true, stdio: 'ignore' })
486
+ const child = spawn(binary, [payload], { detached: true, stdio: 'ignore', windowsHide: false })
288
487
  child.unref()
289
488
  floatState.child = child
290
489
  floatState.startedAt = Date.now()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.48",
3
+ "version": "1.3.50",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+ # 在 Linux 本机构建摸鱼悬浮层 helper(X11 + GTK3 + WebKit2GTK),并放到 host 期望的位置。
3
+ # 依赖:sudo apt install build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.1-dev
4
+ set -euo pipefail
5
+ cd "$(dirname "$0")/.."
6
+ if [ "$(uname -s)" != "Linux" ]; then
7
+ echo "build-float-linux.sh 只能在 Linux 上运行;macOS/Windows 请用 GitHub Actions(.github/workflows/build-float.yml)构建。" >&2
8
+ exit 1
9
+ fi
10
+ make -C desktop/float/linux -j"$(nproc)"
11
+ mkdir -p desktop/float/bin/linux-x64
12
+ cp desktop/float/linux/gufa-float-linux desktop/float/bin/linux-x64/gufa-float-linux
13
+ chmod +x desktop/float/bin/linux-x64/gufa-float-linux
14
+ echo "built: desktop/float/bin/linux-x64/gufa-float-linux"
15
+ echo "提示:列窗口需要 wmctrl(sudo apt install wmctrl),或直接用 helper 自带 --list-windows。"
@@ -1,22 +1,50 @@
1
1
  #!/usr/bin/env bash
2
- # 构建 macOS 悬浮层 helper(P0/P1):Objective-C + AppKit + WebKit。
3
- # 产物 1:可直接启动的二进制(Host spawn 用)
4
- # 产物 2:.app bundle(方便用户在「屏幕录制」隐私列表里手动添加)
2
+ # 构建 macOS 悬浮层 helper:Objective-C + AppKit + WebKit。
3
+ # 产物:
4
+ # desktop/float/bin/gufa-float-macos-arm64 (Apple Silicon)
5
+ # desktop/float/bin/gufa-float-macos-x64 (Intel)
6
+ # desktop/float/bin/gufa-float-macos-universal (通用二进制,两个架构都能跑)
7
+ # desktop/float/古法编程悬浮层.app (通用二进制 + ad-hoc 签名)
8
+ # 在 Apple Silicon 上也能交叉编译 x86_64(Xcode CLT 自带两套架构 SDK),
9
+ # 所以 npm 包可以只带 universal 一份、Intel/Apple Silicon 开箱即用。
5
10
  set -euo pipefail
6
11
  cd "$(dirname "$0")/.."
7
12
  mkdir -p desktop/float/bin
8
- ARCH="$(uname -m)"
9
- OUT="desktop/float/bin/gufa-float-macos-${ARCH}"
10
- clang -fobjc-arc -O2 -framework AppKit -framework WebKit -framework Carbon -o "$OUT" desktop/float/GufaFloat.m
11
- chmod +x "$OUT"
12
- # 带稳定的 code identifier 签名(TCC 按它识别,避免每次构建都换身份字符串)
13
- codesign --force --sign - -i com.gufa.float "$OUT" >/dev/null 2>&1 || true
13
+
14
+ VERSION="$(node -p "require('./package.json').version" 2>/dev/null || echo 0.0.0)"
15
+ SRC=desktop/float/GufaFloat.m
16
+ TMP_ARM="$(mktemp /tmp/gufa-float-arm64.XXXXXX)"
17
+ TMP_X64="$(mktemp /tmp/gufa-float-x64.XXXXXX)"
18
+ trap 'rm -f "$TMP_ARM" "$TMP_X64"' EXIT
19
+
20
+ compile_arch() {
21
+ local arch="$1" out="$2"
22
+ clang -fobjc-arc -O2 -arch "$arch" \
23
+ -framework AppKit -framework WebKit -framework Carbon \
24
+ -o "$out" "$SRC"
25
+ }
26
+
27
+ echo "building arm64 slice..."
28
+ compile_arch arm64 "$TMP_ARM"
29
+ echo "building x86_64 slice..."
30
+ compile_arch x86_64 "$TMP_X64"
31
+
32
+ cp "$TMP_ARM" desktop/float/bin/gufa-float-macos-arm64
33
+ cp "$TMP_X64" desktop/float/bin/gufa-float-macos-x64
34
+ lipo -create "$TMP_ARM" "$TMP_X64" -output desktop/float/bin/gufa-float-macos-universal
35
+ chmod +x desktop/float/bin/gufa-float-macos-*.??? 2>/dev/null || true
36
+ chmod +x desktop/float/bin/gufa-float-macos-arm64 desktop/float/bin/gufa-float-macos-x64 desktop/float/bin/gufa-float-macos-universal
37
+
38
+ # 稳定的 code identifier(TCC 按它识别,避免每次构建换身份字符串)
39
+ codesign --force --sign - -i com.gufa.float desktop/float/bin/gufa-float-macos-arm64 >/dev/null 2>&1 || true
40
+ codesign --force --sign - -i com.gufa.float desktop/float/bin/gufa-float-macos-x64 >/dev/null 2>&1 || true
41
+ codesign --force --sign - -i com.gufa.float desktop/float/bin/gufa-float-macos-universal >/dev/null 2>&1 || true
14
42
 
15
43
  APP="desktop/float/古法编程悬浮层.app"
16
44
  rm -rf "$APP"
17
45
  mkdir -p "$APP/Contents/MacOS"
18
- cp "$OUT" "$APP/Contents/MacOS/gufa-float"
19
- cat > "$APP/Contents/Info.plist" <<'PLIST'
46
+ cp desktop/float/bin/gufa-float-macos-universal "$APP/Contents/MacOS/gufa-float"
47
+ cat > "$APP/Contents/Info.plist" <<PLIST
20
48
  <?xml version="1.0" encoding="UTF-8"?>
21
49
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
22
50
  <plist version="1.0">
@@ -26,8 +54,8 @@ cat > "$APP/Contents/Info.plist" <<'PLIST'
26
54
  <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
27
55
  <key>CFBundleExecutable</key><string>gufa-float</string>
28
56
  <key>CFBundlePackageType</key><string>APPL</string>
29
- <key>CFBundleShortVersionString</key><string>1.3.1</string>
30
- <key>CFBundleVersion</key><string>1.3.1</string>
57
+ <key>CFBundleShortVersionString</key><string>${VERSION}</string>
58
+ <key>CFBundleVersion</key><string>${VERSION}</string>
31
59
  <key>LSUIElement</key><true/>
32
60
  <key>NSHighResolutionCapable</key><true/>
33
61
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -35,5 +63,6 @@ cat > "$APP/Contents/Info.plist" <<'PLIST'
35
63
  </plist>
36
64
  PLIST
37
65
  codesign --force --deep --sign - "$APP" >/dev/null 2>&1 || true
38
- echo "built: $OUT"
66
+
67
+ echo "built: desktop/float/bin/gufa-float-macos-universal ($(lipo -archs desktop/float/bin/gufa-float-macos-universal))"
39
68
  echo "built: $APP"
@@ -0,0 +1,33 @@
1
+ # 在 Windows 本机构建摸鱼悬浮层 helper(Win32 + WebView2),并放到 host 期望的位置。
2
+ # 依赖:Visual Studio 2022(Desktop development with C++)+ Windows 10/11 SDK。
3
+ # 用法(仓库根目录,PowerShell):
4
+ # pwsh -File scripts/build-float-win.ps1
5
+ # # 或指定已解压的 WebView2 SDK:
6
+ # pwsh -File scripts/build-float-win.ps1 -WebView2SdkDir C:\wv2
7
+ $ErrorActionPreference = 'Stop'
8
+ $Root = Split-Path -Parent $PSScriptRoot
9
+ Set-Location $Root
10
+
11
+ param(
12
+ [string]$WebView2SdkDir = $env:WEBVIEW2_SDK_DIR,
13
+ [string]$WebView2Version = '1.0.2903.40'
14
+ )
15
+ if (-not $WebView2SdkDir) {
16
+ $tmp = Join-Path $env:TEMP 'gufa-webview2'
17
+ $zip = Join-Path $env:TEMP 'gufa-webview2.zip'
18
+ if (-not (Test-Path (Join-Path $tmp 'build/native/include/WebView2.h'))) {
19
+ Write-Host "下载 Microsoft.Web.WebView2 $WebView2Version ..."
20
+ Invoke-WebRequest "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/$WebView2Version" -OutFile $zip
21
+ if (Test-Path $tmp) { Remove-Item $tmp -Recurse -Force }
22
+ Expand-Archive $zip -DestinationPath $tmp -Force
23
+ }
24
+ $WebView2SdkDir = $tmp
25
+ }
26
+
27
+ cmake -S desktop/float/win -B build-win -A x64 -DWEBVIEW2_SDK_DIR="$WebView2SdkDir"
28
+ cmake --build build-win --config Release
29
+ New-Item -ItemType Directory -Force desktop/float/bin/win-x64 | Out-Null
30
+ $exe = Get-ChildItem -Path build-win -Recurse -Filter *.exe | Where-Object { $_.Name -notlike 'vc_redist*' } | Select-Object -First 1
31
+ if (-not $exe) { throw '没有找到构建出的 exe' }
32
+ Copy-Item $exe.FullName desktop/float/bin/win-x64/gufa-float-win.exe -Force
33
+ Write-Host "built: desktop/float/bin/win-x64/gufa-float-win.exe"