#480·Mineradio

bug用户点击“新建歌单”,程序想弹出一个“请输入歌单名字”的输入框,但 Electron 根本不支持它使用的这个输入框,所以按钮点了以后直接报错了。

Author: wu-xing-aiCreated Sep 19, 2026Updated Sep 19, 2026

「新建内置歌单」等按钮点击无反应(Electron 不支持 window.prompt)

severity component type platform status

字段 值
组件 内置歌单(创建 / 重命名)、FX 预设短码
严重级别 Medium — 功能完全失效且无任何报错提示,用户无法判断原因
类型 Electron 运行时不兼容(window.prompt 未实现)
影响版本 2025-09-07 构建(resources/app)
状态 已定位 · 已修复 · 已在真实 Chromium 验证

目录

  1. 摘要
  2. 为什么删除能用、新建不能用
  3. 复现步骤
  4. 根因
  5. 受影响清单
  6. 修复方案
  7. 验证结果
  8. 上游建议

1. 摘要

点击「+ 新建内置」按钮完全没有反应 —— 不弹窗、不报错、不提示。

对已有内置歌单执行「重命名」同样毫无反应。

[!IMPORTANT] 这不是逻辑 bug,而是 Electron 从未实现 window.prompt()。

Electron 官方在 window-setup.js 中直接让它抛异常:

prompt() is and will not be supported.

异常从 HTML 的 onclick 属性中冒泡出去被静默吞掉,因此表现为「按钮点了没反应」,控制台之外没有任何可见反馈。


2. 为什么删除能用、新建不能用

这是理解本 bug 的关键 —— Electron 对这三个 API 的支持并不一致:

API Electron 支持 应用中的用途 实际表现
window.alert ✅ 支持 (未使用) —
window.confirm ✅ 支持 删除内置歌单(00-built-in-playlists.js#L153) ✅ 正常工作
window.prompt ❌ 抛异常 新建内置歌单(#L94)、重命名(#L134) ❌ 点击无反应

[!NOTE] 这就是为什么用户可以删除歌单,却无法新建或重命名 —— 三个操作看起来在同一层级,底层用的却是不同 API。


3. 复现步骤

  • 1. 打开底部播放列表面板,切到「歌单」页(#pl-pane)
  • 2. 点击右上角「+ 新建内置」按钮
  • 3. 观察结果

实际结果

(无任何反应:不弹窗、不报错、不提示)

期望结果

弹出输入框,输入名称后创建歌单

同样失效的入口

  • 打开任意歌单 → 对内置歌单执行「重命名」
  • FX 面板 → 复制 MR2 短码(剪贴板失败时的降级路径)

4. 根因

4.1 调用点(补丁前)

public/js/modules/06-lyrics/00-built-in-playlists.js#L94

javascript
function promptCreateBuiltInPlaylist() {
  var name = window.prompt('新建 Mineradio 内置歌单', '我的歌单');   // ← 此处抛异常
  if (name == null) return;                                        // ← 永远执行不到
  createBuiltInPlaylist(name).catch(function (error) { ... });
}

public/js/modules/06-lyrics/00-built-in-playlists.js#L134

javascript
async function renameBuiltInPlaylist(id, currentName) {
  var name = window.prompt('重命名内置歌单', String(currentName || ''));   // ← 此处抛异常
  if (name == null || !String(name).trim()) return false;
  ...
}

public/js/modules/07-fx/00-preset-archive-data.js#L1080

javascript
window.prompt('复制这段 MR2 短代码', code);   // ← 剪贴板写入失败时的降级路径
showToast('已打开完整短码');                   // ← 永远执行不到

4.2 异常传播路径

mermaid
flowchart TD
    A["用户点击 + 新建内置"] --> B["onclick 调用 promptCreateBuiltInPlaylist()"]
    B --> C["执行 window.prompt(...)"]
    C --> D["Electron 抛出异常<br/>prompt() is and will not be supported."]
    D --> E["异常从 onclick 处理器冒泡"]
    E --> F["被浏览器静默丢弃(仅控制台可见)"]
    F --> G["界面无任何变化 → 用户以为按钮坏了"]
    style D fill:#5a1f1f,stroke:#c66,color:#fff
    style G fill:#5a1f1f,stroke:#c66,color:#fff

4.3 为什么应用里没有兜底

全项目检索确认:

  • 不存在 window.prompt 的 polyfill / 覆盖实现
  • 不存在自定义的文本输入弹窗(只有展示用的 #cookie-export-prompt,无输入能力)
bash
$ grep -rn "window.prompt\s*=\|prompt\s*=\s*function\|will not be supported" public/js desktop/
(无匹配)

因此三处调用点全部裸调用 window.prompt,无一例外都会失败。


5. 受影响清单

# 位置 功能 影响
1 00-built-in-playlists.js#L94 新建内置歌单 主功能完全失效
2 00-built-in-playlists.js#L134 重命名内置歌单 主功能完全失效
3 07-fx/00-preset-archive-data.js#L1080 复制 MR2 短码(降级路径) 剪贴板失败时无法手动复制

[!TIP] 影响 #3 只在 writeUserFxArchiveClipboard() 失败时触发,属于二次故障,优先级较低,但同一补丁顺带修复。


6. 修复方案

6.1 新增应用内文本输入弹窗 mrPrompt()

在 Modal 工具文件 public/js/modules/08-account/01-login-modal-utils.js 中新增(紧随 closeGsapModal 之后):

javascript
function mrPrompt(title, defaultValue, options) {
  options = options || {};
  return new Promise(function (resolve) {
    var multiline = !!options.multiline;
    var readonly = !!options.readonly;
    var maxLength = Math.max(1, Number(options.maxLength) || 60);

    var mask = document.createElement('div');
    mask.className = 'modal-mask';
    mask.innerHTML = '<div class="modal mr-prompt-modal">' +
      '<h2></h2>' +
      '<div class="collect-create">' +
      (multiline
        ? '<textarea class="mr-prompt-input" rows="8" spellcheck="false"></textarea>'
        : '<input class="mr-prompt-input" type="text" autocomplete="off">') +
      '</div>' +
      '<div class="btn-row">' +
      '<button type="button" class="modal-btn mr-prompt-cancel">取消</button>' +
      '<button type="button" class="modal-btn primary mr-prompt-ok">确定</button>' +
      '</div>' +
      '</div>';
    // ... 详见源码(含 ESC / 回车 / 遮罩点击 / 空值校验 / 焦点管理)
  });
}

接口契约

javascript
mrPrompt(title, defaultValue, options) → Promise<string|null>

  resolve(输入值)   点击「确定」或按回车(单行模式自动 trim)
  resolve(null)     点击「取消」/ 按 ESC / 点击遮罩

options:
  maxLength   单行最大长度,默认 60
  multiline   使用 textarea
  readonly    只读(按钮文案变为「关闭」)

[!NOTE] 零 CSS 改动。 弹窗完全复用应用既有的样式类: .modal-mask · .modal · .modal h2 · .collect-create input · .modal .btn-row · .modal-btn.primary

因此视觉上与 #collect-modal 等原生弹窗完全一致。

6.2 替换三处调用点

diff
 function promptCreateBuiltInPlaylist() {
-  var name = window.prompt('新建 Mineradio 内置歌单', '我的歌单');
-  if (name == null) return;
-  createBuiltInPlaylist(name).catch(function (error) {
+  return mrPrompt('新建 Mineradio 内置歌单', '我的歌单', { maxLength: 80 }).then(function (name) {
+    if (name == null) return;
+    return createBuiltInPlaylist(name);
+  }).catch(function (error) {
     console.warn('[BuiltInPlaylistCreate]', error);
     if (typeof showToast === 'function') showToast('创建内置歌单失败');
   });
 }
diff
 async function renameBuiltInPlaylist(id, currentName) {
-  var name = window.prompt('重命名内置歌单', String(currentName || ''));
+  var name = await mrPrompt('重命名内置歌单', String(currentName || ''), { maxLength: 80 });
   if (name == null || !String(name).trim()) return false;
diff
-      window.prompt('复制这段 MR2 短代码', code);
+      mrPrompt('复制这段 MR2 短代码', code, { multiline: true, readonly: true });
       showToast('已打开完整短码');

6.3 改动量

文件 变更
public/js/modules/08-account/01-login-modal-utils.js +92 / −0(新增 mrPrompt)
public/js/modules/06-lyrics/00-built-in-playlists.js +7 / −4
public/js/modules/07-fx/00-preset-archive-data.js +2 / −1
合计 +101 / −5

7. 验证结果

7.1 功能验证(真实 Chromium + 应用真实 CSS)

bash
$ node test-mrprompt.js
【1】基本创建:标题/默认值/按钮        6/6 ✓
【2】输入并点「确定」                  2/2 ✓   (含 trim 验证)
【3】回车提交                          2/2 ✓
【4】点「取消」返回 null               2/2 ✓
【5】ESC 返回 null                     1/1 ✓
【6】点击遮罩返回 null                 1/1 ✓
【7】空输入校验:不 resolve,提示且弹窗保留  3/3 ✓
【8】只读多行模式                      7/7 ✓   (含换行保留)

通过 24 / 24   全部通过 ✓

7.2 样式一致性验证

bash
$ node visual-check.js
=== 与原生 modal 规范值比对 ===
  ✓ modal 圆角        18px        ✓ input 高度      32px
  ✓ modal 内边距       32px        ✓ input 圆角       9px
  ✓ modal 最大宽度     380px       ✓ input 字号      12px
  ✓ modal 文本居中     center      ✓ 按钮行 display  flex
  ✓ h2 字号          18px        ✓ 遮罩定位        fixed
  ✓ h2 下边距         18px        ✓ 遮罩层级        50

  模态是否水平居中: ✓ 是  (中心 x=450.0, 视口中心 450)

全部一致 ✓

7.3 效果预览

mrPrompt 预览

深色渐变背景、18px 圆角、香槟金主按钮 —— 与内置歌单模块的 #collect-modal 视觉完全统一。 输入框内默认值已自动全选,可直接覆盖输入。

7.4 静态检查

bash
$ node --check public/js/modules/08-account/01-login-modal-utils.js   ✓
$ node --check public/js/modules/06-lyrics/00-built-in-playlists.js   ✓
$ node --check public/js/modules/07-fx/00-preset-archive-data.js      ✓

$ grep -rn "window.prompt" public/ desktop/ --include=*.js --include=*.html
(仅剩注释,无实际调用)✓

8. 上游建议

8.1 审计其它 Electron 不支持的浏览器 API

window.prompt 只是其中一例。建议做一次全量审计,重点关注:

API Electron 状态 备注
window.prompt ❌ 抛异常 本 bug
window.alert / window.confirm ✅ 支持 但为原生模态,会阻塞渲染进程
showOpenFilePicker / showSaveFilePicker ⚠️ 受限 建议改用主进程 dialog
navigator.clipboard ⚠️ 权限相关 建议改用 Electron clipboard
window.open ⚠️ 需 setWindowOpenHandler 否则可能被静默拦截

[!TIP] 建议加一道静态检查:在 CI / 构建脚本中 grep window.prompt,命中即失败。 一个 3 行的检查即可防止此类问题再次被引入。

javascript
// 建议加入构建前检查
const bad = /\bwindow\.prompt\s*\(/;

8.2 统一走 mrPrompt,避免再次误用

新增代码如需文本输入,一律使用 mrPrompt(),不要再碰 window.prompt。

window.confirm 虽然能用,但它是原生阻塞式模态,会冻结渲染进程(播放动画、歌词渲染全部暂停)。 若后续要统一体验,建议同样迁移到应用内的确认弹窗。


本报告基于真实运行环境复现与修复 · 修复已在真实 Chromium 中完成 24 项功能验证 + 12 项样式验证