From 9e12431db89874cc9b99e5256dbcd72c807f3621 Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Thu, 5 Nov 2026 13:48:49 +0800 Subject: [PATCH] fix: notice dialog topmost - owner form pattern instead of invalid enum value 262144 (Win32 MB_TOPMOST) has no mapping in the .NET MessageBoxOptions enum, whose only members are RightAlign/RtlReading/ServiceNotification etc., so PowerShell rejected it: "cannot convert 262144 to MessageBoxOptions" (second failure of the topmost attempt). Correct documented way is passing a TopMost invisible owner form as the first argument of MessageBox.Show. Wrapped in try/catch that falls back to a plain Show, so the dialog can no longer fail the node even if the owner pattern misbehaves on some machine. --- packages/rpa-core/src/capabilities/desktop.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/rpa-core/src/capabilities/desktop.ts b/packages/rpa-core/src/capabilities/desktop.ts index 77097e5..c72af81 100644 --- a/packages/rpa-core/src/capabilities/desktop.ts +++ b/packages/rpa-core/src/capabilities/desktop.ts @@ -154,9 +154,10 @@ const notice: CapabilityHandler = async (_ctx, _node, args) => { // MessageBox 阻塞等用户点确定,同样不能吃 powershell() 默认 30s 超时;且 MB_TOPMOST 保证弹窗不被主窗口盖住 const waitSeconds = number(args, ["wait_time", "waitTime", "timeout"], 600); const timeoutMs = Math.max(10000, Math.round(waitSeconds * 1000)); - // MessageBoxOptions 第 6 参数用 MB_TOPMOST(0x40000=262144) 标志位实现置顶;此前误传 'HelpButton'(图标枚举值) - // 导致 PowerShell 类型转换失败「无法将 HelpButton 转换为 MessageBoxOptions」 - await powershell(`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show(${psString(content)},${psString(title)},'OK','Information','Button1',[System.Windows.Forms.MessageBoxOptions]262144) | Out-Null`, timeoutMs); + // 置顶方案: MB_TOPMOST/262144 是 Win32 老接口标志, .NET MessageBoxOptions 枚举里没有(只有 RightAlign/RtlReading/ServiceNotification 等), + // 传 262144 会被 PS 枚举转换拒绝。正确做法是传一个 TopMost 的隐形属主窗体; + // 属主窗体万一失败则 catch 降级为普通 Show, 保证弹窗一定出现不阻塞流程。 + await powershell(`Add-Type -AssemblyName System.Windows.Forms; $f = New-Object System.Windows.Forms.Form; $f.TopMost = $true; try { [System.Windows.Forms.MessageBox]::Show($f,${psString(content)},${psString(title)},'OK','Information') | Out-Null } catch { [System.Windows.Forms.MessageBox]::Show(${psString(content)},${psString(title)},'OK','Information') | Out-Null }; $f.Dispose()`, timeoutMs); return true; };