diff --git a/renderer/app.js b/renderer/app.js index 59c77dc..8309a31 100644 --- a/renderer/app.js +++ b/renderer/app.js @@ -119,10 +119,24 @@ async function init() { } } if (newFiles.length > 0) { + const newPaths = new Set(newFiles.map(f => f.path)); selectedFiles.push(...newFiles); buildQueuePreview(); updateUploadView(); - if (fm.autoStart && !uploading && !healthCheckRunning) startUpload(); + if (fm.autoStart && !uploading && !healthCheckRunning) { + startUpload(); + } else if (uploading) { + // Inject new preview jobs into the running batch + const newJobs = queueJobs.filter(j => j.status === 'preview' && newPaths.has(j.file)); + if (newJobs.length > 0) { + newJobs.forEach(j => { j.status = 'queued'; }); + renderQueueTable(); + window.api.addJobsToBatch({ + jobs: newJobs.map(j => ({ id: j.id, file: j.file, fileName: j.fileName, hoster: j.hoster })) + }).then(result => { _markSkippedJobs(result); }).catch(() => {}); + persistQueueStateSoon(true); + } + } } } else { // No pre-selected hosters: open modal @@ -360,11 +374,29 @@ function applyHosterSelection() { selectedUploadHosters = Array.from(document.querySelectorAll('input[data-hoster-modal]:checked')) .map(input => input.dataset.hosterModal); // Move pending files to selectedFiles on confirm + const pendingPaths = new Set(_pendingFiles.map(f => f.path)); if (_pendingFiles.length > 0) { selectedFiles.push(..._pendingFiles); _pendingFiles = []; } renderHosterSummary(); + + // During an active upload, build preview jobs for the new files and inject + // them into the running batch immediately (otherwise they'd be lost on + // handleBatchDone via syncSelectedFilesFromQueue) + if (uploading && pendingPaths.size > 0) { + buildQueuePreview(); // creates 'preview' jobs for new files + const newJobs = queueJobs.filter(j => j.status === 'preview' && pendingPaths.has(j.file)); + if (newJobs.length > 0) { + newJobs.forEach(j => { j.status = 'queued'; }); + renderQueueTable(); + window.api.addJobsToBatch({ + jobs: newJobs.map(j => ({ id: j.id, file: j.file, fileName: j.fileName, hoster: j.hoster })) + }).then(result => { _markSkippedJobs(result); }).catch(() => {}); + persistQueueStateSoon(true); + } + } + updateUploadView(); persistQueueStateSoon(true); // immediate persist after adding files document.getElementById('hosterModal').style.display = 'none';