fix: 清理死代码、错误渲染防XSS、blob URL释放时机修复

This commit is contained in:
thzxx
2026-05-18 15:57:02 +08:00
parent addf8e4dd1
commit 69e2ee0713
2 changed files with 5 additions and 11 deletions
+5 -9
View File
@@ -120,13 +120,15 @@
// ===== Markdown Rendering =====
function renderMarkdown(text) {
if (typeof marked === 'undefined') {
preview.innerHTML = '<p style="color: red;">错误: Markdown 解析库未加载</p>';
preview.textContent = '错误: Markdown 解析库未加载';
preview.style.color = 'red';
return;
}
try {
preview.innerHTML = marked.parse(text);
} catch (e) {
preview.innerHTML = '<p style="color: red;">渲染错误: ' + e.message + '</p>';
preview.textContent = '渲染错误: ' + e.message;
preview.style.color = 'red';
}
}
@@ -468,7 +470,7 @@
a.href = URL.createObjectURL(blob);
a.download = tab.filePath || 'untitled.md';
a.click();
URL.revokeObjectURL(a.href);
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
tab.isModified = false;
renderTabBar();
updateTitle();
@@ -739,7 +741,6 @@
if (typeof window.electronAPI !== 'undefined') {
// Remove old listeners first to prevent stacking
window.electronAPI.removeAllListeners('file:openInTab');
window.electronAPI.removeAllListeners('file:opened');
window.electronAPI.removeAllListeners('menu:save');
window.electronAPI.removeAllListeners('menu:saveAs');
window.electronAPI.removeAllListeners('menu:viewMode');
@@ -749,11 +750,6 @@
createNewTab(data.filePath, data.content);
});
// Legacy: file opened via old dialog
window.electronAPI.onFileOpened((data) => {
createNewTab(data.filePath, data.content);
});
window.electronAPI.onMenuSave(() => handleSave());
window.electronAPI.onMenuSaveAs(() => handleSaveAs());
window.electronAPI.onViewModeChange((mode) => setViewMode(mode));