(callerWindow)
| 40 | const downloadQueue = {}; |
| 41 | |
| 42 | function updateProgress(callerWindow) { |
| 43 | let count = Object.keys(downloadQueue).length; |
| 44 | if (count === 0) { |
| 45 | clearBadge(); |
| 46 | clearProgress.call(callerWindow); |
| 47 | return; |
| 48 | } |
| 49 | setBadge(Object.keys(downloadQueue).length); |
| 50 | let progress; |
| 51 | if(Object.values(downloadQueue).some((item) => item.total === null)) { |
| 52 | // If any of the items in the queue does not have a total, we cannot calculate progress |
| 53 | // so we return 2 to indicate that the progress is indeterminate. |
| 54 | progress = 2; |
| 55 | } else { |
| 56 | const total = Object.values(downloadQueue).reduce((acc, item) => { |
| 57 | if (item.total) { |
| 58 | return acc + item.currentLoaded / item.total; |
| 59 | } |
| 60 | return acc + item.currentLoaded; |
| 61 | }, 0); |
| 62 | progress = total / Object.keys(downloadQueue).length; |
| 63 | } |
| 64 | setProgress.call(callerWindow, progress); |
| 65 | } |
| 66 | |
| 67 | async function fileDownloadPath(callerWindow, options, prompt=true) { |
| 68 | let filePath = path.join(app.getPath('downloads'), options.defaultPath); |
no test coverage detected