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.
This commit is contained in:
parent
124f11bd6b
commit
9e12431db8
@ -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;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user