From 900a3d598bc6b19db669e9b409aefe4df96bdd3e Mon Sep 17 00:00:00 2001 From: winewill Date: Fri, 6 Nov 2026 17:47:04 +0800 Subject: [PATCH] fix(desktop): defer installer completion through system menus --- apps/desktop/README.i18n.yaml | 4 +- apps/desktop/README.md | 2 +- apps/desktop/README.zh.md | 2 +- apps/desktop/installer/pages.nsh | 1 + apps/desktop/installer/window-frame.cpp | 22 ++++---- .../tests/windows-installer-presentation.cpp | 54 +++++++++++++++---- .../tests/windows-installer-render.cpp | 19 +++---- 7 files changed, 73 insertions(+), 31 deletions(-) diff --git a/apps/desktop/README.i18n.yaml b/apps/desktop/README.i18n.yaml index 60c3a56059..9fb3bc2229 100644 --- a/apps/desktop/README.i18n.yaml +++ b/apps/desktop/README.i18n.yaml @@ -54,8 +54,8 @@ en: ac31ebdd9de54f34 zh: 921e534d5c4b3a16 /deepseek-harness-desktop/windows-installer-interface: - en: 7918faaa7a8fd9d6 - zh: 67ee74e3a6ababe2 + en: 4dd9eed5d99cc568 + zh: c913afe987e56ded /deepseek-harness-desktop/updates: en: 8b0b9efeb83727ef zh: 5ee95de48ceab392 diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 4761229b78..477f0b89ca 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -256,7 +256,7 @@ During a confirmed Windows update restart, a separate process displays a draggab The Windows installer uses native NSIS pages with light and dark palettes, system shadows, an editable installation directory, and a finish page whose launch checkbox is selected by default. Installation is restricted to the current user. Clicking Install or pressing Enter validates the current path; drive roots remain invalid after normalization, including repeated trailing separators. New destinations must be empty, and nonempty destinations must be registered installations. Running executables at the affected installation path produce a native prompt and remain running; same-named applications in other directories do not block installation. Silent updates wait up to ten seconds for the affected application to exit, then stop with exit code 2 if it is still running. -The theme follows Windows at startup; `/THEME=light`, `/THEME=dark`, and `/THEME=auto` select a palette explicitly. The window appears after its branded controls are ready. When the welcome page first appears, the installer moves above ordinary windows once and flashes its taskbar button if another window has focus; it does not remain always on top. Progress reads the pinned 7-Zip extractor’s percentage; directory promotion, registration, and cleanup retain bounded estimates. The weighted percentage does not predict remaining time. After NSIS reports success, the bar fills over 600 ms and displays 100% briefly before the finish page appears; the transition targets 750 ms. The finish page preserves the window position and waits for an active native window move to return before opening. During installation, Close is disabled and dimmed without changing the cursor. On the finish page, Close exits without launching the application. Finish dismisses the installer before launching the installed executable; a launch failure restores the page for retry. Directory replacement and failure recovery follow the [installation checks](packaging/README.md#runtime-file-selection). First-launch profile preparation remains a separate Desktop operation. +The theme follows Windows at startup; `/THEME=light`, `/THEME=dark`, and `/THEME=auto` select a palette explicitly. The window appears after its branded controls are ready. When the welcome page first appears, the installer moves above ordinary windows once and flashes its taskbar button if another window has focus; it does not remain always on top. Progress reads the pinned 7-Zip extractor’s percentage; directory promotion, registration, and cleanup retain bounded estimates. The weighted percentage does not predict remaining time. After NSIS reports success, the bar fills over 600 ms and displays 100% briefly before the finish page appears; the transition targets 750 ms. The finish page preserves the window position and waits for an active native window move or system menu to return before opening. During installation, the Close button is disabled and dimmed without changing the cursor. On the finish page, Close exits without launching the application. Finish dismisses the installer before launching the installed executable; a launch failure restores the page for retry. Directory replacement and failure recovery follow the [installation checks](packaging/README.md#runtime-file-selection). First-launch profile preparation remains a separate Desktop operation. Windows packaging compiles an x86 Win32/GDI+ helper with Visual C++ Build Tools and a Windows SDK; signed builds sign this helper through the configured Windows signer. The progress page keeps one opaque pixel buffer for its lifetime, draws static artwork once, and copies repainted pixels with GDI. The preparation hook leaves production dependency collection to electron-builder on every platform. diff --git a/apps/desktop/README.zh.md b/apps/desktop/README.zh.md index 729c1a7a0d..75c7736b18 100644 --- a/apps/desktop/README.zh.md +++ b/apps/desktop/README.zh.md @@ -256,7 +256,7 @@ Windows 更新确认重启后,独立进程显示可拖动的状态提示,直 Windows 安装程序使用原生 NSIS 页面,提供亮暗配色、系统阴影、可编辑的安装目录,以及默认勾选立即启动的完成页。安装仅面向当前用户。点击安装或按 Enter 均校验当前路径;路径规范化后仍拒绝磁盘根目录,包括带重复末尾分隔符的写法。新安装位置必须为空,非空位置必须是已登记的安装目录。受影响安装路径中的程序运行时显示系统提示,并保持应用运行;其他目录中的同名应用不阻止安装。静默更新最多等待受影响应用退出十秒,若仍在运行则以退出码 2 结束。 -主题在启动时跟随 Windows;可用 `/THEME=light`、`/THEME=dark` 和 `/THEME=auto` 显式选择配色。窗口在品牌控件准备完成后显示。欢迎页首次出现时,安装窗口会一次性移到普通窗口前方;若焦点在其他窗口,任务栏按钮会闪烁提示,但安装窗口不会始终置顶。进度读取锁定版本的 7-Zip 解压器百分比;目录替换、注册和清理仍使用有界估算。加权百分比不代表剩余时间。NSIS 报告成功后,进度条用 600 毫秒补满并短暂显示 100%,再显示完成页;切换目标时长为 750 毫秒。完成页保留窗口位置,并等待正在进行的原生窗口移动调用返回后再显示。安装中关闭按钮禁用并变灰,鼠标指针保持不变;完成页的关闭按钮退出安装器且不启动应用。点击完成后,安装程序先隐藏窗口,再启动已安装的可执行文件;启动失败会恢复页面以供重试。目录替换和失败恢复遵循[安装检查](packaging/README.zh.md#runtime-file-selection)。首次启动的配置档案准备仍属于独立的 Desktop 操作。 +主题在启动时跟随 Windows;可用 `/THEME=light`、`/THEME=dark` 和 `/THEME=auto` 显式选择配色。窗口在品牌控件准备完成后显示。欢迎页首次出现时,安装窗口会一次性移到普通窗口前方;若焦点在其他窗口,任务栏按钮会闪烁提示,但安装窗口不会始终置顶。进度读取锁定版本的 7-Zip 解压器百分比;目录替换、注册和清理仍使用有界估算。加权百分比不代表剩余时间。NSIS 报告成功后,进度条用 600 毫秒补满并短暂显示 100%,再显示完成页;切换目标时长为 750 毫秒。完成页保留窗口位置,并等待正在进行的原生窗口移动或系统菜单调用返回后再显示。安装中关闭按钮禁用并变灰,鼠标指针保持不变;完成页的关闭按钮退出安装器且不启动应用。点击完成后,安装程序先隐藏窗口,再启动已安装的可执行文件;启动失败会恢复页面以供重试。目录替换和失败恢复遵循[安装检查](packaging/README.zh.md#runtime-file-selection)。首次启动的配置档案准备仍属于独立的 Desktop 操作。 Windows 打包使用 Visual C++ Build Tools 和 Windows SDK 编译 x86 Win32/GDI+ 辅助库;签名构建通过已配置的 Windows 签名器对该库签名。进度页在其生命周期内保留一个不透明像素缓冲,只绘制一次静态图像,并通过 GDI 复制重绘的像素。准备钩子在所有平台上均由 electron-builder 继续负责收集生产依赖。 diff --git a/apps/desktop/installer/pages.nsh b/apps/desktop/installer/pages.nsh index 1bbf9cd467..cb586351de 100644 --- a/apps/desktop/installer/pages.nsh +++ b/apps/desktop/installer/pages.nsh @@ -220,6 +220,7 @@ Function InstallerWelcomeLeave ${EndIf} FunctionEnd +; Both Finish and Close use this exit path; Close clears the launch selection. Function InstallerFinishLeave ${NSD_GetState} $InstallerLaunch $0 HideWindow diff --git a/apps/desktop/installer/window-frame.cpp b/apps/desktop/installer/window-frame.cpp index 1062815b14..9ca637ae92 100644 --- a/apps/desktop/installer/window-frame.cpp +++ b/apps/desktop/installer/window-frame.cpp @@ -178,6 +178,7 @@ static UINT CaptionCommand(const ProgressPage& page, LPARAM position) { const int x = static_cast(LOWORD(position)); const int y = static_cast(HIWORD(position)); if (y < 0 || y >= MulDiv(48, page.dpi, 96) || x < MulDiv(504, page.dpi, 96) || x >= MulDiv(600, page.dpi, 96)) return 0; + // Installation cannot be cancelled with the progress page close button. return x >= MulDiv(548, page.dpi, 96) ? 0 : SC_MINIMIZE; } @@ -185,7 +186,8 @@ static void PaintCaptionButtons(Graphics& graphics, const ProgressPage& page) { SolidBrush background(page.dark ? Color(255, 21, 21, 23) : Color(255, 255, 255, 255)); graphics.FillRectangle(&background, 504, 0, 96, 48); SolidBrush ink(page.dark ? Color(255, 255, 255, 255) : Color(255, 15, 17, 21)); - SolidBrush disabledInk(page.dark ? Color(255, 97, 102, 107) : Color(255, 173, 177, 184)); + // Disabled caption uses the same foreground with reduced opacity in both themes. + SolidBrush disabledInk(page.dark ? Color(96, 255, 255, 255) : Color(96, 15, 17, 21)); FontFamily family(L"Microsoft YaHei UI"); Font font(&family, 16, FontStyleRegular, UnitPixel); StringFormat centered; @@ -411,30 +413,32 @@ extern "C" __declspec(dllexport) BOOL __cdecl InstallerFinishProgress(HWND windo } struct FrameState { - unsigned moveDepth = 0; + unsigned modalDepth = 0; bool nextPending = false; }; // NSIS advances synchronously into nsDialogs::Show. Its nested loop must not -// start until DefWindowProc has returned from moving the window and released input. -constexpr UINT NotifyOuterNext = WM_USER + 8; +// start until DefWindowProc has returned from moving the window or tracking its system menu. +// NSIS ui.h: WM_NOTIFY_OUTER_NEXT; also declared in installer/pages.nsh. +constexpr UINT WM_NOTIFY_OUTER_NEXT = WM_USER + 8; static LRESULT CALLBACK FrameProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam, UINT_PTR id, DWORD_PTR data) { auto* state = reinterpret_cast(data); - if (message == NotifyOuterNext && wparam == 1 && state->moveDepth) { + if (message == WM_NOTIFY_OUTER_NEXT && wparam == 1 && state->modalDepth) { state->nextPending = true; return 0; } - if (message == WM_SYSCOMMAND && ((wparam & 0xfff0) == SC_MOVE || (wparam & 0xfff0) == SC_SIZE)) { - ++state->moveDepth; + if (message == WM_SYSCOMMAND && ((wparam & 0xfff0) == SC_MOVE || (wparam & 0xfff0) == SC_SIZE + || (wparam & 0xfff0) == SC_KEYMENU || (wparam & 0xfff0) == SC_MOUSEMENU)) { + ++state->modalDepth; const LRESULT result = DefSubclassProc(window, message, wparam, lparam); DWORD_PTR remaining = 0; // Destruction inside the native loop also destroys the frame state. if (GetWindowSubclass(window, FrameProc, id, &remaining) && remaining == data) { - if (--state->moveDepth == 0 && state->nextPending) { + if (--state->modalDepth == 0 && state->nextPending) { state->nextPending = false; - PostMessageW(window, NotifyOuterNext, 1, 0); + PostMessageW(window, WM_NOTIFY_OUTER_NEXT, 1, 0); } } return result; diff --git a/apps/desktop/tests/windows-installer-presentation.cpp b/apps/desktop/tests/windows-installer-presentation.cpp index ebcce344aa..4b9619b27b 100644 --- a/apps/desktop/tests/windows-installer-presentation.cpp +++ b/apps/desktop/tests/windows-installer-presentation.cpp @@ -6,12 +6,17 @@ extern "C" __declspec(dllimport) BOOL __cdecl InstallerPresentWelcome(HWND window); extern "C" __declspec(dllimport) HRESULT __cdecl InstallerApplyFrame(HWND window); +// NSIS ui.h and installer/pages.nsh define this outer-page notification. +constexpr UINT WM_NOTIFY_OUTER_NEXT = WM_USER + 8; + struct MoveTest { bool moving = false; bool reentered = false; bool destroyDuringMove = false; bool native = false; bool entered = false; + bool captionEntry = false; + unsigned transitions = 0; }; @@ -26,21 +31,25 @@ static LRESULT CALLBACK MoveProc(HWND window, UINT message, WPARAM wparam, LPARA test = static_cast(reinterpret_cast(lparam)->lpCreateParams); SetWindowLongPtrW(window, GWLP_USERDATA, reinterpret_cast(test)); } - if (test && message == WM_USER + 8) { + if (test && message == WM_NOTIFY_OUTER_NEXT) { ++test->transitions; test->reentered = test->reentered || test->moving; return 0; } - if (test && test->native && message == WM_ENTERSIZEMOVE) { + if (test && test->native && (message == WM_ENTERSIZEMOVE || message == WM_ENTERMENULOOP)) { test->entered = true; PostMessageW(window, WM_APP, 0, 0); } if (test && test->native && message == WM_APP) { - SendMessageW(window, WM_USER + 8, 1, 0); + SendMessageW(window, WM_NOTIFY_OUTER_NEXT, 1, 0); + if (test->captionEntry) { + INPUT release = {}; release.type = INPUT_MOUSE; release.mi.dwFlags = MOUSEEVENTF_LEFTUP; + SendInput(1, &release, sizeof(release)); + } SendMessageW(window, WM_CANCELMODE, 0, 0); return 0; } - if (test && message == WM_SYSCOMMAND && (wparam & 0xfff0) == SC_MOVE) { + if (test && message == WM_SYSCOMMAND && ((wparam & 0xfff0) == SC_MOVE || (wparam & 0xfff0) == SC_KEYMENU || (wparam & 0xfff0) == SC_MOUSEMENU)) { if (test->native) { test->moving = true; const LRESULT result = DefWindowProcW(window, message, wparam, lparam); @@ -51,7 +60,7 @@ static LRESULT CALLBACK MoveProc(HWND window, UINT message, WPARAM wparam, LPARA // that notification alone is not evidence that the move call returned. test->moving = true; SendMessageW(window, WM_ENTERSIZEMOVE, 0, 0); - SendMessageW(window, WM_USER + 8, 1, 0); + SendMessageW(window, WM_NOTIFY_OUTER_NEXT, 1, 0); Drain(window); SendMessageW(window, WM_EXITSIZEMOVE, 0, 0); Drain(window); @@ -62,23 +71,47 @@ static LRESULT CALLBACK MoveProc(HWND window, UINT message, WPARAM wparam, LPARA return DefWindowProcW(window, message, wparam, lparam); } -static bool TestMoveCompletion(HINSTANCE instance, bool destroy, bool native = false) { +static bool TestMoveCompletion(HINSTANCE instance, bool destroy, bool native = false, bool captionEntry = false, UINT menu = 0) { MoveTest test; test.destroyDuringMove = destroy; test.native = native; - HWND window = CreateWindowExW(0, L"HarnessInstallerMoveTest", L"", WS_POPUP, + test.captionEntry = captionEntry; + + HWND window = CreateWindowExW(0, L"HarnessInstallerMoveTest", L"", WS_POPUP | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 100, 100, nullptr, nullptr, instance, &test); if (!window) return false; if (FAILED(InstallerApplyFrame(window))) { DestroyWindow(window); return false; } RECT clipBefore, clipAfter; GetClipCursor(&clipBefore); if (native) ShowWindow(window, SW_SHOWNOACTIVATE); - SendMessageW(window, WM_SYSCOMMAND, native ? SC_MOVE : SC_MOVE | 2, 0); + if (menu) SetForegroundWindow(window); + POINT cursorBefore; + GetCursorPos(&cursorBefore); + if (captionEntry) { + SetForegroundWindow(window); + SetCursorPos(50, 24); + INPUT press = {}; press.type = INPUT_MOUSE; press.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; + const UINT sent = SendInput(1, &press, sizeof(press)); + if (sent != 1) { DestroyWindow(window); SetCursorPos(cursorBefore.x, cursorBefore.y); return false; } + const ULONGLONG deadline = GetTickCount64() + 2000; + while (!(GetAsyncKeyState(VK_LBUTTON) & 0x8000) && GetTickCount64() < deadline) { + Drain(window); + MsgWaitForMultipleObjectsEx(0, nullptr, 10, QS_ALLINPUT, MWMO_INPUTAVAILABLE); + } + Drain(window); + + SendMessageW(window, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(50, 24)); + INPUT release = {}; release.type = INPUT_MOUSE; release.mi.dwFlags = MOUSEEVENTF_LEFTUP; + SendInput(1, &release, sizeof(release)); + } else { + SendMessageW(window, WM_SYSCOMMAND, menu ? menu : native ? SC_MOVE : SC_MOVE | 2, menu == SC_KEYMENU ? VK_SPACE : 0); + } + SetCursorPos(cursorBefore.x, cursorBefore.y); const bool deferred = test.transitions == 0 && !test.reentered; if (destroy) return deferred && !IsWindow(window); Drain(window); const bool delivered = test.transitions == 1 && !test.reentered; - SendMessageW(window, WM_USER + 8, 1, 0); + SendMessageW(window, WM_NOTIFY_OUTER_NEXT, 1, 0); const bool ordinary = test.transitions == 2; GetClipCursor(&clipAfter); GUITHREADINFO input = {sizeof(input)}; @@ -107,6 +140,9 @@ int wmain() { if (!RegisterClassW(&type)) return 7; if (!TestMoveCompletion(instance, false) || !TestMoveCompletion(instance, true)) return 8; if (!TestMoveCompletion(instance, false, true)) return 9; + if (!TestMoveCompletion(instance, false, true, true)) return 10; + if (!TestMoveCompletion(instance, false, true, false, SC_KEYMENU)) return 11; + if (!TestMoveCompletion(instance, false, true, false, SC_MOUSEMENU)) return 12; std::puts("Move completion deferred until native call returns; destruction discards pending transition."); HWND installer = CreateWindowExW(0, L"STATIC", L"Installer", WS_POPUP, 100, 100, 300, 300, nullptr, nullptr, instance, nullptr); diff --git a/apps/desktop/tests/windows-installer-render.cpp b/apps/desktop/tests/windows-installer-render.cpp index ab9bc778fa..5edbb839eb 100644 --- a/apps/desktop/tests/windows-installer-render.cpp +++ b/apps/desktop/tests/windows-installer-render.cpp @@ -124,14 +124,15 @@ int wmain(int argc, wchar_t** argv) { }; bool captionStates = true; ShowWindow(progress, SW_HIDE); - for (int x : {504}) { + { + constexpr int x = 504; const LPARAM point = MAKELPARAM(MulDiv(x + 20, dpi, 96), MulDiv(24, dpi, 96)); captionStates = expectPixel(x, normalColor) && captionStates; SendMessageW(progress, WM_MOUSEMOVE, 0, point); captionStates = expectPixel(x, hoverColor) && captionStates; SendMessageW(progress, WM_LBUTTONDOWN, MK_LBUTTON, point); captionStates = expectPixel(x, pressedColor) && captionStates; - const int other = x == 504 ? 548 : 504; + constexpr int other = 548; SendMessageW(progress, WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(MulDiv(other + 20, dpi, 96), MulDiv(24, dpi, 96))); captionStates = expectPixel(other, normalColor) && captionStates; captionStates = expectPixel(x, normalColor) && captionStates; @@ -167,15 +168,15 @@ int wmain(int argc, wchar_t** argv) { const LPARAM closePoint = MAKELPARAM(MulDiv(568, dpi, 96), MulDiv(24, dpi, 96)); MSG closeMessage; SendMessageW(progress, WM_LBUTTONDOWN, MK_LBUTTON, closePoint); - bool closeRelease = GetCapture() != progress && expectPixel(548, normalColor) + bool closeDisabled = GetCapture() != progress && expectPixel(548, normalColor) && !PeekMessageW(&closeMessage, window, WM_CLOSE, WM_CLOSE, PM_REMOVE); SendMessageW(progress, WM_MOUSEMOVE, MK_LBUTTON, closePoint); - closeRelease = closeRelease && expectPixel(548, normalColor); + closeDisabled = closeDisabled && expectPixel(548, normalColor); SendMessageW(progress, WM_LBUTTONUP, 0, minimizePoint); - closeRelease = closeRelease && !PeekMessageW(&closeMessage, window, WM_CLOSE, WM_CLOSE, PM_REMOVE); + closeDisabled = closeDisabled && !PeekMessageW(&closeMessage, window, WM_CLOSE, WM_CLOSE, PM_REMOVE); SendMessageW(progress, WM_LBUTTONDOWN, MK_LBUTTON, closePoint); SendMessageW(progress, WM_LBUTTONUP, 0, closePoint); - closeRelease = closeRelease && !PeekMessageW(&closeMessage, window, WM_CLOSE, WM_CLOSE, PM_REMOVE) && GetCapture() != progress; + closeDisabled = closeDisabled && !PeekMessageW(&closeMessage, window, WM_CLOSE, WM_CLOSE, PM_REMOVE) && GetCapture() != progress; LARGE_INTEGER frequency, started, finished; QueryPerformanceFrequency(&frequency); std::vector samples; @@ -207,7 +208,7 @@ int wmain(int argc, wchar_t** argv) { DestroyWindow(progress); const DWORD finalGdi = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS); DestroyWindow(window); - std::printf("client_frame=%d stock_preserved=%d completed=%d final_caption=%d caption_states=%d button_release=%d close_release=%d minimized=%d restored=%d gdi_before=%lu gdi_after=%lu\n", - clientFrame, failurePreservesStock, completed, finalCaption, captionStates, buttonRelease, closeRelease, minimized, restored, initialGdi, finalGdi); - return clientFrame && failurePreservesStock && completed && finalCaption && captionStates && buttonRelease && closeRelease && minimized && restored && finalGdi <= initialGdi ? 0 : 6; + std::printf("client_frame=%d stock_preserved=%d completed=%d final_caption=%d caption_states=%d button_release=%d close_disabled=%d minimized=%d restored=%d gdi_before=%lu gdi_after=%lu\n", + clientFrame, failurePreservesStock, completed, finalCaption, captionStates, buttonRelease, closeDisabled, minimized, restored, initialGdi, finalGdi); + return clientFrame && failurePreservesStock && completed && finalCaption && captionStates && buttonRelease && closeDisabled && minimized && restored && finalGdi <= initialGdi ? 0 : 6; }