const path = require('path') const React = require('react') const colors = require('material-ui/styles/colors') const Checkbox = require('material-ui/Checkbox').default const RaisedButton = require('material-ui/RaisedButton').default const Heading = require('../components/heading') const PathSelector = require('../components/path-selector') const {dispatch} = require('../lib/dispatcher') const config = require('../../config') class PreferencesPage extends React.Component { constructor (props) { super(props) this.handleDownloadPathChange = this.handleDownloadPathChange.bind(this) this.handleOpenExternalPlayerChange = this.handleOpenExternalPlayerChange.bind(this) this.handleExternalPlayerPathChange = this.handleExternalPlayerPathChange.bind(this) this.handleStartupChange = this.handleStartupChange.bind(this) } downloadPathSelector () { return ( ) } handleDownloadPathChange (filePath) { dispatch('updatePreferences', 'downloadPath', filePath) } openExternalPlayerCheckbox () { return ( ) } handleOpenExternalPlayerChange (e, isChecked) { dispatch('updatePreferences', 'openExternalPlayer', !isChecked) } highestPlaybackPriorityCheckbox () { return (

Pauses all active torrents to allow playback to use all of the available bandwidth.

) } handleHighestPlaybackPriorityChange (e, isChecked) { dispatch('updatePreferences', 'highestPlaybackPriority', isChecked) } externalPlayerPathSelector () { const playerPath = this.props.state.unsaved.prefs.externalPlayerPath const playerName = this.props.state.getExternalPlayerName() const description = this.props.state.unsaved.prefs.openExternalPlayer ? `Torrent media files will always play in ${playerName}.` : `Torrent media files will play in ${playerName} if WebTorrent cannot play them.` return (

{description}

) } handleExternalPlayerPathChange (filePath) { dispatch('updatePreferences', 'externalPlayerPath', filePath) } autoAddTorrentsCheckbox () { return ( { this.handleAutoAddTorrentsChange(e, value) }} /> ) } handleAutoAddTorrentsChange (e, isChecked) { const torrentsFolderPath = this.props.state.unsaved.prefs.torrentsFolderPath if (isChecked && !torrentsFolderPath) { alert('Select a torrents folder first.') // eslint-disable-line e.preventDefault() return } dispatch('updatePreferences', 'autoAddTorrents', isChecked) if (isChecked) { dispatch('startFolderWatcher', null) return } dispatch('stopFolderWatcher', null) } torrentsFolderPathSelector () { const torrentsFolderPath = this.props.state.unsaved.prefs.torrentsFolderPath return ( ) } handletorrentsFolderPathChange (filePath) { dispatch('updatePreferences', 'torrentsFolderPath', filePath) } setDefaultAppButton () { const isFileHandler = this.props.state.unsaved.prefs.isFileHandler if (isFileHandler) { return (

WebTorrent is your default torrent app. Hooray!

) } return (

WebTorrent is not currently the default torrent app.

) } handleStartupChange (e, isChecked) { dispatch('updatePreferences', 'startup', isChecked) } setStartupSection () { if (config.IS_PORTABLE) { return } return ( ) } handleSetDefaultApp () { dispatch('updatePreferences', 'isFileHandler', true) } render () { const style = { color: colors.grey400, marginLeft: 25, marginRight: 25 } return (
{this.downloadPathSelector()} {this.autoAddTorrentsCheckbox()} {this.torrentsFolderPathSelector()} {this.openExternalPlayerCheckbox()} {this.externalPlayerPathSelector()} {this.highestPlaybackPriorityCheckbox()} {this.setDefaultAppButton()} {this.setStartupSection()}
) } } class PreferencesSection extends React.Component { static get propTypes () { return { title: React.PropTypes.string } } render () { const style = { marginBottom: 25, marginTop: 25 } return (
{this.props.title} {this.props.children}
) } } class Preference extends React.Component { render () { const style = { marginBottom: 10 } return (
{this.props.children}
) } } module.exports = PreferencesPage