diff --git a/renderer/controllers/torrent-list-controller.js b/renderer/controllers/torrent-list-controller.js index f35c4cb3..e1e27ff5 100644 --- a/renderer/controllers/torrent-list-controller.js +++ b/renderer/controllers/torrent-list-controller.js @@ -114,19 +114,26 @@ module.exports = class TorrentListController { // TODO: use torrentKey, not infoHash deleteTorrent (infoHash, deleteData) { - var state = this.state - ipcRenderer.send('wt-stop-torrenting', infoHash) - if (deleteData) { - var torrentSummary = TorrentSummary.getByKey(state, infoHash) - moveItemToTrash(torrentSummary) + var index = this.state.saved.torrents.findIndex((x) => x.infoHash === infoHash) + + if (index > -1) { + var summary = this.state.saved.torrents[index] + + // remove torrent and poster file + deleteFile(TorrentSummary.getTorrentPath(summary)) + deleteFile(TorrentSummary.getPosterPath(summary)) // TODO: will the css path hack affect windows? + + // optionally delete the torrent data + if (deleteData) moveItemToTrash(summary) + + // remove torrent from saved list + this.state.saved.torrents.splice(index, 1) + State.saveThrottled(this.state) } - var index = state.saved.torrents.findIndex((x) => x.infoHash === infoHash) - if (index > -1) state.saved.torrents.splice(index, 1) - State.saveThrottled(state) - state.location.clearForward('player') // prevent user from going forward to a deleted torrent + this.state.location.clearForward('player') // prevent user from going forward to a deleted torrent sound.play('DELETE') } @@ -229,6 +236,13 @@ function findFilesRecursive (paths, cb) { }) } +function deleteFile (path) { + if (!path) return + fs.unlink(path, function (err) { + if (err) dispatch('onError', err) + }) +} + // Delete all files in a torren function moveItemToTrash (torrentSummary) { // TODO: delete directories, not just files