From 76ecbc652d60f1e820b9b5a24faf4fc35833241e Mon Sep 17 00:00:00 2001 From: xRangerDE Date: Fri, 20 Mar 2026 09:26:19 +0100 Subject: [PATCH] perf: parallel init with Promise.all, targeted DOM updates for download progress Co-Authored-By: Claude Opus 4.6 (1M context) --- src/renderer-queue.ts | 19 +++++++++++++++++++ src/renderer.ts | 14 +++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/renderer-queue.ts b/src/renderer-queue.ts index 01e9b76..6567960 100644 --- a/src/renderer-queue.ts +++ b/src/renderer-queue.ts @@ -179,6 +179,25 @@ async function createMergeGroupFromSelection(): Promise { updateMergeGroupButton(); } +function updateQueueItemProgress(progress: DownloadProgress): void { + const items = byId('queueList').children; + const idx = queue.findIndex(i => i.id === progress.id); + if (idx < 0 || idx >= items.length) return; + + const el = items[idx]; + const bar = el.querySelector('.queue-progress-bar') as HTMLElement; + const text = el.querySelector('.queue-progress-text') as HTMLElement; + const meta = el.querySelector('.queue-meta') as HTMLElement; + + if (bar) { + const pct = progress.progress > 0 ? Math.min(100, progress.progress) : 0; + bar.style.width = `${pct}%`; + bar.className = `queue-progress-bar${progress.progress <= 0 ? ' indeterminate' : ''}`; + } + if (text) text.textContent = getQueueProgressText(queue[idx]); + if (meta) meta.textContent = getQueueMetaText(queue[idx]); +} + function renderQueue(): void { if (!Array.isArray(queue)) { queue = []; diff --git a/src/renderer.ts b/src/renderer.ts index 0721c2a..7755e7a 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -5,14 +5,18 @@ const QUEUE_SYNC_HIDDEN_MS = 9000; const QUEUE_SYNC_RECENT_ACTIVITY_WINDOW_MS = 15000; async function init(): Promise { - config = await window.api.getConfig(); + const [loadedConfig, initialQueue, isDown, version] = await Promise.all([ + window.api.getConfig(), + window.api.getQueue(), + window.api.isDownloading(), + window.api.getVersion() + ]); + config = loadedConfig; const language = setLanguage((config.language as string) || 'en'); config.language = language; - const initialQueue = await window.api.getQueue(); queue = Array.isArray(initialQueue) ? initialQueue : []; - downloading = await window.api.isDownloading(); + downloading = isDown; markQueueActivity(); - const version = await window.api.getVersion(); byId('versionText').textContent = `v${version}`; byId('versionInfo').textContent = `Version: v${version}`; @@ -66,7 +70,7 @@ async function init(): Promise { item.downloadedBytes = progress.downloadedBytes; item.totalBytes = progress.totalBytes; item.progressStatus = progress.status; - renderQueue(); + updateQueueItemProgress(progress); markQueueActivity(); });