External player clean up (#914)
* minor `addSubtitles` clean up * external player clean up
This commit is contained in:
@@ -5,6 +5,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cp = require('child_process')
|
const cp = require('child_process')
|
||||||
|
const path = require('path')
|
||||||
const vlcCommand = require('vlc-command')
|
const vlcCommand = require('vlc-command')
|
||||||
|
|
||||||
const log = require('./log')
|
const log = require('./log')
|
||||||
@@ -13,15 +14,15 @@ const windows = require('./windows')
|
|||||||
// holds a ChildProcess while we're playing a video in an external player, null otherwise
|
// holds a ChildProcess while we're playing a video in an external player, null otherwise
|
||||||
let proc = null
|
let proc = null
|
||||||
|
|
||||||
function checkInstall (path, cb) {
|
function checkInstall (playerPath, cb) {
|
||||||
// check for VLC if external player has not been specified by the user
|
// check for VLC if external player has not been specified by the user
|
||||||
// otherwise assume the player is installed
|
// otherwise assume the player is installed
|
||||||
if (path == null) return vlcCommand((err) => cb(!err))
|
if (playerPath == null) return vlcCommand((err) => cb(!err))
|
||||||
process.nextTick(() => cb(true))
|
process.nextTick(() => cb(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawn (path, url, title) {
|
function spawn (playerPath, url, title) {
|
||||||
if (path != null) return spawnExternal(path, [url])
|
if (playerPath != null) return spawnExternal(playerPath, [url])
|
||||||
|
|
||||||
// Try to find and use VLC if external player is not specified
|
// Try to find and use VLC if external player is not specified
|
||||||
vlcCommand(function (err, vlcPath) {
|
vlcCommand(function (err, vlcPath) {
|
||||||
@@ -44,10 +45,15 @@ function kill () {
|
|||||||
proc = null
|
proc = null
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawnExternal (path, args) {
|
function spawnExternal (playerPath, args) {
|
||||||
log('Running external media player:', path + ' ' + args.join(' '))
|
log('Running external media player:', playerPath + ' ' + args.join(' '))
|
||||||
|
|
||||||
proc = cp.spawn(path, args, {stdio: 'ignore'})
|
if (path.extname(playerPath) === '.app') {
|
||||||
|
// Mac: Use executable in packaged .app bundle
|
||||||
|
playerPath += '/Contents/MacOS/' + path.basename(playerPath, '.app')
|
||||||
|
}
|
||||||
|
|
||||||
|
proc = cp.spawn(playerPath, args, {stdio: 'ignore'})
|
||||||
|
|
||||||
// If it works, close the modal after a second
|
// If it works, close the modal after a second
|
||||||
const closeModalTimeout = setTimeout(() =>
|
const closeModalTimeout = setTimeout(() =>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const React = require('react')
|
const React = require('react')
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
const ModalOKCancel = require('./modal-ok-cancel')
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
const {dispatcher} = require('../lib/dispatcher')
|
const {dispatcher} = require('../lib/dispatcher')
|
||||||
@@ -12,15 +11,11 @@ module.exports = class UnsupportedMediaModal extends React.Component {
|
|||||||
const message = (err && err.getMessage)
|
const message = (err && err.getMessage)
|
||||||
? err.getMessage()
|
? err.getMessage()
|
||||||
: err
|
: err
|
||||||
const playerPath = state.saved.prefs.externalPlayerPath
|
|
||||||
const playerName = playerPath
|
|
||||||
? path.basename(playerPath).split('.')[0]
|
|
||||||
: 'VLC'
|
|
||||||
const onAction = state.modal.externalPlayerInstalled
|
const onAction = state.modal.externalPlayerInstalled
|
||||||
? dispatcher('openExternalPlayer')
|
? dispatcher('openExternalPlayer')
|
||||||
: () => this.onInstall()
|
: () => this.onInstall()
|
||||||
const actionText = state.modal.externalPlayerInstalled
|
const actionText = state.modal.externalPlayerInstalled
|
||||||
? 'PLAY IN ' + playerName.toUpperCase()
|
? 'PLAY IN ' + state.getExternalPlayerName().toUpperCase()
|
||||||
: 'INSTALL VLC'
|
: 'INSTALL VLC'
|
||||||
const errorMessage = state.modal.externalPlayerNotFound
|
const errorMessage = state.modal.externalPlayerNotFound
|
||||||
? 'Couldn\'t run external player. Please make sure it\'s installed.'
|
? 'Couldn\'t run external player. Please make sure it\'s installed.'
|
||||||
|
|||||||
@@ -33,11 +33,10 @@ module.exports = class SubtitlesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addSubtitles (files, autoSelect) {
|
addSubtitles (files, autoSelect) {
|
||||||
const state = this.state
|
|
||||||
// Subtitles are only supported when playing video files
|
// Subtitles are only supported when playing video files
|
||||||
if (state.playing.type !== 'video') return
|
if (this.state.playing.type !== 'video') return
|
||||||
if (files.length === 0) return
|
if (files.length === 0) return
|
||||||
const subtitles = state.playing.subtitles
|
const subtitles = this.state.playing.subtitles
|
||||||
|
|
||||||
// Read the files concurrently, then add all resulting subtitle tracks
|
// Read the files concurrently, then add all resulting subtitle tracks
|
||||||
const tasks = files.map((file) => (cb) => loadSubtitle(file, cb))
|
const tasks = files.map((file) => (cb) => loadSubtitle(file, cb))
|
||||||
@@ -47,17 +46,17 @@ module.exports = class SubtitlesController {
|
|||||||
for (let i = 0; i < tracks.length; i++) {
|
for (let i = 0; i < tracks.length; i++) {
|
||||||
// No dupes allowed
|
// No dupes allowed
|
||||||
const track = tracks[i]
|
const track = tracks[i]
|
||||||
let trackIndex = state.playing.subtitles.tracks
|
let trackIndex = subtitles.tracks.findIndex((t) =>
|
||||||
.findIndex((t) => track.filePath === t.filePath)
|
track.filePath === t.filePath)
|
||||||
|
|
||||||
// Add the track
|
// Add the track
|
||||||
if (trackIndex === -1) {
|
if (trackIndex === -1) {
|
||||||
trackIndex = state.playing.subtitles.tracks.push(track) - 1
|
trackIndex = subtitles.tracks.push(track) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're auto-selecting a track, try to find one in the user's language
|
// If we're auto-selecting a track, try to find one in the user's language
|
||||||
if (autoSelect && (i === 0 || isSystemLanguage(track.language))) {
|
if (autoSelect && (i === 0 || isSystemLanguage(track.language))) {
|
||||||
state.playing.subtitles.selectedIndex = trackIndex
|
subtitles.selectedIndex = trackIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ function getDefaultState () {
|
|||||||
* Getters, for convenience
|
* Getters, for convenience
|
||||||
*/
|
*/
|
||||||
getPlayingTorrentSummary,
|
getPlayingTorrentSummary,
|
||||||
getPlayingFileSummary
|
getPlayingFileSummary,
|
||||||
|
getExternalPlayerName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +169,12 @@ function getPlayingFileSummary () {
|
|||||||
return torrentSummary.files[this.playing.fileIndex]
|
return torrentSummary.files[this.playing.fileIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getExternalPlayerName () {
|
||||||
|
const playerPath = this.saved.prefs.externalPlayerPath
|
||||||
|
if (!playerPath) return 'VLC'
|
||||||
|
return path.basename(playerPath).split('.')[0]
|
||||||
|
}
|
||||||
|
|
||||||
function load (cb) {
|
function load (cb) {
|
||||||
const state = getDefaultState()
|
const state = getDefaultState()
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const React = require('react')
|
|||||||
const Bitfield = require('bitfield')
|
const Bitfield = require('bitfield')
|
||||||
const prettyBytes = require('prettier-bytes')
|
const prettyBytes = require('prettier-bytes')
|
||||||
const zeroFill = require('zero-fill')
|
const zeroFill = require('zero-fill')
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
const TorrentSummary = require('../lib/torrent-summary')
|
const TorrentSummary = require('../lib/torrent-summary')
|
||||||
const Playlist = require('../lib/playlist')
|
const Playlist = require('../lib/playlist')
|
||||||
@@ -289,11 +288,8 @@ function renderCastScreen (state) {
|
|||||||
castType = 'DLNA'
|
castType = 'DLNA'
|
||||||
isCast = true
|
isCast = true
|
||||||
} else if (state.playing.location === 'external') {
|
} else if (state.playing.location === 'external') {
|
||||||
// TODO: get the player name in a more reliable way
|
|
||||||
const playerPath = state.saved.prefs.externalPlayerPath
|
|
||||||
const playerName = playerPath ? path.basename(playerPath).split('.')[0] : 'VLC'
|
|
||||||
castIcon = 'tv'
|
castIcon = 'tv'
|
||||||
castType = playerName
|
castType = state.getExternalPlayerName()
|
||||||
isCast = false
|
isCast = false
|
||||||
} else if (state.playing.location === 'error') {
|
} else if (state.playing.location === 'error') {
|
||||||
castIcon = 'error_outline'
|
castIcon = 'error_outline'
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const colors = require('material-ui/styles/colors')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const React = require('react')
|
const React = require('react')
|
||||||
|
|
||||||
|
const colors = require('material-ui/styles/colors')
|
||||||
const Checkbox = require('material-ui/Checkbox').default
|
const Checkbox = require('material-ui/Checkbox').default
|
||||||
|
const RaisedButton = require('material-ui/RaisedButton').default
|
||||||
const Heading = require('../components/heading')
|
const Heading = require('../components/heading')
|
||||||
const PathSelector = require('../components/path-selector')
|
const PathSelector = require('../components/path-selector')
|
||||||
const RaisedButton = require('material-ui/RaisedButton').default
|
|
||||||
|
|
||||||
const {dispatch} = require('../lib/dispatcher')
|
const {dispatch} = require('../lib/dispatcher')
|
||||||
|
|
||||||
@@ -59,9 +59,8 @@ class PreferencesPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
externalPlayerPathSelector () {
|
externalPlayerPathSelector () {
|
||||||
const playerName = path.basename(
|
const playerPath = this.props.state.unsaved.prefs.externalPlayerPath
|
||||||
this.props.state.unsaved.prefs.externalPlayerPath || 'VLC'
|
const playerName = this.props.state.getExternalPlayerName()
|
||||||
)
|
|
||||||
|
|
||||||
const description = this.props.state.unsaved.prefs.openExternalPlayer
|
const description = this.props.state.unsaved.prefs.openExternalPlayer
|
||||||
? `Torrent media files will always play in ${playerName}.`
|
? `Torrent media files will always play in ${playerName}.`
|
||||||
@@ -79,16 +78,12 @@ class PreferencesPage extends React.Component {
|
|||||||
displayValue={playerName}
|
displayValue={playerName}
|
||||||
onChange={this.handleExternalPlayerPathChange}
|
onChange={this.handleExternalPlayerPathChange}
|
||||||
title='External player'
|
title='External player'
|
||||||
value={this.props.state.unsaved.prefs.externalPlayerPath} />
|
value={playerPath ? path.dirname(playerPath) : null} />
|
||||||
</Preference>
|
</Preference>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleExternalPlayerPathChange (filePath) {
|
handleExternalPlayerPathChange (filePath) {
|
||||||
if (path.extname(filePath) === '.app') {
|
|
||||||
// Mac: Use executable in packaged .app bundle
|
|
||||||
filePath += '/Contents/MacOS/' + path.basename(filePath, '.app')
|
|
||||||
}
|
|
||||||
dispatch('updatePreferences', 'externalPlayerPath', filePath)
|
dispatch('updatePreferences', 'externalPlayerPath', filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user