(opts = {})
| 825 | } |
| 826 | |
| 827 | export function startTransferProgress(opts = {}) { |
| 828 | ensureUi(); |
| 829 | |
| 830 | const job = { |
| 831 | id: ++_seq, |
| 832 | action: String(opts.action || 'Transferring'), |
| 833 | itemCount: Number.isFinite(opts.itemCount) ? opts.itemCount : 0, |
| 834 | itemLabel: opts.itemLabel ? String(opts.itemLabel) : 'items', |
| 835 | totalBytes: Number.isFinite(opts.totalBytes) ? opts.totalBytes : 0, |
| 836 | source: opts.source ? String(opts.source) : '', |
| 837 | destination: opts.destination ? String(opts.destination) : '', |
| 838 | title: opts.title ? String(opts.title) : '', |
| 839 | subText: opts.subText ? String(opts.subText) : '', |
| 840 | startedAt: Date.now(), |
| 841 | endedAt: 0, |
| 842 | showAt: Date.now() + TRANSFER_UI_DELAY_MS, |
| 843 | shown: false, |
| 844 | estimateBps: readStoredSpeed(), |
| 845 | indeterminate: false, |
| 846 | state: String(opts.state || 'running').toLowerCase(), |
| 847 | error: '', |
| 848 | removeAt: 0, |
| 849 | dismissed: false, |
| 850 | mode: 'estimate', |
| 851 | pct: null, |
| 852 | bytesDone: null, |
| 853 | bytesTotal: null, |
| 854 | filesDone: null, |
| 855 | filesTotal: null, |
| 856 | current: '', |
| 857 | lastProgressAt: Date.now(), |
| 858 | renderedPct: null, |
| 859 | cancelable: !!opts.cancelable && typeof opts.onCancel === 'function', |
| 860 | onCancel: (typeof opts.onCancel === 'function') ? opts.onCancel : null, |
| 861 | cancelInFlight: false, |
| 862 | cancelRequested: false |
| 863 | }; |
| 864 | |
| 865 | const bytesKnown = opts.bytesKnown !== false; |
| 866 | job.indeterminate = !!opts.indeterminate || !bytesKnown || job.totalBytes <= 0; |
| 867 | |
| 868 | _jobs.set(job.id, job); |
| 869 | ensureTicking(); |
| 870 | renderAll(); |
| 871 | return job; |
| 872 | } |
| 873 | |
| 874 | export function updateTransferProgress(jobRef, updates = {}) { |
| 875 | const job = resolveJob(jobRef); |
no test coverage detected