diff --git a/src/renderer/components/open-torrent-address-modal.js b/src/renderer/components/open-torrent-address-modal.js index 01cb5a04..4e478736 100644 --- a/src/renderer/components/open-torrent-address-modal.js +++ b/src/renderer/components/open-torrent-address-modal.js @@ -1,8 +1,10 @@ const React = require('react') const TextField = require('material-ui/TextField').default +const { clipboard } = require('electron') const ModalOKCancel = require('./modal-ok-cancel') const { dispatch, dispatcher } = require('../lib/dispatcher') +const { isMagnetLink } = require('../lib/torrent-player') module.exports = class OpenTorrentAddressModal extends React.Component { render () { @@ -30,6 +32,12 @@ module.exports = class OpenTorrentAddressModal extends React.Component { componentDidMount () { this.torrentURL.input.focus() + const clipboardContent = clipboard.readText() + + if (isMagnetLink(clipboardContent)) { + this.torrentURL.input.value = clipboardContent + this.torrentURL.input.select() + } } } diff --git a/src/renderer/lib/torrent-player.js b/src/renderer/lib/torrent-player.js index ab0e9702..3e8d1403 100644 --- a/src/renderer/lib/torrent-player.js +++ b/src/renderer/lib/torrent-player.js @@ -3,6 +3,7 @@ module.exports = { isVideo, isAudio, isTorrent, + isMagnetLink, isPlayableTorrentSummary } @@ -31,9 +32,15 @@ function isAudio (file) { // - a file object where obj.name is ends in .torrent // - a string that's a magnet link (magnet://...) function isTorrent (file) { - const isTorrentFile = getFileExtension(file) === '.torrent' - const isMagnet = typeof file === 'string' && /^(stream-)?magnet:/.test(file) - return isTorrentFile || isMagnet + return isTorrentFile(file) || isMagnetLink(file) +} + +function isTorrentFile (file) { + return getFileExtension(file) === '.torrent' +} + +function isMagnetLink (link) { + return typeof link === 'string' && /^(stream-)?magnet:/.test(link) } function getFileExtension (file) {