对话框 API 提供了在桌面端和 Web 环境下都能一致工作的标准化对话框。扩展作者会发现 prompt 和 confirm 方法最为实用。

基本用法

输入对话框(Prompt Dialog)

// 显示一个输入对话框
app.extensionManager.dialog.prompt({
  title: "用户输入",
  message: "请输入你的姓名:",
  defaultValue: "User"
}).then(result => {
  if (result !== null) {
    console.log(`输入内容: ${result}`);
  }
});

确认对话框(Confirm Dialog)

// 显示一个确认对话框
app.extensionManager.dialog.confirm({
  title: "确认操作",
  message: "你确定要继续吗?",
  type: "default"
}).then(result => {
  console.log(result ? "用户已确认" : "用户已取消");
});

API 参考

Prompt

app.extensionManager.dialog.prompt({
  title: string,             // 对话框标题
  message: string,           // 显示的消息/问题
  defaultValue?: string      // 输入框的初始值(可选)
}).then((result: string | null) => {
  // result 是输入的文本,若取消则为 null
});

Confirm

app.extensionManager.dialog.confirm({
  title: string,             // 对话框标题
  message: string,           // 显示的消息
  type?: "default" | "overwrite" | "delete" | "dirtyClose" | "reinstall", // 对话框类型(可选)
  itemList?: string[],       // 要显示的项目列表(可选)
  hint?: string              // 显示的提示文本(可选)
}).then((result: boolean | null) => {
  // result 为 true 表示确认,false 表示拒绝,null 表示取消
});

如需了解 ComfyUI 中其他专用对话框,扩展作者可参考源码中的 dialogService.ts 文件。