From cd575d20055becc3c089b3d3d6d5b83b12587048 Mon Sep 17 00:00:00 2001 From: Andrea Tupini Date: Thu, 21 Jul 2016 14:18:56 -0600 Subject: [PATCH] Display torrent ETA in list item (#726) * Display torrent ETA in list ETA being the estimated time to download completion calculated using the current download speed and missing bytes. * Refactor ETA string construction * Removed extra 's' in ETA string construction --- renderer/views/torrent-list.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/renderer/views/torrent-list.js b/renderer/views/torrent-list.js index 6b6d68ac..c3bcd5fc 100644 --- a/renderer/views/torrent-list.js +++ b/renderer/views/torrent-list.js @@ -70,6 +70,7 @@ function TorrentList (state) { ${renderPeers()} ${renderDownloadSpeed()} ${renderUploadSpeed()} + ${renderEta()} `) } @@ -106,6 +107,27 @@ function TorrentList (state) { if (prog.uploadSpeed === 0) return return hx`↑ ${prettyBytes(prog.uploadSpeed)}/s` } + + function renderEta () { + var downloaded = prog.downloaded + var total = prog.length || 0 + var missing = total - downloaded + var downloadSpeed = prog.downloadSpeed + if (downloadSpeed === 0 || missing === 0) return + + var rawEta = missing / downloadSpeed + var hours = Math.floor(rawEta / 3600) % 24 + var minutes = Math.floor(rawEta / 60) % 60 + var seconds = Math.floor(rawEta % 60) + + // Only display hours and minutes if they are greater than 0 but always + // display minutes if hours is being displayed + var hoursStr = hours ? hours + 'h' : '' + var minutesStr = (hours || minutes) ? minutes + 'm' : '' + var secondsStr = seconds + 's' + + return hx`ETA: ${hoursStr} ${minutesStr} ${secondsStr}` + } } // Download button toggles between torrenting (DL/seed) and paused