diff --git a/main/ipc.js b/main/ipc.js index d494c620..86eb0fe1 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -70,10 +70,15 @@ function init () { }) ipcMain.on('openItem', function (e, path) { - log('opening file or folder: ' + path) + log('open item: ' + path) electron.shell.openItem(path) }) + ipcMain.on('showItemInFolder', function (e, path) { + log('show item in folder: ' + path) + electron.shell.showItemInFolder(path) + }) + ipcMain.on('blockPowerSave', blockPowerSave) ipcMain.on('unblockPowerSave', unblockPowerSave) diff --git a/renderer/index.js b/renderer/index.js index 8319766a..56930997 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -226,9 +226,6 @@ function dispatch (action, ...args) { if (action === 'openFile') { openFile(args[0] /* infoHash */, args[1] /* index */) } - if (action === 'openFolder') { - openFolder(args[0] /* infoHash */) - } if (action === 'toggleTorrent') { toggleTorrent(args[0] /* infoHash */) } @@ -956,17 +953,6 @@ function openFile (infoHash, index) { ipcRenderer.send('openItem', filePath) } -function openFolder (infoHash) { - var torrentSummary = getTorrentSummary(infoHash) - - var firstFilePath = path.join( - torrentSummary.path, - torrentSummary.files[0].path) - var folderPath = path.dirname(firstFilePath) - - ipcRenderer.send('openItem', folderPath) -} - // TODO: use torrentKey, not infoHash function toggleTorrent (infoHash) { var torrentSummary = getTorrentSummary(infoHash) @@ -1001,9 +987,20 @@ function toggleSelectTorrent (infoHash) { function openTorrentContextMenu (infoHash) { var torrentSummary = getTorrentSummary(infoHash) var menu = new Menu() + + if (torrentSummary.files) { + menu.append(new MenuItem({ + label: process.platform === 'darwin' ? 'Show in Finder' : 'Show in Folder', + click: () => showItemInFolder(torrentSummary) + })) + menu.append(new MenuItem({ + type: 'separator' + })) + } + menu.append(new MenuItem({ - label: 'Save Torrent File As...', - click: () => saveTorrentFileAs(torrentSummary) + label: 'Copy Magnet Link to Clipboard', + click: () => clipboard.writeText(torrentSummary.magnetURI) })) menu.append(new MenuItem({ @@ -1012,13 +1009,21 @@ function openTorrentContextMenu (infoHash) { })) menu.append(new MenuItem({ - label: 'Copy Magnet Link to Clipboard', - click: () => clipboard.writeText(torrentSummary.magnetURI) + label: 'Save Torrent File As...', + click: () => saveTorrentFileAs(torrentSummary) })) menu.popup(remote.getCurrentWindow()) } +function showItemInFolder (torrentSummary) { + var itemPath = path.join(torrentSummary.path, torrentSummary.files[0].path) + if (torrentSummary.files.length > 1) { + itemPath = path.dirname(itemPath) + } + ipcRenderer.send('showItemInFolder', itemPath) +} + function saveTorrentFileAs (torrentSummary) { var newFileName = `${path.parse(torrentSummary.name).name}.torrent` var opts = { diff --git a/renderer/views/torrent-list.js b/renderer/views/torrent-list.js index 28fed5de..401b3494 100644 --- a/renderer/views/torrent-list.js +++ b/renderer/views/torrent-list.js @@ -167,7 +167,6 @@ function TorrentList (state) { // Show files, per-file download status and play buttons, and so on function renderTorrentDetails (torrentSummary) { - var infoHash = torrentSummary.infoHash var filesElement if (!torrentSummary.files) { // We don't know what files this torrent contains @@ -182,10 +181,6 @@ function TorrentList (state) { filesElement = hx`
Files - - Open folder - ${fileRows}