dsh-gufa-code 1.3.49 → 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.
- package/README.md +13 -4
- package/client.js +1 -1
- package/desktop/float/PLATFORM-PROTOCOL.md +120 -0
- package/desktop/float/bin/README.md +12 -0
- package/desktop/float/bin/linux-x64/gufa-float-linux +0 -0
- package/desktop/float/bin/win-x64/gufa-float-win.exe +0 -0
- package/desktop/float/linux/Makefile +85 -0
- package/desktop/float/linux/README-LINUX.md +206 -0
- package/desktop/float/linux/json.c +498 -0
- package/desktop/float/linux/json.h +56 -0
- package/desktop/float/linux/log.c +48 -0
- package/desktop/float/linux/log.h +19 -0
- package/desktop/float/linux/main.c +1184 -0
- package/desktop/float/linux/x11.c +608 -0
- package/desktop/float/linux/x11.h +118 -0
- package/desktop/float/win/CMakeLists.txt +159 -0
- package/desktop/float/win/README-WIN.md +184 -0
- package/desktop/float/win/json.h +505 -0
- package/desktop/float/win/main.cpp +1935 -0
- package/docs/MODES.md +7 -0
- package/host/dev.js +254 -55
- package/package.json +1 -1
- package/scripts/build-float-linux.sh +15 -0
- package/scripts/build-float-win.ps1 +33 -0
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
|
|
29
|
+
/** 查找当前平台编译好的悬浮层 helper。 */
|
|
30
30
|
function floatBinaryPath() {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
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
|
-
/* ── 桌面悬浮层 /
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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 =
|
|
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
|
-
|
|
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('
|
|
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
|
|
82
|
-
if (
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
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() +
|
|
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
|
-
/*
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
341
|
+
/** 打开 helper 所在位置(macOS 在 Finder 显示 App;Windows 在资源管理器选中 exe;Linux 打开目录)。 */
|
|
170
342
|
router.method('float.revealHelper', async () => {
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
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('
|
|
175
|
-
|
|
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
|
|
364
|
+
/** 列出可吸附的 App 窗口(三平台统一返回 {ok, accessibility, apps})。 */
|
|
182
365
|
router.method('float.windows', async () => {
|
|
183
|
-
|
|
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 (
|
|
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
|
-
|
|
245
|
-
if (
|
|
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
|
@@ -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。"
|
|
@@ -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"
|