修复:close超时保护、移除冗余变量、优化文件大小计算、去重formatBytes

This commit is contained in:
thzxx
2026-05-18 13:11:35 +08:00
parent cb29c67f94
commit b613384030
2 changed files with 24 additions and 18 deletions
+8 -12
View File
@@ -140,13 +140,15 @@
}
// ===== File Size =====
function formatBytes(bytes) {
if (bytes < 1024) return bytes + ' B';
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
}
function updateFileSize() {
const bytes = new TextEncoder().encode(editor.value).length;
let display;
if (bytes < 1024) display = bytes + ' B';
else if (bytes < 1024 * 1024) display = (bytes / 1024).toFixed(1) + ' KB';
else display = (bytes / (1024 * 1024)).toFixed(1) + ' MB';
statusSize.textContent = display;
const bytes = new Blob([editor.value]).size;
statusSize.textContent = formatBytes(bytes);
statusSizeDivider.classList.add('visible');
}
@@ -215,12 +217,6 @@
return filePath.split(/[/\\]/).pop();
}
function formatBytes(bytes) {
if (bytes < 1024) return bytes + ' B';
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
}
async function updateFileStats(filePath) {
if (typeof window.electronAPI !== 'undefined' && filePath) {
const stats = await window.electronAPI.getFileStats(filePath);