add context menu with share/save actions
This commit is contained in:
@@ -30,6 +30,7 @@ var torrentPoster = require('./lib/torrent-poster')
|
|||||||
// and this IPC channel receives from and sends messages to the main process
|
// and this IPC channel receives from and sends messages to the main process
|
||||||
var ipcRenderer = electron.ipcRenderer
|
var ipcRenderer = electron.ipcRenderer
|
||||||
var clipboard = electron.clipboard
|
var clipboard = electron.clipboard
|
||||||
|
var dialog = remote.require('dialog')
|
||||||
|
|
||||||
// For easy debugging in Developer Tools
|
// For easy debugging in Developer Tools
|
||||||
var state = global.state = require('./state')
|
var state = global.state = require('./state')
|
||||||
@@ -209,6 +210,9 @@ function dispatch (action, ...args) {
|
|||||||
if (action === 'toggleSelectTorrent') {
|
if (action === 'toggleSelectTorrent') {
|
||||||
toggleSelectTorrent(args[0] /* infoHash */)
|
toggleSelectTorrent(args[0] /* infoHash */)
|
||||||
}
|
}
|
||||||
|
if (action === 'openTorrentContextMenu') {
|
||||||
|
openTorrentContextMenu(args[0] /* torrentSummary */)
|
||||||
|
}
|
||||||
if (action === 'openChromecast') {
|
if (action === 'openChromecast') {
|
||||||
Cast.openChromecast()
|
Cast.openChromecast()
|
||||||
}
|
}
|
||||||
@@ -795,6 +799,44 @@ function toggleSelectTorrent (infoHash) {
|
|||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openTorrentContextMenu (torrentSummary) {
|
||||||
|
var menu = new remote.Menu()
|
||||||
|
menu.append(new remote.MenuItem({
|
||||||
|
label: 'Save Torrent File As...',
|
||||||
|
click: () => saveTorrentFileAs(torrentSummary)
|
||||||
|
}))
|
||||||
|
|
||||||
|
menu.append(new remote.MenuItem({
|
||||||
|
label: 'Copy Instant.io Link to Clipboard',
|
||||||
|
click: () => clipboard.writeText(`https://instant.io/#${torrentSummary.infoHash}`)
|
||||||
|
}))
|
||||||
|
|
||||||
|
menu.append(new remote.MenuItem({
|
||||||
|
label: 'Copy Magnet Link to Clipboard',
|
||||||
|
click: () => clipboard.writeText(torrentSummary.magnetURI)
|
||||||
|
}))
|
||||||
|
|
||||||
|
menu.popup(remote.getCurrentWindow())
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveTorrentFileAs (torrentSummary) {
|
||||||
|
var newFileName = `${path.parse(torrentSummary.name).name}.torrent`
|
||||||
|
var opts = {
|
||||||
|
title: 'Save Torrent File',
|
||||||
|
defaultPath: path.join(state.saved.downloadPath, newFileName),
|
||||||
|
filters: [{ name: 'Torrents', extensions: ['torrent'] }]
|
||||||
|
}
|
||||||
|
dialog.showSaveDialog(remote.getCurrentWindow(), opts, (savePath) => {
|
||||||
|
var torrentFile = fs.createReadStream(torrentSummary.torrentPath)
|
||||||
|
var savedTorrentFile = fs.createWriteStream(savePath)
|
||||||
|
torrentFile.on('error', (err) => console.error('Error reading torrent file', err))
|
||||||
|
savedTorrentFile.on('error', (err) => console.error('Error saving torrent file', err))
|
||||||
|
savedTorrentFile.on('close', () => console.log('Torrent saved', savePath))
|
||||||
|
|
||||||
|
torrentFile.pipe(savedTorrentFile)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Set window dimensions to match video dimensions or fill the screen
|
// Set window dimensions to match video dimensions or fill the screen
|
||||||
function setDimensions (dimensions) {
|
function setDimensions (dimensions) {
|
||||||
// Don't modify the window size if it's already maximized
|
// Don't modify the window size if it's already maximized
|
||||||
|
|||||||
@@ -47,7 +47,9 @@ function TorrentList (state, dispatch) {
|
|||||||
if (isSelected) classes.push('selected')
|
if (isSelected) classes.push('selected')
|
||||||
classes = classes.join(' ')
|
classes = classes.join(' ')
|
||||||
return hx`
|
return hx`
|
||||||
<div style=${style} class=${classes} onclick=${() => dispatch('toggleSelectTorrent', infoHash)}>
|
<div style=${style} class=${classes}
|
||||||
|
oncontextmenu=${() => dispatch('openTorrentContextMenu', torrentSummary)}
|
||||||
|
onclick=${() => dispatch('toggleSelectTorrent', infoHash)}>
|
||||||
${renderTorrentMetadata(torrent, torrentSummary)}
|
${renderTorrentMetadata(torrent, torrentSummary)}
|
||||||
${renderTorrentButtons(torrentSummary)}
|
${renderTorrentButtons(torrentSummary)}
|
||||||
${isSelected ? renderTorrentDetails(torrent, torrentSummary) : ''}
|
${isSelected ? renderTorrentDetails(torrent, torrentSummary) : ''}
|
||||||
|
|||||||
Reference in New Issue
Block a user