Show new files immediately when seeding

Fixes #208
This commit is contained in:
DC
2016-03-31 08:07:55 -07:00
parent f500cbf4dd
commit f0cae2509c
2 changed files with 28 additions and 12 deletions

View File

@@ -419,7 +419,17 @@ function resumeTorrents () {
// Write state.saved to the JSON state file
function saveState () {
console.log('saving state to ' + cfg.filePath)
cfg.write(state.saved, function (err) {
// Clean up, so that we're not saving any pending state
var copy = JSON.parse(JSON.stringify(state.saved))
// Remove torrents pending addition to the list, where we haven't finished
// reading the torrent file or file(s) to seed & don't have an infohash
copy.torrents = copy.torrents.filter((x) => x.infoHash)
copy.torrents.forEach(function (x) {
if (x.playStatus !== 'unplayable') delete x.playStatus
})
cfg.write(copy, function (err) {
if (err) console.error(err)
update()
})
@@ -462,12 +472,14 @@ function isNotTorrent (file) {
// Gets a torrent summary {name, infoHash, status} from state.saved.torrents
// Returns undefined if we don't know that infoHash
function getTorrentSummary (infoHash) {
if (!infoHash) return undefined
return state.saved.torrents.find((x) => x.infoHash === infoHash)
}
// Get an active torrent from state.client.torrents
// Returns undefined if we are not currently torrenting that infoHash
function getTorrent (infoHash) {
if (!infoHash) return undefined
var pending = state.pendingTorrents[infoHash]
if (pending) return pending
return lazyLoadClient().torrents.find((x) => x.infoHash === infoHash)
@@ -487,20 +499,23 @@ function addTorrentToList (torrent) {
return // Skip, torrent is already in state.saved
}
var torrentSummary = {
status: 'new',
name: torrent.name
}
state.saved.torrents.push(torrentSummary)
playInterfaceSound('ADD')
// If torrentId is a remote torrent (filesystem path, http url, etc.), wait for
// WebTorrent to finish reading it
if (torrent.infoHash) onInfoHash()
else torrent.on('infoHash', onInfoHash)
function onInfoHash () {
state.saved.torrents.push({
status: 'new',
name: torrent.name,
infoHash: torrent.infoHash,
magnetURI: torrent.magnetURI
})
torrentSummary.infoHash = torrent.infoHash
torrentSummary.magnetURI = torrent.magnetURI
saveState()
playInterfaceSound('ADD')
update()
}
}

View File

@@ -30,7 +30,7 @@ function TorrentList (state) {
var torrent = state.client
? state.client.torrents.find((x) => x.infoHash === infoHash)
: null
var isSelected = state.selectedInfoHash === infoHash
var isSelected = infoHash && state.selectedInfoHash === infoHash
// Background image: show some nice visuals, like a frame from the movie, if possible
var style = {}
@@ -51,13 +51,14 @@ function TorrentList (state) {
// playStatus turns the play button into a loading spinner or error icon
if (torrentSummary.playStatus) classes.push(torrentSummary.playStatus)
if (isSelected) classes.push('selected')
if (!infoHash) classes.push('disabled')
classes = classes.join(' ')
return hx`
<div style=${style} class=${classes}
oncontextmenu=${dispatcher('openTorrentContextMenu', infoHash)}
onclick=${dispatcher('toggleSelectTorrent', infoHash)}>
oncontextmenu=${infoHash && dispatcher('openTorrentContextMenu', infoHash)}
onclick=${infoHash && dispatcher('toggleSelectTorrent', infoHash)}>
${renderTorrentMetadata(torrent, torrentSummary)}
${renderTorrentButtons(torrentSummary)}
${infoHash ? renderTorrentButtons(torrentSummary) : ''}
${isSelected ? renderTorrentDetails(torrent, torrentSummary) : ''}
</div>
`