diff --git a/renderer/index.js b/renderer/index.js index 96c88255..146ec01c 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -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() } } diff --git a/renderer/views/torrent-list.js b/renderer/views/torrent-list.js index 6a6b13d4..d92db495 100644 --- a/renderer/views/torrent-list.js +++ b/renderer/views/torrent-list.js @@ -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`
+ oncontextmenu=${infoHash && dispatcher('openTorrentContextMenu', infoHash)} + onclick=${infoHash && dispatcher('toggleSelectTorrent', infoHash)}> ${renderTorrentMetadata(torrent, torrentSummary)} - ${renderTorrentButtons(torrentSummary)} + ${infoHash ? renderTorrentButtons(torrentSummary) : ''} ${isSelected ? renderTorrentDetails(torrent, torrentSummary) : ''}
`