@@ -419,7 +419,17 @@ function resumeTorrents () {
|
|||||||
// Write state.saved to the JSON state file
|
// Write state.saved to the JSON state file
|
||||||
function saveState () {
|
function saveState () {
|
||||||
console.log('saving state to ' + cfg.filePath)
|
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)
|
if (err) console.error(err)
|
||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
@@ -462,12 +472,14 @@ function isNotTorrent (file) {
|
|||||||
// Gets a torrent summary {name, infoHash, status} from state.saved.torrents
|
// Gets a torrent summary {name, infoHash, status} from state.saved.torrents
|
||||||
// Returns undefined if we don't know that infoHash
|
// Returns undefined if we don't know that infoHash
|
||||||
function getTorrentSummary (infoHash) {
|
function getTorrentSummary (infoHash) {
|
||||||
|
if (!infoHash) return undefined
|
||||||
return state.saved.torrents.find((x) => x.infoHash === infoHash)
|
return state.saved.torrents.find((x) => x.infoHash === infoHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get an active torrent from state.client.torrents
|
// Get an active torrent from state.client.torrents
|
||||||
// Returns undefined if we are not currently torrenting that infoHash
|
// Returns undefined if we are not currently torrenting that infoHash
|
||||||
function getTorrent (infoHash) {
|
function getTorrent (infoHash) {
|
||||||
|
if (!infoHash) return undefined
|
||||||
var pending = state.pendingTorrents[infoHash]
|
var pending = state.pendingTorrents[infoHash]
|
||||||
if (pending) return pending
|
if (pending) return pending
|
||||||
return lazyLoadClient().torrents.find((x) => x.infoHash === infoHash)
|
return lazyLoadClient().torrents.find((x) => x.infoHash === infoHash)
|
||||||
@@ -487,20 +499,23 @@ function addTorrentToList (torrent) {
|
|||||||
return // Skip, torrent is already in state.saved
|
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
|
// If torrentId is a remote torrent (filesystem path, http url, etc.), wait for
|
||||||
// WebTorrent to finish reading it
|
// WebTorrent to finish reading it
|
||||||
if (torrent.infoHash) onInfoHash()
|
if (torrent.infoHash) onInfoHash()
|
||||||
else torrent.on('infoHash', onInfoHash)
|
else torrent.on('infoHash', onInfoHash)
|
||||||
|
|
||||||
function onInfoHash () {
|
function onInfoHash () {
|
||||||
state.saved.torrents.push({
|
torrentSummary.infoHash = torrent.infoHash
|
||||||
status: 'new',
|
torrentSummary.magnetURI = torrent.magnetURI
|
||||||
name: torrent.name,
|
|
||||||
infoHash: torrent.infoHash,
|
|
||||||
magnetURI: torrent.magnetURI
|
|
||||||
})
|
|
||||||
saveState()
|
saveState()
|
||||||
playInterfaceSound('ADD')
|
update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ function TorrentList (state) {
|
|||||||
var torrent = state.client
|
var torrent = state.client
|
||||||
? state.client.torrents.find((x) => x.infoHash === infoHash)
|
? state.client.torrents.find((x) => x.infoHash === infoHash)
|
||||||
: null
|
: 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
|
// Background image: show some nice visuals, like a frame from the movie, if possible
|
||||||
var style = {}
|
var style = {}
|
||||||
@@ -51,13 +51,14 @@ function TorrentList (state) {
|
|||||||
// playStatus turns the play button into a loading spinner or error icon
|
// playStatus turns the play button into a loading spinner or error icon
|
||||||
if (torrentSummary.playStatus) classes.push(torrentSummary.playStatus)
|
if (torrentSummary.playStatus) classes.push(torrentSummary.playStatus)
|
||||||
if (isSelected) classes.push('selected')
|
if (isSelected) classes.push('selected')
|
||||||
|
if (!infoHash) classes.push('disabled')
|
||||||
classes = classes.join(' ')
|
classes = classes.join(' ')
|
||||||
return hx`
|
return hx`
|
||||||
<div style=${style} class=${classes}
|
<div style=${style} class=${classes}
|
||||||
oncontextmenu=${dispatcher('openTorrentContextMenu', infoHash)}
|
oncontextmenu=${infoHash && dispatcher('openTorrentContextMenu', infoHash)}
|
||||||
onclick=${dispatcher('toggleSelectTorrent', infoHash)}>
|
onclick=${infoHash && dispatcher('toggleSelectTorrent', infoHash)}>
|
||||||
${renderTorrentMetadata(torrent, torrentSummary)}
|
${renderTorrentMetadata(torrent, torrentSummary)}
|
||||||
${renderTorrentButtons(torrentSummary)}
|
${infoHash ? renderTorrentButtons(torrentSummary) : ''}
|
||||||
${isSelected ? renderTorrentDetails(torrent, torrentSummary) : ''}
|
${isSelected ? renderTorrentDetails(torrent, torrentSummary) : ''}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user