feat:功能优化

- fix:修复日志过多导致内存占用大和渲染性能问题
- 优化性能,动态处理。更好的利用多核CPU
- 完全本地化,不依赖任何网络加载css
This commit is contained in:
ASLant committed 2025-11-14 10:12:41 +08:00
1 parent f674a10bc0
commit 38939c9b80
3 files changed
+290 -8

No files matched your search

+245
View File
@@ -0,0 +1,245 @@
/* UPX GUI - 精简版 Tailwind CSS */
/* 仅包含项目中实际使用的类,优化加载性能 */
/* Reset & Base */
*, ::before, ::after {
box-sizing: border-box;
border-width: 0;
border-style: solid;
border-color: #e5e7eb;
}
/* Layout */
.h-screen { height: 100vh; }
.h-10 { height: 2.5rem; }
.h-9 { height: 2.25rem; }
.h-4 { height: 1rem; }
.h-2 { height: 0.5rem; }
.h-full { height: 100%; }
.h-\[calc\(100vh-2\.5rem\)\] { height: calc(100vh - 2.5rem); }
.w-full { width: 100%; }
.w-16 { width: 4rem; }
.w-9 { width: 2.25rem; }
.w-4 { width: 1rem; }
.w-2 { width: 0.5rem; }
.min-h-0 { min-height: 0; }
.min-w-0 { min-width: 0; }
.max-w-\[700px\] { max-width: 700px; }
/* Flexbox */
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.flex-shrink-0 { flex-shrink: 0; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
/* Grid */
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.col-span-2 { grid-column: span 2 / span 2; }
/* Spacing */
.gap-3 { gap: 0.75rem; }
.gap-6 { gap: 1.5rem; }
.space-x-1 > :not([hidden]) ~ :not([hidden]) { margin-left: 0.25rem; }
.space-x-2\.5 > :not([hidden]) ~ :not([hidden]) { margin-left: 0.625rem; }
.space-x-3 > :not([hidden]) ~ :not([hidden]) { margin-left: 0.75rem; }
.space-y-5 > :not([hidden]) ~ :not([hidden]) { margin-top: 1.25rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.px-1 { padding-left: 0.25rem; padding-right: 0.25rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-2\.5 { padding-top: 0.625rem; padding-bottom: 0.625rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.m-0 { margin: 0; }
.mx-4 { margin-left: 1rem; margin-right: 1rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.mt-0\.5 { margin-top: 0.125rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mt-6 { margin-top: 1.5rem; }
.pt-5 { padding-top: 1.25rem; }
/* Position */
.relative { position: relative; }
.fixed { position: fixed; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.z-50 { z-index: 50; }
/* Display */
.hidden { display: none; }
.block { display: block; }
/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.overflow-x-hidden { overflow-x: hidden; }
/* Colors - Background */
.bg-transparent { background-color: transparent; }
.bg-white { background-color: rgb(255 255 255); }
.bg-gray-50 { background-color: rgb(249 250 251); }
.bg-gray-100 { background-color: rgb(243 244 246); }
.bg-gray-200 { background-color: rgb(229 231 235); }
.bg-gray-900 { background-color: rgb(17 24 39); }
.bg-blue-50 { background-color: rgb(239 246 255); }
.bg-blue-500 { background-color: rgb(59 130 246); }
.bg-red-50 { background-color: rgb(254 242 242); }
.bg-black { background-color: rgb(0 0 0); }
.bg-opacity-50 { --tw-bg-opacity: 0.5; }
.bg-opacity-50 { background-color: rgb(0 0 0 / var(--tw-bg-opacity)); }
/* Colors - Text */
.text-gray-400 { color: rgb(156 163 175); }
.text-gray-500 { color: rgb(107 114 128); }
.text-gray-600 { color: rgb(75 85 99); }
.text-gray-700 { color: rgb(55 65 81); }
.text-gray-800 { color: rgb(31 41 55); }
.text-blue-600 { color: rgb(37 99 235); }
.text-blue-700 { color: rgb(29 78 216); }
.text-green-400 { color: rgb(74 222 128); }
.text-green-600 { color: rgb(22 163 74); }
.text-green-700 { color: rgb(21 128 61); }
.text-white { color: rgb(255 255 255); }
/* Colors - Border */
.border { border-width: 1px; }
.border-2 { border-width: 2px; }
.border-b { border-bottom-width: 1px; }
.border-t { border-top-width: 1px; }
.border-gray-200 { border-color: rgb(229 231 235); }
.border-gray-300 { border-color: rgb(209 213 219); }
.border-blue-300 { border-color: rgb(147 197 253); }
.border-blue-500 { border-color: rgb(59 130 246); }
.border-green-500 { border-color: rgb(34 197 94); }
/* Border Radius */
.rounded { border-radius: 0.25rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-full { border-radius: 9999px; }
/* Shadow */
.shadow-md { box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); }
.shadow-lg { box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); }
.shadow-xl { box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); }
.shadow-2xl { box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25); }
/* Typography */
.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; line-height: 1.5rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
/* Appearance */
.appearance-none { appearance: none; }
/* Cursor */
.cursor-pointer { cursor: pointer; }
/* Select */
.select-none { user-select: none; }
/* Transform */
.transform { transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)); }
.hover\:-translate-y-1:hover { --tw-translate-y: -0.25rem; transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)); }
/* Transition */
.transition-all { transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; }
.transition-colors { transition-property: color, background-color, border-color, text-decoration-color, fill, stroke; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; }
.duration-200 { transition-duration: 200ms; }
/* Gradient */
.bg-gradient-to-br { background-image: linear-gradient(to bottom right, var(--tw-gradient-stops)); }
.from-blue-50 { --tw-gradient-from: #eff6ff; --tw-gradient-to: rgb(239 246 255 / 0); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }
.from-blue-100 { --tw-gradient-from: #dbeafe; --tw-gradient-to: rgb(219 234 254 / 0); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }
.from-green-50 { --tw-gradient-from: #f0fdf4; --tw-gradient-to: rgb(240 253 244 / 0); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }
.from-green-100 { --tw-gradient-from: #dcfce7; --tw-gradient-to: rgb(220 252 231 / 0); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }
.to-blue-100 { --tw-gradient-to: #dbeafe; }
.to-blue-200 { --tw-gradient-to: #bfdbfe; }
.to-green-100 { --tw-gradient-to: #dcfce7; }
.to-green-200 { --tw-gradient-to: #bbf7d0; }
/* Hover States - Background */
.hover\:bg-gray-100:hover {
background-color: rgb(243 244 246) !important;
}
.hover\:bg-red-50:hover {
background-color: rgb(254 242 242) !important;
}
.hover\:bg-blue-50:hover {
background-color: rgb(239 246 255) !important;
}
.hover\:bg-blue-600:hover {
background-color: rgb(37 99 235) !important;
}
/* Hover States - Border */
.hover\:border-blue-300:hover {
border-color: rgb(147 197 253) !important;
}
/* Hover States - Text */
.hover\:text-blue-600:hover {
color: rgb(37 99 235) !important;
}
.hover\:text-red-600:hover {
color: rgb(220 38 38) !important;
}
/* Hover States - Shadow */
.hover\:shadow-xl:hover {
box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1) !important;
}
.hover\:shadow-lg:hover {
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1) !important;
}
/* Hover States - Gradient */
.hover\:from-blue-100:hover {
--tw-gradient-from: #dbeafe !important;
--tw-gradient-to: rgb(219 234 254 / 0) !important;
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.hover\:from-green-100:hover {
--tw-gradient-from: #dcfce7 !important;
--tw-gradient-to: rgb(220 252 231 / 0) !important;
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.hover\:to-blue-200:hover {
--tw-gradient-to: #bfdbfe !important;
}
.hover\:to-green-200:hover {
--tw-gradient-to: #bbf7d0 !important;
}
/* Active States */
.active\:bg-blue-700:active { background-color: rgb(29 78 216); }
/* Focus States */
.focus\:ring-2:focus { --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color); box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); }
.focus\:ring-blue-500:focus { --tw-ring-color: rgb(59 130 246); }
/* Group Hover */
.group:hover .group-hover\:text-red-600 { color: rgb(220 38 38); }
/* Drop Zone */
.drop-zone { transition: all 0.3s ease; position: relative; }
+7 -6
View File
@@ -4,7 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UPX GUI</title>
<script src="https://cdn.tailwindcss.com"></script>
<!-- 本地化 Tailwind CSS - 仅包含使用的类,优化性能 -->
<link rel="stylesheet" href="css/tailwind-custom.css">
<link rel="stylesheet" href="css/style.css">
<!-- 预加载关键资源 -->
<link rel="preload" href="js/main.js" as="script">
@@ -18,28 +19,28 @@
<span id="upx-version" class="text-gray-400 text-xs select-none"></span>
</div>
<div class="flex items-center space-x-1">
<button id="refresh-icon-btn" class="w-9 h-9 hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;" title="刷新图标缓存">
<button id="refresh-icon-btn" class="w-9 h-9 bg-transparent hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;" title="刷新图标缓存">
<svg class="w-4 h-4 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
</svg>
</button>
<button id="settings-btn" class="w-9 h-9 hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;" title="设置">
<button id="settings-btn" class="w-9 h-9 bg-transparent hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;" title="设置">
<svg class="w-4 h-4 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
</button>
<button id="titlebar-minimize" class="w-9 h-9 hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;">
<button id="titlebar-minimize" class="w-9 h-9 bg-transparent hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;">
<svg class="w-4 h-4 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 12H4"></path>
</svg>
</button>
<button id="titlebar-maximize" class="w-9 h-9 hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;">
<button id="titlebar-maximize" class="w-9 h-9 bg-transparent hover:bg-gray-100 flex items-center justify-center transition-all duration-200" style="border-radius: 0.3rem;">
<svg class="w-4 h-4 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"></path>
</svg>
</button>
<button id="titlebar-close" class="w-9 h-9 hover:bg-red-50 flex items-center justify-center transition-all duration-200 group" style="border-radius: 0.3rem;">
<button id="titlebar-close" class="w-9 h-9 bg-transparent hover:bg-red-50 flex items-center justify-center transition-all duration-200 group" style="border-radius: 0.3rem;">
<svg class="w-4 h-4 text-gray-600 group-hover:text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
+38 -2
View File
@@ -6,6 +6,21 @@ const { listen } = window.__TAURI__.event;
// 获取当前窗口实例
const appWindow = getCurrentWindow();
// 性能配置:动态批处理大小
const PERFORMANCE_CONFIG = {
cpuCores: navigator.hardwareConcurrency || 4, // CPU逻辑核心数
batchSize: null // 将在初始化时计算
};
// 计算最优批处理大小
function calculateOptimalBatchSize() {
// 根据CPU核心数计算:每个核心处理1-2个任务
// 最小为2,最大为16(避免过度并发)
const optimal = Math.max(2, Math.min(PERFORMANCE_CONFIG.cpuCores * 2, 16));
PERFORMANCE_CONFIG.batchSize = optimal;
return optimal;
}
// DOM 元素
const compressBtn = document.getElementById('compress-btn');
const decompressBtn = document.getElementById('decompress-btn');
@@ -31,6 +46,9 @@ const closeBtn = document.getElementById('titlebar-close');
// 初始化
document.addEventListener('DOMContentLoaded', async () => {
// 初始化性能配置
calculateOptimalBatchSize();
initWindowControls();
initOperationButtons();
initCompressionLevelSlider();
@@ -270,12 +288,13 @@ async function processBatchFiles(files, mode) {
}
addLog(`批量处理模式 - 找到 ${files.length} 个文件`, 'info');
addLog(`使用 ${PERFORMANCE_CONFIG.batchSize} 并发处理(CPU核心: ${PERFORMANCE_CONFIG.cpuCores})`, 'info');
let successCount = 0;
let failCount = 0;
// 并行处理,每次最多5个文件
const batchSize = 5;
// 动态并行处理,根据CPU核心数自动调整
const batchSize = PERFORMANCE_CONFIG.batchSize;
for (let i = 0; i < files.length; i += batchSize) {
const batch = files.slice(i, Math.min(i + batchSize, files.length));
const batchStart = i + 1;
@@ -632,6 +651,12 @@ async function handleRefreshIcon() {
// 日志初始化标志
let logInitialized = false;
// 日志管理配置
const LOG_CONFIG = {
MAX_LOGS: 1000, // 最大日志条数
TRIM_COUNT: 200 // 超出时一次删除的条数
};
// 添加日志
function addLog(message, type = 'info', highlight = false) {
const logLine = document.createElement('div');
@@ -654,6 +679,17 @@ function addLog(message, type = 'info', highlight = false) {
logOutput.appendChild(logLine);
// 日志数量管理:超过最大值时删除旧日志
const logCount = logOutput.children.length;
if (logCount > LOG_CONFIG.MAX_LOGS) {
// 批量删除旧日志以提升性能
for (let i = 0; i < LOG_CONFIG.TRIM_COUNT; i++) {
if (logOutput.firstChild) {
logOutput.removeChild(logOutput.firstChild);
}
}
}
// 使用 requestAnimationFrame 优化滚动性能
requestAnimationFrame(() => {
logOutput.scrollTop = logOutput.scrollHeight;