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.
@@ -0,0 +1,118 @@
1
+ /**
2
+ * X11 相关能力(Linux helper 专有):
3
+ * - 按 pid 找目标窗口(follow 吸附)、读取窗口在 root 坐标系里的矩形;
4
+ * - 读 _NET_WM_PID / _NET_WM_NAME / WM_CLASS,识别窗口类型;
5
+ * - 隐藏 / 恢复 DSH 主窗口(_NET_WM_PID 或标题匹配);
6
+ * - 发送 _NET_ACTIVE_WINDOW 前置窗口、复制 _NET_WM_DESKTOP 工作区;
7
+ * - --list-windows 模式的窗口枚举。
8
+ *
9
+ * 所有查询走 helper 自己开的独立 X 连接,避免影响 GTK 的 GDK 连接与错误处理。
10
+ * Wayland 下这里不可用(XOpenDisplay 拿不到目标窗口),上层负责降级。
11
+ */
12
+ #ifndef GUFA_X11_H
13
+ #define GUFA_X11_H
14
+
15
+ #include <X11/Xlib.h>
16
+ #include <glib.h>
17
+
18
+ typedef struct {
19
+ int x;
20
+ int y;
21
+ int width;
22
+ int height;
23
+ gboolean valid;
24
+ gboolean viewable;
25
+ } GufaX11Rect;
26
+
27
+ typedef struct {
28
+ Window *wins;
29
+ guint n;
30
+ } GufaX11WindowList;
31
+
32
+ typedef struct {
33
+ Window win;
34
+ long pid;
35
+ char *title;
36
+ char *owner;
37
+ char *wm_class;
38
+ gboolean frontmost;
39
+ } GufaX11App;
40
+
41
+ typedef struct {
42
+ Display *dpy;
43
+ Window root;
44
+ gboolean ok;
45
+ long self_pid;
46
+ Atom atom_net_wm_pid;
47
+ Atom atom_net_wm_name;
48
+ Atom atom_utf8_string;
49
+ Atom atom_net_active_window;
50
+ Atom atom_net_client_list;
51
+ Atom atom_net_wm_window_type;
52
+ Atom atom_net_wm_window_type_normal;
53
+ Atom atom_net_wm_window_type_dialog;
54
+ Atom atom_net_wm_window_type_desktop;
55
+ Atom atom_net_wm_window_type_dock;
56
+ Atom atom_net_wm_window_type_toolbar;
57
+ Atom atom_net_wm_window_type_menu;
58
+ Atom atom_net_wm_window_type_utility;
59
+ Atom atom_net_wm_window_type_splash;
60
+ Atom atom_net_wm_window_type_dropdown;
61
+ Atom atom_net_wm_window_type_tooltip;
62
+ Atom atom_net_wm_desktop;
63
+ } GufaX11;
64
+
65
+ /** 打开 X 连接并缓存 atoms。失败返回 FALSE(上层降级为纯 GTK 自由悬浮)。 */
66
+ gboolean gufa_x11_open(GufaX11 *x11);
67
+
68
+ /** 关闭连接(可重复调用)。 */
69
+ void gufa_x11_close(GufaX11 *x11);
70
+
71
+ /** 读窗口标题(_NET_WM_NAME 优先,退回 WM_NAME);调用方 g_free。 */
72
+ char *gufa_x11_window_title(GufaX11 *x11, Window window);
73
+
74
+ /** 读 _NET_WM_PID;没有返回 0。 */
75
+ long gufa_x11_window_pid(GufaX11 *x11, Window window);
76
+
77
+ /** 读 WM_CLASS 的 class 字段(退回 instance);调用方 g_free。 */
78
+ char *gufa_x11_window_class(GufaX11 *x11, Window window);
79
+
80
+ /** 当前活动窗口(_NET_ACTIVE_WINDOW),没有返回 0。 */
81
+ Window gufa_x11_active_window(GufaX11 *x11);
82
+
83
+ /**
84
+ * 按 pid(>0 时)找目标窗口,title_hint 非空时优先标题匹配;
85
+ * 只考虑可跟随的普通窗口(_NET_WM_WINDOW_TYPE 为 NORMAL/DIALOG 或未声明)。
86
+ */
87
+ Window gufa_x11_find_window(GufaX11 *x11, long pid, const char *title_hint, Window skip);
88
+
89
+ /** 读取窗口在 root 上的绝对矩形;窗口不存在返回 FALSE。 */
90
+ gboolean gufa_x11_window_rect(GufaX11 *x11, Window window, GufaX11Rect *out);
91
+
92
+ /** 窗口是否还存在(可能已最小化/未映射)。 */
93
+ gboolean gufa_x11_window_exists(GufaX11 *x11, Window window);
94
+
95
+ /** 发送 _NET_ACTIVE_WINDOW ClientMessage 并 raise。 */
96
+ void gufa_x11_activate_window(GufaX11 *x11, Window window, guint32 timestamp);
97
+
98
+ /** 映射窗口(恢复显示),可选 raise。 */
99
+ void gufa_x11_map_window(GufaX11 *x11, Window window, gboolean do_raise);
100
+
101
+ /** 把 own 窗口的 _NET_WM_DESKTOP 设置成 target 窗口所在工作区(best-effort)。 */
102
+ void gufa_x11_copy_desktop(GufaX11 *x11, Window target, Window own);
103
+
104
+ /**
105
+ * 隐藏 DSH 主窗口:优先 owner_pid 匹配,找不到时按标题/类名启发式匹配;
106
+ * 命中的窗口被 XUnmapWindow 并记录到 hidden(供退出时恢复)。
107
+ */
108
+ void gufa_x11_hide_windows_like_dsh(GufaX11 *x11, long owner_pid, const char *title_hint, GufaX11WindowList *hidden);
109
+
110
+ /** 恢复 hidden 里的窗口(XMapWindow + raise + _NET_ACTIVE_WINDOW 前置)。 */
111
+ void gufa_x11_restore_windows(GufaX11 *x11, GufaX11WindowList *hidden, guint32 timestamp);
112
+
113
+ /** 枚举可吸附的 App 窗口(--list-windows 模式用,调用方用 gufa_x11_apps_free 释放)。 */
114
+ GPtrArray *gufa_x11_list_apps(GufaX11 *x11);
115
+
116
+ void gufa_x11_apps_free(GPtrArray *apps);
117
+
118
+ #endif /* GUFA_X11_H */
@@ -0,0 +1,159 @@
1
+ # 古法编程 · Windows 悬浮层 helper(Win32 + WebView2)
2
+ #
3
+ # 依赖:Visual Studio 2022(Desktop development with C++)+ Windows 10/11 SDK +
4
+ # Microsoft.Web.WebView2 NuGet 包(只需解压,提供头文件和 WebView2LoaderStatic.lib)。
5
+ #
6
+ # 用法(在仓库根目录执行):
7
+ # cmake -S desktop/float/win -B build-win -A x64 -DWEBVIEW2_SDK_DIR=<解压后的 NuGet 包目录>
8
+ # cmake --build build-win --config Release
9
+ #
10
+ # CI 会先用 NuGet 下载 Microsoft.Web.WebView2/1.0.2903.40 并解压,然后把解压目录
11
+ # 通过 -DWEBVIEW2_SDK_DIR=... 传进来(见 .github/workflows/build-float.yml)。
12
+ # 产物:build-win/bin/<Config>/gufa-float-win.exe(CI 会复制到
13
+ # desktop/float/bin/win-x64/gufa-float-win.exe)。
14
+
15
+ cmake_minimum_required(VERSION 3.20)
16
+
17
+ project(gufa-float-win LANGUAGES CXX)
18
+
19
+ if(NOT WIN32)
20
+ message(FATAL_ERROR
21
+ "gufa-float-win 只能在 Windows 上构建(当前系统:${CMAKE_SYSTEM_NAME})。"
22
+ "macOS/Linux 上请用 CI(GitHub Actions windows-latest)构建。")
23
+ endif()
24
+
25
+ set(CMAKE_CXX_STANDARD 17)
26
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
27
+ set(CMAKE_CXX_EXTENSIONS OFF)
28
+
29
+ # ---------------------------------------------------------------------------
30
+ # 定位 WebView2 SDK(NuGet 包解压目录)
31
+ # ---------------------------------------------------------------------------
32
+ if(NOT DEFINED WEBVIEW2_SDK_DIR OR WEBVIEW2_SDK_DIR STREQUAL "")
33
+ if(DEFINED ENV{WEBVIEW2_SDK_DIR} AND NOT "$ENV{WEBVIEW2_SDK_DIR}" STREQUAL "")
34
+ set(WEBVIEW2_SDK_DIR "$ENV{WEBVIEW2_SDK_DIR}")
35
+ endif()
36
+ endif()
37
+ if(NOT DEFINED WEBVIEW2_SDK_DIR OR WEBVIEW2_SDK_DIR STREQUAL "")
38
+ message(FATAL_ERROR
39
+ "没有设置 WEBVIEW2_SDK_DIR。\n"
40
+ "请先下载/解压 Microsoft.Web.WebView2 NuGet 包,然后用 -DWEBVIEW2_SDK_DIR=<目录> 传入。\n"
41
+ " 例如:\n"
42
+ " Invoke-WebRequest 'https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/1.0.2903.40' -OutFile wv2.zip\n"
43
+ " Expand-Archive wv2.zip -DestinationPath wv2\n"
44
+ " cmake -S . -B build-win -A x64 -DWEBVIEW2_SDK_DIR=\"$PWD/wv2\"")
45
+ endif()
46
+ get_filename_component(WEBVIEW2_SDK_DIR "${WEBVIEW2_SDK_DIR}" ABSOLUTE)
47
+
48
+ # WebView2.h(NuGet 包标准布局:build/native/include/WebView2.h;也允许任意子目录)
49
+ set(WEBVIEW2_HEADER "")
50
+ if(EXISTS "${WEBVIEW2_SDK_DIR}/build/native/include/WebView2.h")
51
+ set(WEBVIEW2_HEADER "${WEBVIEW2_SDK_DIR}/build/native/include/WebView2.h")
52
+ else()
53
+ file(GLOB_RECURSE _wv2_headers "${WEBVIEW2_SDK_DIR}/*WebView2.h")
54
+ if(_wv2_headers)
55
+ list(GET _wv2_headers 0 WEBVIEW2_HEADER)
56
+ endif()
57
+ endif()
58
+ if(NOT WEBVIEW2_HEADER)
59
+ message(FATAL_ERROR
60
+ "在 ${WEBVIEW2_SDK_DIR} 下找不到 WebView2.h。\n"
61
+ "WEBVIEW2_SDK_DIR 应为 Microsoft.Web.WebView2 NuGet 包的解压根目录"
62
+ "(其中包含 build/native/include/WebView2.h)。")
63
+ endif()
64
+ get_filename_component(WEBVIEW2_INCLUDE_DIR "${WEBVIEW2_HEADER}" DIRECTORY)
65
+
66
+ if(NOT EXISTS "${WEBVIEW2_INCLUDE_DIR}/WebView2EnvironmentOptions.h")
67
+ message(FATAL_ERROR
68
+ "在 ${WEBVIEW2_INCLUDE_DIR} 下找不到 WebView2EnvironmentOptions.h;"
69
+ "SDK 包不完整?请更换 Microsoft.Web.WebView2 的稳定版本(CI 用 1.0.2903.40)。")
70
+ endif()
71
+
72
+ # 目标架构(CI 显式 -A x64;也兼容 ARM64/x86)
73
+ set(_wv2_arch "x64")
74
+ if(CMAKE_GENERATOR_PLATFORM)
75
+ string(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" _wv2_platform)
76
+ if(_wv2_platform MATCHES "arm64")
77
+ set(_wv2_arch "arm64")
78
+ elseif(_wv2_platform MATCHES "win32" OR _wv2_platform MATCHES "^x86$")
79
+ set(_wv2_arch "x86")
80
+ endif()
81
+ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
82
+ set(_wv2_arch "x86")
83
+ endif()
84
+
85
+ # WebView2LoaderStatic.lib(静态加载器:产物是单 exe,不需要额外的 WebView2Loader.dll)
86
+ set(WEBVIEW2_LOADER_LIB "")
87
+ set(_wv2_direct "${WEBVIEW2_SDK_DIR}/build/native/${_wv2_arch}/WebView2LoaderStatic.lib")
88
+ if(EXISTS "${_wv2_direct}")
89
+ set(WEBVIEW2_LOADER_LIB "${_wv2_direct}")
90
+ else()
91
+ file(GLOB_RECURSE _wv2_loader_candidates "${WEBVIEW2_SDK_DIR}/*WebView2LoaderStatic.lib")
92
+ foreach(_candidate IN LISTS _wv2_loader_candidates)
93
+ if(_candidate MATCHES "[/\\\\]${_wv2_arch}[/\\\\]")
94
+ set(WEBVIEW2_LOADER_LIB "${_candidate}")
95
+ break()
96
+ endif()
97
+ endforeach()
98
+ if(NOT WEBVIEW2_LOADER_LIB AND _wv2_loader_candidates)
99
+ list(GET _wv2_loader_candidates 0 WEBVIEW2_LOADER_LIB)
100
+ endif()
101
+ endif()
102
+ if(NOT WEBVIEW2_LOADER_LIB)
103
+ message(FATAL_ERROR
104
+ "找不到 ${_wv2_arch} 架构的 WebView2LoaderStatic.lib(应在 build/native/${_wv2_arch}/ 下)。")
105
+ endif()
106
+
107
+ message(STATUS "WebView2 include dir: ${WEBVIEW2_INCLUDE_DIR}")
108
+ message(STATUS "WebView2 loader lib : ${WEBVIEW2_LOADER_LIB}")
109
+
110
+ # ---------------------------------------------------------------------------
111
+ # 目标
112
+ # ---------------------------------------------------------------------------
113
+ add_executable(gufa-float-win WIN32
114
+ main.cpp
115
+ json.h
116
+ )
117
+
118
+ target_include_directories(gufa-float-win PRIVATE "${WEBVIEW2_INCLUDE_DIR}")
119
+
120
+ target_compile_definitions(gufa-float-win PRIVATE
121
+ UNICODE
122
+ _UNICODE
123
+ WIN32_LEAN_AND_MEAN
124
+ NOMINMAX
125
+ _WIN32_WINNT=0x0A00
126
+ WINVER=0x0A00
127
+ _CRT_SECURE_NO_WARNINGS
128
+ )
129
+
130
+ # WebView2LoaderStatic.lib 需要 version.lib(见 NuGet 包内 Common.targets)。
131
+ target_link_libraries(gufa-float-win PRIVATE
132
+ "${WEBVIEW2_LOADER_LIB}"
133
+ version
134
+ ole32
135
+ oleaut32
136
+ uuid
137
+ user32
138
+ gdi32
139
+ shell32
140
+ advapi32
141
+ dwmapi
142
+ )
143
+
144
+ if(MSVC)
145
+ # /utf-8:源码是 UTF-8,界面里的中文(拖动条文字等)需要按 UTF-8 解析;
146
+ # /ENTRY:显式指定 Unicode 入口,避免个别工具链找不到 wWinMain。
147
+ target_compile_options(gufa-float-win PRIVATE /W3 /utf-8 /EHsc)
148
+ target_link_options(gufa-float-win PRIVATE "/ENTRY:wWinMainCRTStartup")
149
+ endif()
150
+
151
+ set_target_properties(gufa-float-win PROPERTIES
152
+ OUTPUT_NAME "gufa-float-win"
153
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
154
+ )
155
+ # 多配置生成器(VS)下为每个配置生成独立 exe 路径(build-win/bin/<Config>/...)
156
+ foreach(_config DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
157
+ set_target_properties(gufa-float-win PROPERTIES
158
+ "RUNTIME_OUTPUT_DIRECTORY_${_config}" "${CMAKE_BINARY_DIR}/bin/${_config}")
159
+ endforeach()
@@ -0,0 +1,184 @@
1
+ # 古法编程 · Windows 悬浮层 helper(gufa-float-win)
2
+
3
+ 独立小进程:用 **C++17 + Win32 + WebView2** 加载 DSH Web GUI 的「古法编程」,
4
+ 做成无边框、永远置顶、可拖拽/可缩放、能吸附跟随其它 App 窗口的悬浮层。
5
+
6
+ 行为协议见 [`../PLATFORM-PROTOCOL.md`](../PLATFORM-PROTOCOL.md);
7
+ macOS 参考实现在 [`../GufaFloat.m`](../GufaFloat.m)。本目录只负责 Windows helper,
8
+ Host 侧(`host/dev.js` 的 `float.*`)与 CI(`.github/workflows/build-float.yml`)不在本目录维护。
9
+
10
+ ## 文件
11
+
12
+ | 文件 | 说明 |
13
+ | --- | --- |
14
+ | `main.cpp` | 全部逻辑:payload 解析、Win32 窗口、拖动条、WebView2 宿主、follow、隐藏/恢复 DSH、controlPath 退出、ciProbe |
15
+ | `json.h` | 极简 JSON 解析/序列化(header-only,只依赖 C++17 标准库;数字保留原始文本) |
16
+ | `CMakeLists.txt` | MSVC 构建脚本;从 `WEBVIEW2_SDK_DIR` 找 `WebView2.h` / `WebView2LoaderStatic.lib` |
17
+ | `README-WIN.md` | 本文件 |
18
+
19
+ 构建产物约定:`desktop/float/bin/win-x64/gufa-float-win.exe`(CI 从构建目录复制)。
20
+
21
+ ## 依赖
22
+
23
+ - **Visual Studio 2022**(Desktop development with C++)或带 MSVC x64 工具链的等价环境
24
+ - **Windows 10/11 SDK**(`wWinMain`、DPI、Dwmapi 等)
25
+ - **Microsoft.Web.WebView2 NuGet 包**(只需解压,不需要 `nuget restore`):
26
+ - CI 固定使用 `1.0.2903.40`,解压后通过 `-DWEBVIEW2_SDK_DIR=<解压目录>` 传给 CMake;
27
+ - 包内需要 `build/native/include/WebView2.h`、`build/native/include/WebView2EnvironmentOptions.h`、
28
+ `build/native/x64/WebView2LoaderStatic.lib`(用静态 loader,产物是单 exe,不需要附带 `WebView2Loader.dll`)。
29
+ - **Microsoft Edge WebView2 Runtime**(运行期依赖,Windows 10/11 通常随 Edge 自带;
30
+ 缺失时程序会弹窗提示安装 <https://go.microsoft.com/fwlink/p/?LinkId=2124703> 并以退出码 1 结束)。
31
+ helper 会显式把 `TargetCompatibleBrowserVersion` 设为 WebView2 GA 最低版本 `86.0.616.0`
32
+ (并用 `QueryInterface` 对 `CookieManager` / `Controller2` 做降级),避免用户机器 Runtime
33
+ 稍旧时直接启动失败。
34
+ - 说明:产物未做代码签名,用户机器首次运行 exe 可能遇到 SmartScreen 提示(选「更多信息 → 仍要运行」)。
35
+
36
+ ## 构建
37
+
38
+ CI(推荐,也是唯一被验证过的构建路径):`.github/workflows/build-float.yml` 的 `windows` job 会
39
+ 下载 NuGet 包 → `cmake -S desktop/float/win -B build-win -A x64 -DWEBVIEW2_SDK_DIR=...` →
40
+ `cmake --build build-win --config Release` → 复制到 `desktop/float/bin/win-x64/gufa-float-win.exe`。
41
+
42
+ 本机 Windows 手动构建(PowerShell,仓库根目录):
43
+
44
+ ```powershell
45
+ $ver = '1.0.2903.40'
46
+ Invoke-WebRequest "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/$ver" -OutFile wv2.zip
47
+ Expand-Archive wv2.zip -DestinationPath wv2 -Force
48
+ cmake -S desktop/float/win -B build-win -A x64 -DWEBVIEW2_SDK_DIR="$PWD/wv2"
49
+ cmake --build build-win --config Release
50
+ & .\build-win\bin\Release\gufa-float-win.exe --version
51
+ ```
52
+
53
+ CMake 会依次尝试:`${WEBVIEW2_SDK_DIR}/build/native/include/WebView2.h` → 递归搜索;
54
+ loader 库优先 `build/native/<arch>/WebView2LoaderStatic.lib`,其次按架构递归匹配。
55
+ 若 `WEBVIEW2_SDK_DIR` 未传,也会读取同名环境变量;两者都没有则 configure 阶段直接报错并给出提示。
56
+
57
+ ## 运行方式
58
+
59
+ Host 用 `spawn(binary, [payloadJson])` 启动,**argv[1] 是协议里的整个 JSON**(见协议 §1)。
60
+ 也支持几个便于排查/CI 的命令行参数(不影响 Host 协议):
61
+
62
+ | 命令 | 说明 |
63
+ | --- | --- |
64
+ | `gufa-float-win.exe --version` | 打印版本并退出 0(CI 的冒烟步骤会用) |
65
+ | `gufa-float-win.exe --help` | 用法提示 |
66
+ | `gufa-float-win.exe --ci-probe` | 等价于 payload `{"ciProbe":true}` |
67
+ | `gufa-float-win.exe '<payload-json>'` | 正常启动 |
68
+
69
+ ### ciProbe(CI 冒烟)
70
+
71
+ CI 传入:`{"appUrl":"http://127.0.0.1:1/","authUrl":"http://127.0.0.1:1/","ciProbe":true}`。
72
+ 行为:
73
+
74
+ - 创建**隐藏**窗口 + WebView2 环境,加载 `appUrl`(缺省时用内置 HTML);
75
+ - 页面加载完成(成功/失败都算)或 8s 超时后,stdout 打印**一行** JSON 并退出:
76
+ - 走到探针结束:`{"ok":true,"platform":"win32","urlLoaded":true|false}` → 退出码 0
77
+ - 环境创建失败(例如 runner 没有 WebView2 Runtime):`{"ok":false,"platform":"win32","urlLoaded":false}` → 退出码 1
78
+ - 另有 20s 看门狗:即使 WebView2 环境创建卡死,也不会让 CI 步骤无限等待。
79
+
80
+ > CI 的 runner 可能没有可用 GPU,ciProbe 会额外传 `--disable-gpu`(只影响 ciProbe,不影响真机运行)。
81
+
82
+ ## 已实现的协议条目
83
+
84
+ 对照 `PLATFORM-PROTOCOL.md`:
85
+
86
+ - §2.1 启动
87
+ - 解析 argv[1] JSON;解析失败 **退出码 2**(无参数也是 2)。
88
+ - 无边框(`WM_NCCALCSIZE` 去掉系统边框)置顶(`WS_EX_TOPMOST`)可缩放窗口;
89
+ 自由悬浮模式下尺寸/位置保存到 `%LOCALAPPDATA%\gufa-float\frame.ini` 并恢复。
90
+ - 鉴权两条路径:
91
+ - `cookie` 存在:用 `ICoreWebView2_2::get_CookieManager` + `CreateCookie` / `AddOrUpdateCookie`
92
+ 注入 cookie(Domain 取 appUrl 的 host,Path=`/`),再导航 `appUrl?gufa-float=1`;
93
+ - 否则:先加载 `authUrl`,等主 frame `NavigationCompleted` 后再导航 `appUrl?gufa-float=1`。
94
+ - document-start 注入(`ICoreWebView2::AddScriptToExecuteOnDocumentCreated`):
95
+ `gufa-code:float='1'`、`gufa-code:float-state=<state JSON>`、
96
+ 以及(有值时)`gufa-code:project` / `gufa-code:ui:v1`;注入登记完成之后才开始导航。
97
+ - 启动 **450ms** 后隐藏 DSH 主窗口。
98
+ - §2.2 吸附(payload 带 `follow.pid`)
99
+ - 每 **250ms** 用 `EnumWindows` 找目标 pid 的最大/最前可见顶层窗口(`DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS)`,
100
+ DWM 阴影边距不算在内;取不到时退回 `GetWindowRect`),把悬浮窗 `SetWindowPos` 到相同物理像素矩形;
101
+ - 进程全程 `PER_MONITOR_AWARE_V2`,多屏/负坐标/不同 DPI 直接用物理坐标拷贝,`WM_DPICHANGED` 时重排;
102
+ - 目标最小化/消失:保留最后位置继续轮询(约 5 分钟都找不到才降级为自由悬浮);
103
+ - 首次吸附和隐藏 DSH 之后用 `SetForegroundWindow`(配合 `AttachThreadInput`)把目标 App 前置。
104
+ - §2.3 隐藏/恢复 DSH 主窗口
105
+ - 识别顺序:① 标题包含 `DeepSeek Harness` 的可见顶层窗口;② 可执行文件名包含 `deepseek` 的进程的窗口;
106
+ ③ 两者都没有时,退化为「本 helper 的直接父进程(spawn 它的 Host 进程)」的窗口。
107
+ - 隐藏用 `ShowWindowAsync(hwnd, SW_HIDE)`,退出时 `SW_SHOW` + `SetForegroundWindow` 恢复;
108
+ - **安全策略**:不会盲信 `payload.ownerPid`(Host 传的是 `process.ppid`,可能是 explorer.exe),
109
+ 避免把任务栏/桌面隐藏掉。`ownerPid` 只作诊断信息。
110
+ - 崩溃/terminate 兜底:未处理异常过滤器会把已隐藏的 DSH 窗口尽量恢复,避免「主窗口消失」。
111
+ - §2.4 顶部拖动条:窗口顶部 **22 DIP** 高的子窗口(与网页 CSS `padding-top:22px` 对齐):
112
+ 按住拖动(`WM_NCLBUTTONDOWN`/`HTCAPTION`)、左键最右侧「✕」退出摸鱼、右键菜单(退出/重置窗口位置)。
113
+ - §2.5 控制文件退出:每 **300ms** 检查 `controlPath` 是否存在 → 恢复并前置 DSH 主窗口 → 删除控制文件 → 退出 0。
114
+ 另外监测 spawn 它的 Host 进程:Host 异常消失时也会恢复 DSH 后退出,避免孤儿悬浮窗。
115
+ - §3 ciProbe:见上。
116
+ - 自由悬浮:payload 无 `follow` 时不轮询跟随,可拖动/缩放;Alt+F4 会走「恢复 DSH 后退出」。
117
+ - 多显示器:`PER_MONITOR_AWARE_V2` + 物理像素坐标,支持负坐标屏幕;`WM_DPICHANGED` 时按系统建议矩形重排。
118
+
119
+ ## 交互速查
120
+
121
+ - **拖动窗口**:按住顶部 22px 条。
122
+ - **缩放窗口**:拖动左右/底部 8px 边缘(缩放手柄由 `WM_NCHITTEST` 提供;顶部 22px 保留给拖动)。
123
+ - **退出摸鱼**:顶部条右侧「✕」,或右键菜单「退出摸鱼」;网页里的「退出摸鱼」按钮会把编辑器状态
124
+ 先交给 Host(`float.saveExitState` → `float.stop`),效果相同且能带回状态。
125
+ - **重置窗口**:顶部条右键菜单「重置窗口位置和大小」。
126
+
127
+ ## 日志与数据
128
+
129
+ - 日志:`%TEMP%\gufa-float-debug.log`(UTF-8,单文件超过 4MB 下次启动会清空)。
130
+ 排查 failed/blank 时优先看它:会记录 payload 概要(**不记录 authUrl token 和 cookie 值**)、
131
+ WebView2 环境/控制器创建、导航完成、follow 命中矩形、隐藏/恢复窗口数量、ciProbe 结果等。
132
+ - WebView2 用户数据:`%LOCALAPPDATA%\gufa-float\webview2-<build>`(按插件版本分目录;
133
+ 版本变化时相当于换新 profile,避免旧前端缓存;`<build>` 来自 payload.build)。
134
+ 首次创建失败会自动用 `%LOCALAPPDATA%\gufa-float\webview2-retry-<pid>-<tick>` 再试一次。
135
+ - 自由悬浮窗口位置:`%LOCALAPPDATA%\gufa-float\frame.ini`。
136
+
137
+ ## 已知限制 / TODO(首版)
138
+
139
+ 1. **透明窗口:首版不透明**。
140
+ WebView2 的 windowed hosting(`CreateCoreWebView2Controller`)只能渲染不透明内容,
141
+ `put_DefaultBackgroundColor` 也不支持 alpha=0;因此首版窗口是不透明深色背景。
142
+ 协议 §2.6 允许「首版不透明,透明作为后续项」。后续透明方案(未实现,需要真机调试):
143
+ - `WS_EX_NOREDIRECTIONBITMAP` 窗口 + `D3D11CreateDevice` / `DCompositionCreateDevice3` +
144
+ `IDCompositionTarget` / `IDCompositionVisual`;
145
+ - `ICoreWebView2Environment3::CreateCoreWebView2CompositionController` 得到
146
+ `ICoreWebView2CompositionController`,`put_RootVisualTarget(visual)`;
147
+ - 手动转发鼠标输入(`SendMouseInput` + `COREWEBVIEW2_MOUSE_EVENT_KIND`)、处理 `add_CursorChanged`、
148
+ `WM_DPICHANGED` 时更新 DComp visual 的 offset/clip;
149
+ - 页面 CSS(`html[data-gufa-float]` 已把背景改成 rgba)即可透出下层 App。
150
+ 另一条低风险折中路线:`WS_EX_LAYERED + SetLayeredWindowAttributes(LWA_ALPHA)`(窗口整体 alpha,
151
+ 与网页 CSS 叠加,观感一般,且 WebView2 下稳定性待真机验证),未采用。
152
+ 2. **Windows 虚拟桌面**:没有稳定公开 API,切换虚拟桌面时悬浮窗可能留在原桌面;
153
+ 只保证「当前桌面可用」(协议 §2.7 要求写明的平台限制)。
154
+ 3. **窗口无系统阴影/圆角**(`WM_NCCALCSIZE` 去掉了非客户区);不影响功能,后续可用 DWM 相关 API 美化。
155
+ 4. **`payload.alpha` 未用于原生窗口**:首版不透明,透明度按协议「优先由网页 CSS 决定」;
156
+ 页面自己会通过 `float.getPrefs`/`--gufa-float-alpha` 读取偏好。
157
+ 5. **helper 不提供 `--list-windows`**:Windows 的摸鱼窗口列表由 Host 侧用 PowerShell 实现
158
+ (`host/dev.js` 的 `listFloatWindowsWin`,协议 §5.1「列表 Host 侧实现」)。
159
+ 6. **缓存策略**:按 payload.build 分 WebView2 profile 目录,未实现 macOS 那样的「同版本只清内存缓存」;
160
+ 旧版本 profile 目录暂不自动删除(体积有限,后续可清理)。
161
+ 7. **截图/录屏/输入法/高对比度主题**等桌面集成细节未专门处理;WebView2 使用系统输入法。
162
+ 8. **本机(macOS)无法编译**:交付前已逐行核对 WebView2 SDK 1.0.2903.40 的头文件签名与 Win32 API,
163
+ 但首次 CI/真机构建仍可能暴露编译警告或平台差异,见「排障」。
164
+
165
+ ## 排障
166
+
167
+ - **CI 构建失败**:先看 `Fetch WebView2 SDK (NuGet)` 是否成功、`WEBVIEW2_SDK_DIR` 是否指向解压根目录;
168
+ CMake configure 阶段的 `FATAL_ERROR` 会明确说明缺哪个文件。
169
+ - **链接报 `CreateCoreWebView2EnvironmentWithOptions` 未解析**:说明没链上 `WebView2LoaderStatic.lib`
170
+ (CMake 会打印实际使用的库路径,检查架构是否 x64)。
171
+ - **运行弹「无法启动 WebView2」**:安装 WebView2 Runtime(Windows 10/11 通常自带),或检查
172
+ `HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}` 是否存在。
173
+ - **悬浮窗出现但页面空白**:看 `%TEMP%\gufa-float-debug.log` 里 `webview2-*`、`navigation-completed`、
174
+ `page-probe` 记录;`page-probe` 会给出 href/title/localStorage 标记。
175
+ - **退出后主窗口没回来**:正常路径会恢复;若 helper 被强杀,Host 侧 `killFloat()` 有 PowerShell 兜底恢复。
176
+ 为减少该情况,helper 自身还有 ① controlPath 优雅退出、② Host 进程消失自动退出、③ 崩溃过滤器恢复三层兜底。
177
+
178
+ ## 真机验收建议(对照协议 §5)
179
+
180
+ 1. 主窗口点「摸鱼」→ 列表选一个 App → 悬浮层出现、位置尺寸与目标窗口一致、DSH 主窗口隐藏;
181
+ 2. 移动/缩放目标 App → 悬浮层 250ms 内跟随;切到目标 App 全屏 → 悬浮层跟随;
182
+ 3. 点悬浮层标题栏(网页内)「退出摸鱼」或顶部条「✕」→ DSH 主窗口恢复并前置、helper 退出;
183
+ 4. 自由悬浮模式可拖动/缩放,重启后窗口大小位置保留;
184
+ 5. 退出后任务管理器 / `tasklist | findstr gufa-float` 无残留进程。