Auto populate 'Magnet Link' field with the address from clipboard
Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
committed by
Jon Koops
parent
647eaf5af9
commit
a39691fdad
@@ -1,8 +1,10 @@
|
|||||||
const React = require('react')
|
const React = require('react')
|
||||||
const TextField = require('material-ui/TextField').default
|
const TextField = require('material-ui/TextField').default
|
||||||
|
const { clipboard } = require('electron')
|
||||||
|
|
||||||
const ModalOKCancel = require('./modal-ok-cancel')
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
||||||
|
const { isMagnetLink } = require('../lib/torrent-player')
|
||||||
|
|
||||||
module.exports = class OpenTorrentAddressModal extends React.Component {
|
module.exports = class OpenTorrentAddressModal extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
@@ -30,6 +32,12 @@ module.exports = class OpenTorrentAddressModal extends React.Component {
|
|||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.torrentURL.input.focus()
|
this.torrentURL.input.focus()
|
||||||
|
const clipboardContent = clipboard.readText()
|
||||||
|
|
||||||
|
if (isMagnetLink(clipboardContent)) {
|
||||||
|
this.torrentURL.input.value = clipboardContent
|
||||||
|
this.torrentURL.input.select()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ module.exports = {
|
|||||||
isVideo,
|
isVideo,
|
||||||
isAudio,
|
isAudio,
|
||||||
isTorrent,
|
isTorrent,
|
||||||
|
isMagnetLink,
|
||||||
isPlayableTorrentSummary
|
isPlayableTorrentSummary
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,9 +32,15 @@ function isAudio (file) {
|
|||||||
// - a file object where obj.name is ends in .torrent
|
// - a file object where obj.name is ends in .torrent
|
||||||
// - a string that's a magnet link (magnet://...)
|
// - a string that's a magnet link (magnet://...)
|
||||||
function isTorrent (file) {
|
function isTorrent (file) {
|
||||||
const isTorrentFile = getFileExtension(file) === '.torrent'
|
return isTorrentFile(file) || isMagnetLink(file)
|
||||||
const isMagnet = typeof file === 'string' && /^(stream-)?magnet:/.test(file)
|
}
|
||||||
return isTorrentFile || isMagnet
|
|
||||||
|
function isTorrentFile (file) {
|
||||||
|
return getFileExtension(file) === '.torrent'
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMagnetLink (link) {
|
||||||
|
return typeof link === 'string' && /^(stream-)?magnet:/.test(link)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileExtension (file) {
|
function getFileExtension (file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user