dsh-gufa-code 1.3.196 → 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 CHANGED
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
16
16
  const G = {}
17
17
  G.NS = GUFA_NS
18
18
  /** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
19
- G.BUILD = '1.3.196'
19
+ G.BUILD = '1.3.198'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -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
- if (composition) extendedStyle |= WS_EX_NOREDIRECTIONBITMAP;
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
- /* 鼠标穿透:双击/拖动都不要再命中本窗口,让点击落到下层 App。
1694
- WS_EX_TRANSPARENT 在部分 WebView2/Composition 窗口上不生效,这里加 HTTRANSPARENT 兜底。 */
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,22 +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
- LONG_PTR next = clickThrough_ ? (exStyle | WS_EX_TRANSPARENT)
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)
2537
2546
  : (exStyle & ~static_cast<LONG_PTR>(WS_EX_TRANSPARENT));
2538
- /* windowed 模式需要 layered 才能让点击稳定穿透到下层窗口;composition 模式
2539
- 使用 WS_EX_NOREDIRECTIONBITMAP,不能叠加 layered。 */
2540
- if (hostingMode_ == HostingMode::Windowed) {
2541
- if (clickThrough_) {
2542
- if ((next & WS_EX_LAYERED) == 0) {
2543
- next |= WS_EX_LAYERED;
2544
- clickThroughLayered_ = true;
2545
- SetLayeredWindowAttributes(hwnd_, 0, 255, LWA_ALPHA);
2546
- }
2547
- } else if (clickThroughLayered_) {
2548
- next &= ~static_cast<LONG_PTR>(WS_EX_LAYERED);
2549
- clickThroughLayered_ = false;
2550
- }
2547
+ if ((next & WS_EX_LAYERED) != 0 && (exStyle & WS_EX_LAYERED) == 0) {
2548
+ SetLayeredWindowAttributes(hwnd_, 0, 255, LWA_ALPHA);
2551
2549
  }
2550
+ clickThroughLayered_ = (next & WS_EX_LAYERED) != 0;
2552
2551
  if (next != exStyle) {
2553
2552
  SetWindowLongPtrW(hwnd_, GWL_EXSTYLE, next);
2554
2553
  SetWindowPos(hwnd_, nullptr, 0, 0, 0, 0,
@@ -2557,9 +2556,10 @@ void FloatApp::ApplyClickThrough() {
2557
2556
  int childCount = 0;
2558
2557
  EnumChildWindows(hwnd_, CountChildWindow, reinterpret_cast<LPARAM>(&childCount));
2559
2558
  EnumChildWindows(hwnd_, SetChildClickThrough, clickThrough_ ? 1 : 0);
2560
- LogFmt(L"click-through=%d mode=%s layered=%d children=%d", clickThrough_ ? 1 : 0,
2559
+ LogFmt(L"click-through=%d mode=%s layered=%d styleTransparent=%d children=%d", clickThrough_ ? 1 : 0,
2561
2560
  hostingMode_ == HostingMode::Composition ? L"composition" : L"windowed",
2562
- clickThroughLayered_ ? 1 : 0, childCount);
2561
+ clickThroughLayered_ ? 1 : 0,
2562
+ (GetWindowLongPtrW(hwnd_, GWL_EXSTYLE) & WS_EX_TRANSPARENT) != 0 ? 1 : 0, childCount);
2563
2563
  }
2564
2564
 
2565
2565
  void FloatApp::StopFollowing() {
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) => !helperPids.has(Number(row.pid)))
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.196",
3
+ "version": "1.3.198",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [