perf: parallel init with Promise.all, targeted DOM updates for download progress

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
xRangerDE 2026-03-20 09:26:19 +01:00
parent b7499c87a3
commit 76ecbc652d
2 changed files with 28 additions and 5 deletions

View File

@ -179,6 +179,25 @@ async function createMergeGroupFromSelection(): Promise<void> {
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 = [];

View File

@ -5,14 +5,18 @@ const QUEUE_SYNC_HIDDEN_MS = 9000;
const QUEUE_SYNC_RECENT_ACTIVITY_WINDOW_MS = 15000;
async function init(): Promise<void> {
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<void> {
item.downloadedBytes = progress.downloadedBytes;
item.totalBytes = progress.totalBytes;
item.progressStatus = progress.status;
renderQueue();
updateQueueItemProgress(progress);
markQueueActivity();
});