Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

add global progress indicator. closes #296 #297

Merged
merged 1 commit into from Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions elements/status.js
Expand Up @@ -83,6 +83,7 @@ module.exports = function (dat, stats, send) {
if (dat.owner && dat.importer) {
return html`<div>Watching for updates…</div>`
}
var progress = Math.floor(dat.progress * 100)
var progressbarLine = (stats.state === 'loading')
? 'line-loading'
: (stats.state === 'paused' || stats.state === 'stale')
Expand Down Expand Up @@ -115,10 +116,10 @@ module.exports = function (dat, stats, send) {
<div>
<div class="${progressbar}">
<div class="counter">
${stats.progress}%
${progress}%
</div>
<div class="bar">
<div class="line ${progressbarLine}" style="width: ${stats.progress}%">
<div class="line ${progressbarLine}" style="width: ${progress}%">
</div>
</div>
</div>
Expand Down
13 changes: 1 addition & 12 deletions elements/table.js
Expand Up @@ -144,20 +144,9 @@ function row (dat, send) {
var key = encoding.encode(dat.key)
var title = dat.metadata.title || '#' + key

stats.progress = (!stats)
? 0
: (stats.blocksTotal)
? Math.round((stats.blocksProgress / stats.blocksTotal) * 100)
: 0

// place an upper bound of 100% on progress. We've encountered situations
// where blocks downloaded exceeds total block. Once that's fixed this
// should be safe to be removed
stats.progress = Math.min(stats.progress, 100)
stats.size = (dat.archive.content) ? bytes(dat.archive.content.bytes) : 'N/A'

stats.state = (dat.network)
? (dat.owner || stats.progress === 100)
? (dat.owner || dat.progress === 1)
? 'complete'
: (peers)
? 'loading'
Expand Down
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -53,6 +53,7 @@ function onReady () {
const log = str => mainWindow.webContents.send('log', str)

ipcMain.on('quit', () => app.quit()) // TODO: ping backend with error
ipcMain.on('progress', (ev, progress) => mainWindow.setProgressBar(progress))
emitter.on('open-file', (file) => mainWindow.webContents.send('file', file))
emitter.on('open-url', (url) => mainWindow.webContents.send('link', url))

Expand Down
18 changes: 18 additions & 0 deletions models/repos.js
Expand Up @@ -273,6 +273,24 @@ function createModel () {

function update () {
var dats = multidat.list().slice()
dats.forEach(function (dat) {
var stats = dat.stats && dat.stats.get()
dat.progress = (!stats)
? 0
: (stats.blocksTotal)
? Math.min(1, stats.blocksProgress / stats.blocksTotal)
: 0
})

var incomplete = dats.filter(function (dat) {
return dat.progress < 1
})
var progress = incomplete.reduce(function (acc, dat) {
return acc + dat.progress
}, 0) / incomplete.length
if (progress === 1) progress = -1 // deactivate

ipc.send('progress', progress)
onupdate(null, dats)
}

Expand Down