fix: dialog components killed at 30s, pass proper timeout to powershell
Root cause: Dialog_InputBox and other blocking dialogs wait for user input, but powershell() default timeout 30000ms kills the still-waiting dialog process, reporting generic "Command failed" (reproduced: run failed at 30.08s). Fix: - InputBox/Notice default wait 600s, adjustable via wait_time arg - File dialogs (OpenFile/OpenFiles/SaveFile) wait up to 30min - InputBox timeout reports dialog_timeout with clear guidance instead of misleading command failure
This commit is contained in:
parent
2ae1010f67
commit
15fcf66972
@ -151,7 +151,10 @@ const clipboardSet: CapabilityHandler = async (_ctx, _node, args) => {
|
||||
const notice: CapabilityHandler = async (_ctx, _node, args) => {
|
||||
const title = text(args, ["title"], "提醒");
|
||||
const content = text(args, ["text", "message"]);
|
||||
await powershell(`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show(${psString(content)},${psString(title)}) | Out-Null`);
|
||||
// MessageBox 阻塞等用户点确定,同样不能吃 powershell() 默认 30s 超时;notice 组件的 timeout 参数按分钟级等待
|
||||
const waitSeconds = number(args, ["wait_time", "waitTime", "timeout"], 600);
|
||||
const timeoutMs = Math.max(10000, Math.round(waitSeconds * 1000));
|
||||
await powershell(`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show(${psString(content)},${psString(title)}) | Out-Null`, timeoutMs);
|
||||
return true;
|
||||
};
|
||||
|
||||
@ -204,26 +207,39 @@ register("Dialog_CsMsgBox", async (_ctx, _node, args) => {
|
||||
register("Dialog_OpenFile", async (_ctx, _node, args) => {
|
||||
const title = text(args, ["title"], "选择文件");
|
||||
const wildcard = text(args, ["wildcard"], "所有文件|*.*");
|
||||
return powershell("Add-Type -AssemblyName System.Windows.Forms | Out-Null; $dlg = New-Object System.Windows.Forms.OpenFileDialog; $dlg.Filter = " + psString(wildcard) + "; $dlg.Title = " + psString(title) + "; if ($dlg.ShowDialog() -eq 'OK') { $dlg.FileName } else { '' }");
|
||||
// ShowDialog 阻塞等用户选择,等待上限给到 30 分钟(文件挑选通常耗时更久)
|
||||
return powershell("Add-Type -AssemblyName System.Windows.Forms | Out-Null; $dlg = New-Object System.Windows.Forms.OpenFileDialog; $dlg.Filter = " + psString(wildcard) + "; $dlg.Title = " + psString(title) + "; if ($dlg.ShowDialog() -eq 'OK') { $dlg.FileName } else { '' }", 1800000);
|
||||
});
|
||||
|
||||
register("Dialog_OpenFiles", async (_ctx, _node, args) => {
|
||||
const title = text(args, ["title"], "选择文件");
|
||||
const wildcard = text(args, ["wildcard"], "所有文件|*.*");
|
||||
return powershell("Add-Type -AssemblyName System.Windows.Forms | Out-Null; $dlg = New-Object System.Windows.Forms.OpenFileDialog; $dlg.Filter = " + psString(wildcard) + "; $dlg.Title = " + psString(title) + "; $dlg.Multiselect = $true; if ($dlg.ShowDialog() -eq 'OK') { $dlg.FileNames -join ';' } else { '' }");
|
||||
return powershell("Add-Type -AssemblyName System.Windows.Forms | Out-Null; $dlg = New-Object System.Windows.Forms.OpenFileDialog; $dlg.Filter = " + psString(wildcard) + "; $dlg.Title = " + psString(title) + "; $dlg.Multiselect = $true; if ($dlg.ShowDialog() -eq 'OK') { $dlg.FileNames -join ';' } else { '' }", 1800000);
|
||||
});
|
||||
|
||||
register("Dialog_SaveFile", async (_ctx, _node, args) => {
|
||||
const title = text(args, ["title"], "保存文件");
|
||||
const wildcard = text(args, ["wildcard"], "所有文件|*.*");
|
||||
return powershell("Add-Type -AssemblyName System.Windows.Forms | Out-Null; $dlg = New-Object System.Windows.Forms.SaveFileDialog; $dlg.Filter = " + psString(wildcard) + "; $dlg.Title = " + psString(title) + "; if ($dlg.ShowDialog() -eq 'OK') { $dlg.FileName } else { '' }");
|
||||
return powershell("Add-Type -AssemblyName System.Windows.Forms | Out-Null; $dlg = New-Object System.Windows.Forms.SaveFileDialog; $dlg.Filter = " + psString(wildcard) + "; $dlg.Title = " + psString(title) + "; if ($dlg.ShowDialog() -eq 'OK') { $dlg.FileName } else { '' }", 1800000);
|
||||
});
|
||||
|
||||
register(["Dialog_InputBox", "Dialog_CsInputBox"], async (_ctx, _node, args) => {
|
||||
const title = text(args, ["title", "input_title"], "请输入");
|
||||
const description = text(args, ["description", "txt_content"], "");
|
||||
const defaultValue = text(args, ["text"], "");
|
||||
return powershell("Add-Type -AssemblyName Microsoft.VisualBasic | Out-Null; [Microsoft.VisualBasic.Interaction]::InputBox(" + psString(description) + ", " + psString(title) + ", " + psString(defaultValue) + ")");
|
||||
// 交互对话框会一直阻塞等用户输入,必须给 powershell() 传足够长的超时(默认 30s 会把还在等人的对话框进程杀掉,报 Command failed)。
|
||||
// 默认 10 分钟,可用 wait_time(秒)自定义;仍超时则报「用户未及时输入」而非笼统的 Command failed。
|
||||
const waitSeconds = number(args, ["wait_time", "waitTime", "timeout"], 600);
|
||||
const timeoutMs = Math.max(10000, Math.round(waitSeconds * 1000));
|
||||
return powershell(
|
||||
"Add-Type -AssemblyName Microsoft.VisualBasic | Out-Null; [Microsoft.VisualBasic.Interaction]::InputBox(" + psString(description) + ", " + psString(title) + ", " + psString(defaultValue) + ")",
|
||||
timeoutMs
|
||||
).catch((error) => {
|
||||
if (error instanceof RuntimeError && /Command failed/.test(error.message) && !error.message.includes("RPA_ERROR")) {
|
||||
throw new RuntimeError("dialog_timeout", `输入对话框等待超时(${Math.round(timeoutMs / 1000)} 秒)用户未完成输入`, { nodeId: _node.id, componentId: _node.componentId, recommendation: "在弹出的输入框中输入后点确定;如需更长等待时间,调大节点的超时时间或 wait_time 参数" });
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
register("Dialog_Notice", notice);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user