fix: 修复三个启动相关 Bug

Bug 1: prompt()/confirm() 在 Electron contextIsolation 下不可用
- 新增 prompt-modal.ts 自定义弹窗组件
- 替换 memory-panel.ts、kb-modal.ts、settings-modal.ts、history-modal.ts 中所有 prompt()/confirm() 调用

Bug 2: 日志面板重启后无日志
- log-service.ts 新增 earlyBuffer 缓冲 initLogPanel() 之前的日志
- initLogPanel() 初始化时 flush earlyBuffer 到 DOM
- main.ts 中 initLogPanel() 移至最先初始化

Bug 3: 首次启动输入框可能被禁用
- main.ts init() 中防御性重置 IS_STREAMING/IS_HISTORY_VIEW/toolCallingEnabled 等状态
- catch 块也重置关键状态并初始化日志面板
This commit is contained in:
Metona Dev
2026-04-06 20:11:41 +08:00
parent 70fef8e969
commit c516755a5c
7 changed files with 239 additions and 24 deletions
+31
View File
@@ -23,6 +23,9 @@ let autoScroll = true;
let idCounter = 0;
let renderQueued = false;
const pendingEntries: LogEntry[] = [];
let panelInitialized = false;
/** initLogPanel 前的日志暂存区 */
const earlyBuffer: LogEntry[] = [];
const LEVEL_ICONS: Record<LogLevel, string> = {
info: '️',
@@ -69,6 +72,28 @@ export function initLogPanel(): void {
autoScroll = el.scrollHeight - el.scrollTop - el.clientHeight < 40;
} catch { /* ignore */ }
});
// ── 关键修复:flush initLogPanel 前缓冲的日志 ──
panelInitialized = true;
if (earlyBuffer.length > 0 && logBodyEl) {
const frag = document.createDocumentFragment();
for (const entry of earlyBuffer) {
const div = document.createElement('div');
div.className = `log-entry log-${entry.level}`;
div.id = entry.id;
let html = `<span class="log-time">${formatTime(entry.time)}</span>`;
html += `<span class="log-icon">${entry.icon}</span>`;
html += `<span class="log-msg">${escapeHtml(entry.message)}</span>`;
if (entry.detail) {
html += `<pre class="log-detail">${escapeHtml(entry.detail)}</pre>`;
}
div.innerHTML = html;
frag.appendChild(div);
}
logBodyEl.appendChild(frag);
earlyBuffer.length = 0;
if (autoScroll) logBodyEl.scrollTop = logBodyEl.scrollHeight;
}
} catch { /* ignore */ }
}
@@ -137,6 +162,12 @@ export function addLog(level: LogLevel, message: string, detail?: string, icon?:
logs.push(entry);
if (logs.length > MAX_LOGS) logs.splice(0, logs.length - MAX_LOGS);
// initLogPanel 之前:暂存到 earlyBuffer
if (!panelInitialized) {
earlyBuffer.push(entry);
return;
}
pendingEntries.push(entry);
if (!renderQueued) {
renderQueued = true;