Remove torrent data support (#641)

* add moveItemToTrash to shell

* delete torrent/data + context menu items
This commit is contained in:
Mathias Rasmussen
2016-06-23 03:58:16 +02:00
committed by DC
parent 8e64e4120b
commit 1af7e4ef19
3 changed files with 35 additions and 2 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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 = {