| 3534 | |
| 3535 | const overlay = window.ThumbnailProgress; |
| 3536 | if (!overlay) return; |
| 3537 | if (payload.phase) overlay.setPhase(payload.phase); |
| 3538 | if (typeof payload.total === 'number' && payload.total > 0) { |
| 3539 | overlay.update(payload.processed || 0, payload.total, payload.phase); |
| 3540 | } else if (payload.phase) { |
| 3541 | overlay.setIndeterminate(true); |
| 3542 | overlay.setPhase(payload.phase); |
| 3543 | } |
| 3544 | }; |
| 3545 | if (window._electronPendingEvents['thumbnail-job-progress']) { |
| 3546 | window._electronPendingEvents['thumbnail-job-progress'].forEach((args) => { |
| 3547 | window._electronRealEventHandlers['thumbnail-job-progress'].apply(null, args); |
| 3548 | }); |
| 3549 | delete window._electronPendingEvents['thumbnail-job-progress']; |
| 3550 | } |
| 3551 | |
| 3552 | window._electronRealEventHandlers['thumbnail-job-complete'] = function(result) { |
| 3553 | const waiter = activeServerThumbnailJobWaiter; |
| 3554 | activeServerThumbnailJobWaiter = null; |
| 3555 | window._serverBulkThumbnailJobActive = false; |
| 3556 | const wasBackgrounded = !!(waiter && waiter.backgrounded); |
| 3557 | |
| 3558 | hideBackgroundThumbnailProgress(); |
| 3559 | if (typeof processRenderQueue === 'function' && renderQueue.length > 0) { |
| 3560 | setTimeout(() => processRenderQueue(), 100); |
| 3561 | } |
| 3562 | |
| 3563 | if (wasBackgrounded) { |
| 3564 | const cancelled = !!(result && result.cancelled); |
| 3565 | refreshGridAfterBackgroundThumbnailJob(); |
| 3566 | window.electron.showMessage( |
| 3567 | waiter.title || 'Thumbnails', |
| 3568 | cancelled ? 'Thumbnail generation stopped.' : 'Thumbnail generation finished.' |
| 3569 | ).catch(() => {}); |
| 3570 | return; |
| 3571 | } |
| 3572 | |
| 3573 | if (!waiter || waiter.settled) return; |
| 3574 | waiter.settled = true; |
| 3575 | const overlay = window.ThumbnailProgress; |
| 3576 | overlay?.complete(result && result.cancelled ? 'Stopped.' : 'Finished.'); |
| 3577 | waiter.resolve(result || { success: true }); |
| 3578 | }; |
| 3579 | if (window._electronPendingEvents['thumbnail-job-complete']) { |
| 3580 | window._electronPendingEvents['thumbnail-job-complete'].forEach((args) => { |
| 3581 | window._electronRealEventHandlers['thumbnail-job-complete'].apply(null, args); |
| 3582 | }); |
| 3583 | delete window._electronPendingEvents['thumbnail-job-complete']; |
| 3584 | } |
| 3585 | |
| 3586 | window._electronRealEventHandlers['thumbnail-job-error'] = function(payload) { |
| 3587 | const waiter = activeServerThumbnailJobWaiter; |
| 3588 | activeServerThumbnailJobWaiter = null; |
| 3589 | window._serverBulkThumbnailJobActive = false; |
| 3590 | const wasBackgrounded = !!(waiter && waiter.backgrounded); |
| 3591 | |
| 3592 | hideBackgroundThumbnailProgress(); |
| 3593 | window.ThumbnailProgress?.hide(); |