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:
parent
b7499c87a3
commit
76ecbc652d
@ -179,6 +179,25 @@ async function createMergeGroupFromSelection(): Promise<void> {
|
|||||||
updateMergeGroupButton();
|
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 {
|
function renderQueue(): void {
|
||||||
if (!Array.isArray(queue)) {
|
if (!Array.isArray(queue)) {
|
||||||
queue = [];
|
queue = [];
|
||||||
|
|||||||
@ -5,14 +5,18 @@ const QUEUE_SYNC_HIDDEN_MS = 9000;
|
|||||||
const QUEUE_SYNC_RECENT_ACTIVITY_WINDOW_MS = 15000;
|
const QUEUE_SYNC_RECENT_ACTIVITY_WINDOW_MS = 15000;
|
||||||
|
|
||||||
async function init(): Promise<void> {
|
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');
|
const language = setLanguage((config.language as string) || 'en');
|
||||||
config.language = language;
|
config.language = language;
|
||||||
const initialQueue = await window.api.getQueue();
|
|
||||||
queue = Array.isArray(initialQueue) ? initialQueue : [];
|
queue = Array.isArray(initialQueue) ? initialQueue : [];
|
||||||
downloading = await window.api.isDownloading();
|
downloading = isDown;
|
||||||
markQueueActivity();
|
markQueueActivity();
|
||||||
const version = await window.api.getVersion();
|
|
||||||
|
|
||||||
byId('versionText').textContent = `v${version}`;
|
byId('versionText').textContent = `v${version}`;
|
||||||
byId('versionInfo').textContent = `Version: v${version}`;
|
byId('versionInfo').textContent = `Version: v${version}`;
|
||||||
@ -66,7 +70,7 @@ async function init(): Promise<void> {
|
|||||||
item.downloadedBytes = progress.downloadedBytes;
|
item.downloadedBytes = progress.downloadedBytes;
|
||||||
item.totalBytes = progress.totalBytes;
|
item.totalBytes = progress.totalBytes;
|
||||||
item.progressStatus = progress.status;
|
item.progressStatus = progress.status;
|
||||||
renderQueue();
|
updateQueueItemProgress(progress);
|
||||||
markQueueActivity();
|
markQueueActivity();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user