dsh-gufa-code 1.3.197 → 1.3.198
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/client.js +1 -1
- package/desktop/float/bin/win-x64/gufa-float-win.exe +0 -0
- package/desktop/float/win/main.cpp +19 -25
- package/host/dev.js +10 -7
- package/host/window-list-script.js +57 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
Binary file
|
|
@@ -1362,7 +1362,10 @@ bool FloatApp::CreateMainWindow() {
|
|
|
1362
1362
|
bool FloatApp::CreateHostWindow(const RECT& rect, bool composition) {
|
|
1363
1363
|
hostingMode_ = composition ? HostingMode::Composition : HostingMode::Windowed;
|
|
1364
1364
|
DWORD extendedStyle = WS_EX_TOPMOST | WS_EX_TOOLWINDOW;
|
|
1365
|
-
|
|
1365
|
+
/* 透明 + 鼠标穿透的正确组合:WS_EX_LAYERED 与 DirectComposition 可以共存;
|
|
1366
|
+
WS_EX_NOREDIRECTIONBITMAP 与 LAYERED 语义冲突会出白色矩形,而且 NORD 本身
|
|
1367
|
+
不实现穿透(HTTRANSPARENT 又只在同线程生效)。 */
|
|
1368
|
+
if (composition) extendedStyle |= WS_EX_LAYERED;
|
|
1366
1369
|
const DWORD style = WS_POPUP | WS_THICKFRAME | WS_CLIPCHILDREN;
|
|
1367
1370
|
hwnd_ = CreateWindowExW(extendedStyle, kMainWindowClass, kWindowTitle, style, rect.left,
|
|
1368
1371
|
rect.top, rect.right - rect.left, rect.bottom - rect.top, nullptr,
|
|
@@ -1375,6 +1378,9 @@ bool FloatApp::CreateHostWindow(const RECT& rect, bool composition) {
|
|
|
1375
1378
|
LogFmt(L"main-window-created composition=%d rect=(%ld,%ld)-(%ld,%ld) dpi=%u",
|
|
1376
1379
|
composition ? 1 : 0, static_cast<long>(rect.left), static_cast<long>(rect.top),
|
|
1377
1380
|
static_cast<long>(rect.right), static_cast<long>(rect.bottom), WindowDpi(hwnd_));
|
|
1381
|
+
if (composition) {
|
|
1382
|
+
SetLayeredWindowAttributes(hwnd_, 0, 255, LWA_ALPHA);
|
|
1383
|
+
}
|
|
1378
1384
|
if (RegisterHotKey(hwnd_, kHotkeyClickThrough, MOD_CONTROL | MOD_ALT | MOD_SHIFT, 'G')) {
|
|
1379
1385
|
clickThroughHotkey_ = true;
|
|
1380
1386
|
Log(L"click-through-hotkey=registered Ctrl+Alt+Shift+G");
|
|
@@ -1690,9 +1696,8 @@ bool FloatApp::OnCompositionMouseMessage(UINT message, WPARAM wparam, LPARAM lpa
|
|
|
1690
1696
|
}
|
|
1691
1697
|
|
|
1692
1698
|
LRESULT FloatApp::HandleNcHitTest(HWND hwnd, LPARAM lparam) {
|
|
1693
|
-
/*
|
|
1694
|
-
WS_EX_TRANSPARENT
|
|
1695
|
-
if (clickThrough_) return HTTRANSPARENT;
|
|
1699
|
+
/* 注意:穿透不要在这里返回 HTTRANSPARENT —— 它只在同线程窗口间下传,
|
|
1700
|
+
跨进程会直接吞掉点击;跨进程穿透由 WS_EX_LAYERED|WS_EX_TRANSPARENT 负责。 */
|
|
1696
1701
|
POINT point;
|
|
1697
1702
|
point.x = GET_X_LPARAM(lparam);
|
|
1698
1703
|
point.y = GET_Y_LPARAM(lparam);
|
|
@@ -2533,27 +2538,16 @@ void FloatApp::ToggleClickThrough() {
|
|
|
2533
2538
|
void FloatApp::ApplyClickThrough() {
|
|
2534
2539
|
if (hwnd_ == nullptr) return;
|
|
2535
2540
|
LONG_PTR exStyle = GetWindowLongPtrW(hwnd_, GWL_EXSTYLE);
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
if (clickThrough_) {
|
|
2547
|
-
if ((next & WS_EX_LAYERED) == 0) {
|
|
2548
|
-
next |= WS_EX_LAYERED;
|
|
2549
|
-
clickThroughLayered_ = true;
|
|
2550
|
-
SetLayeredWindowAttributes(hwnd_, 0, 255, LWA_ALPHA);
|
|
2551
|
-
}
|
|
2552
|
-
} else if (clickThroughLayered_) {
|
|
2553
|
-
next &= ~static_cast<LONG_PTR>(WS_EX_LAYERED);
|
|
2554
|
-
clickThroughLayered_ = false;
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2541
|
+
/* 跨进程穿透只有 WS_EX_LAYERED | WS_EX_TRANSPARENT 有效:
|
|
2542
|
+
- NORD 窗口不受 WS_EX_TRANSPARENT 影响;
|
|
2543
|
+
- WM_NCHITTEST→HTTRANSPARENT 只在同线程窗口间下传,跨进程会吞掉点击。
|
|
2544
|
+
所以 composition 窗口改成 LAYERED + DComp,穿透只翻转 TRANSPARENT 位。 */
|
|
2545
|
+
LONG_PTR next = clickThrough_ ? (exStyle | WS_EX_TRANSPARENT | WS_EX_LAYERED)
|
|
2546
|
+
: (exStyle & ~static_cast<LONG_PTR>(WS_EX_TRANSPARENT));
|
|
2547
|
+
if ((next & WS_EX_LAYERED) != 0 && (exStyle & WS_EX_LAYERED) == 0) {
|
|
2548
|
+
SetLayeredWindowAttributes(hwnd_, 0, 255, LWA_ALPHA);
|
|
2549
|
+
}
|
|
2550
|
+
clickThroughLayered_ = (next & WS_EX_LAYERED) != 0;
|
|
2557
2551
|
if (next != exStyle) {
|
|
2558
2552
|
SetWindowLongPtrW(hwnd_, GWL_EXSTYLE, next);
|
|
2559
2553
|
SetWindowPos(hwnd_, nullptr, 0, 0, 0, 0,
|
package/host/dev.js
CHANGED
|
@@ -11,6 +11,7 @@ import { dirname, join } from 'node:path'
|
|
|
11
11
|
import { fileURLToPath } from 'node:url'
|
|
12
12
|
import { ApiError } from './context.js'
|
|
13
13
|
import { floatBinaryCandidates, parsePowerShellWindowList, parseTasklistPids, parseWmctrlWindowList } from './float-platform.js'
|
|
14
|
+
import { windowsWindowListScript } from './window-list-script.js'
|
|
14
15
|
|
|
15
16
|
const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
16
17
|
const DEBUG_LOG_PATH = '/tmp/gufa-code-debug.log'
|
|
@@ -71,6 +72,8 @@ export function debugLog(message) {
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
|
|
76
|
+
|
|
74
77
|
export function register(router, env) {
|
|
75
78
|
const startedAt = new Date().toISOString()
|
|
76
79
|
const ctx = env?.ctx ?? router.ctx
|
|
@@ -235,18 +238,18 @@ export function register(router, env) {
|
|
|
235
238
|
})
|
|
236
239
|
})
|
|
237
240
|
|
|
238
|
-
/** Windows:PowerShell 枚举有主窗口的进程。 */
|
|
239
241
|
const listFloatWindowsWin = async () => {
|
|
240
|
-
const script =
|
|
241
|
-
'$rows = @();',
|
|
242
|
-
"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 } };",
|
|
243
|
-
"ConvertTo-Json -InputObject ([pscustomobject]@{ ok = $true; accessibility = $true; apps = @($rows) }) -Compress -Depth 5",
|
|
244
|
-
].join('\n')
|
|
242
|
+
const script = windowsWindowListScript()
|
|
245
243
|
const { stdout } = await runFile('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], { timeout: 20_000, maxBuffer: 8 * 1024 * 1024 })
|
|
246
244
|
const parsed = parsePowerShellWindowList(stdout)
|
|
247
245
|
if (parsed === null) throw new ApiError('list-failed', '读取 Windows 窗口列表失败', 500)
|
|
248
246
|
const helperPids = new Set(await listFloatPids())
|
|
249
|
-
const apps = parsed.apps.filter((row) =>
|
|
247
|
+
const apps = parsed.apps.filter((row) => {
|
|
248
|
+
if (helperPids.has(Number(row.pid))) return false
|
|
249
|
+
const title = String(row.title ?? '')
|
|
250
|
+
if (title.includes('古法编程悬浮层')) return false
|
|
251
|
+
return true
|
|
252
|
+
})
|
|
250
253
|
return { ok: true, accessibility: true, apps }
|
|
251
254
|
}
|
|
252
255
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows 窗口枚举 PowerShell 脚本。
|
|
3
|
+
*
|
|
4
|
+
* 单独成文件是为了让 CI 在没有 npm 依赖的环境里直接 import 做真机验证;
|
|
5
|
+
* Host 侧 host/dev.js 复用同一个脚本。
|
|
6
|
+
*/
|
|
7
|
+
/** Windows 窗口枚举 PowerShell 脚本(同时供 CI 真机测试直接运行)。 */
|
|
8
|
+
export function windowsWindowListScript() {
|
|
9
|
+
const typeDef = [
|
|
10
|
+
'using System;',
|
|
11
|
+
'using System.Text;',
|
|
12
|
+
'using System.Runtime.InteropServices;',
|
|
13
|
+
'public static class GufaWinEnum {',
|
|
14
|
+
' public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);',
|
|
15
|
+
' [DllImport("user32.dll")] public static extern bool EnumWindows(EnumWindowsProc cb, IntPtr lParam);',
|
|
16
|
+
' [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd);',
|
|
17
|
+
' [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int max);',
|
|
18
|
+
' [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetWindowTextLength(IntPtr hWnd);',
|
|
19
|
+
' [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint pid);',
|
|
20
|
+
' [DllImport("user32.dll")] public static extern IntPtr GetWindow(IntPtr hWnd, uint cmd);',
|
|
21
|
+
' [DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hWnd, int index);',
|
|
22
|
+
'}',
|
|
23
|
+
].join('\n')
|
|
24
|
+
const script = [
|
|
25
|
+
'$ErrorActionPreference = "SilentlyContinue";',
|
|
26
|
+
'[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;',
|
|
27
|
+
'$OutputEncoding = [System.Text.Encoding]::UTF8;',
|
|
28
|
+
"Add-Type -TypeDefinition @'",
|
|
29
|
+
typeDef,
|
|
30
|
+
"'@",
|
|
31
|
+
'$procs = @{};',
|
|
32
|
+
'Get-Process | ForEach-Object { $procs[[uint32]$_.Id] = $_.ProcessName }',
|
|
33
|
+
'$rows = New-Object System.Collections.ArrayList;',
|
|
34
|
+
'$cb = [GufaWinEnum+EnumWindowsProc]{ param($hWnd, $lParam)',
|
|
35
|
+
' if (-not [GufaWinEnum]::IsWindowVisible($hWnd)) { return $true };',
|
|
36
|
+
' $len = [GufaWinEnum]::GetWindowTextLength($hWnd);',
|
|
37
|
+
' if ($len -le 0) { return $true };',
|
|
38
|
+
' $sb = New-Object System.Text.StringBuilder ($len + 1);',
|
|
39
|
+
' [void][GufaWinEnum]::GetWindowText($hWnd, $sb, $sb.Capacity);',
|
|
40
|
+
' $title = $sb.ToString();',
|
|
41
|
+
' if ([string]::IsNullOrWhiteSpace($title)) { return $true };',
|
|
42
|
+
' $ex = [GufaWinEnum]::GetWindowLong($hWnd, -20);',
|
|
43
|
+
' if (($ex -band 0x00000080) -ne 0) { return $true };',
|
|
44
|
+
' if ([GufaWinEnum]::GetWindow($hWnd, 4) -ne [IntPtr]::Zero) { return $true };',
|
|
45
|
+
' $ownerPid = [uint32]0;',
|
|
46
|
+
' [void][GufaWinEnum]::GetWindowThreadProcessId($hWnd, [ref]$ownerPid);',
|
|
47
|
+
' $ownerName = $procs[$ownerPid];',
|
|
48
|
+
' if (-not $ownerName) { $ownerName = "" };',
|
|
49
|
+
' [void]$rows.Add([pscustomobject]@{ pid = [int64]$ownerPid; owner = $ownerName; title = $title; bundleId = ""; windowNumber = [int64]$hWnd; frontmost = 0 });',
|
|
50
|
+
' return $true',
|
|
51
|
+
'};',
|
|
52
|
+
'[void][GufaWinEnum]::EnumWindows($cb, [IntPtr]::Zero);',
|
|
53
|
+
'ConvertTo-Json -InputObject ([pscustomobject]@{ ok = $true; accessibility = $true; apps = @($rows) }) -Compress -Depth 5',
|
|
54
|
+
].join('\n')
|
|
55
|
+
return script
|
|
56
|
+
}
|
|
57
|
+
|
package/package.json
CHANGED