diff --git a/main/ipc.js b/main/ipc.js index 8a81853f..b03d03b5 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -81,6 +81,7 @@ function init () { ipc.on('openItem', (e, ...args) => shell.openItem(...args)) ipc.on('showItemInFolder', (e, ...args) => shell.showItemInFolder(...args)) + ipc.on('moveItemToTrash', (e, ...args) => shell.moveItemToTrash(...args)) /** * Windows: Main diff --git a/main/shell.js b/main/shell.js index 8461d3ce..83bf381f 100644 --- a/main/shell.js +++ b/main/shell.js @@ -1,7 +1,8 @@ module.exports = { openExternal, openItem, - showItemInFolder + showItemInFolder, + moveItemToTrash } var electron = require('electron') @@ -30,3 +31,11 @@ function showItemInFolder (path) { log(`showItemInFolder: ${path}`) electron.shell.showItemInFolder(path) } + +/** + * Move the given file to trash and returns a boolean status for the operation. + */ +function moveItemToTrash (path) { + log(`moveItemToTrash: ${path}`) + electron.shell.moveItemToTrash(path) +} diff --git a/renderer/main.js b/renderer/main.js index 941e3e1c..6a759d1d 100644 --- a/renderer/main.js +++ b/renderer/main.js @@ -1127,9 +1127,14 @@ function toggleTorrent (infoHash) { } // TODO: use torrentKey, not infoHash -function deleteTorrent (infoHash) { +function deleteTorrent (infoHash, deleteData) { ipcRenderer.send('wt-stop-torrenting', infoHash) + if (deleteData) { + var torrentSummary = getTorrentSummary(infoHash) + moveItemToTrash(torrentSummary) + } + var index = state.saved.torrents.findIndex((x) => x.infoHash === infoHash) if (index > -1) state.saved.torrents.splice(index, 1) saveStateThrottled() @@ -1155,6 +1160,20 @@ function openTorrentContextMenu (infoHash) { var torrentSummary = getTorrentSummary(infoHash) var menu = new electron.remote.Menu() + menu.append(new electron.remote.MenuItem({ + label: 'Remove From List', + click: () => deleteTorrent(torrentSummary.infoHash, false) + })) + + menu.append(new electron.remote.MenuItem({ + label: 'Remove Data File', + click: () => deleteTorrent(torrentSummary.infoHash, true) + })) + + menu.append(new electron.remote.MenuItem({ + type: 'separator' + })) + if (torrentSummary.files) { menu.append(new electron.remote.MenuItem({ label: process.platform === 'darwin' ? 'Show in Finder' : 'Show in Folder', @@ -1195,6 +1214,10 @@ function showItemInFolder (torrentSummary) { ipcRenderer.send('showItemInFolder', getTorrentPath(torrentSummary)) } +function moveItemToTrash (torrentSummary) { + ipcRenderer.send('moveItemToTrash', getTorrentPath(torrentSummary)) +} + function saveTorrentFileAs (torrentSummary) { var newFileName = `${path.parse(torrentSummary.name).name}.torrent` var opts = {