@@ -1,4 +1,5 @@
|
||||
const State = require('../lib/state')
|
||||
const {dispatch} = require('../lib/dispatcher')
|
||||
const ipcRenderer = require('electron').ipcRenderer
|
||||
|
||||
// Controls the Preferences screen
|
||||
@@ -50,5 +51,6 @@ module.exports = class PrefsController {
|
||||
}
|
||||
state.saved.prefs = Object.assign(state.saved.prefs || {}, state.unsaved.prefs)
|
||||
State.save(state)
|
||||
dispatch('checkDownloadPath')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ const dragDrop = require('drag-drop')
|
||||
const electron = require('electron')
|
||||
const React = require('react')
|
||||
const ReactDOM = require('react-dom')
|
||||
const fs = require('fs')
|
||||
|
||||
const config = require('../config')
|
||||
const App = require('./views/app')
|
||||
@@ -74,6 +75,12 @@ function onState (err, _state) {
|
||||
}
|
||||
})
|
||||
|
||||
// Calling update() updates the UI given the current state
|
||||
// Do this at least once a second to give every file in every torrentSummary
|
||||
// a progress bar and to keep the cursor in sync when playing a video
|
||||
setInterval(update, 1000)
|
||||
app = ReactDOM.render(<App state={state} />, document.querySelector('#body'))
|
||||
|
||||
// Restart everything we were torrenting last time the app ran
|
||||
resumeTorrents()
|
||||
|
||||
@@ -83,11 +90,8 @@ function onState (err, _state) {
|
||||
// Listen for messages from the main process
|
||||
setupIpc()
|
||||
|
||||
// Calling update() updates the UI given the current state
|
||||
// Do this at least once a second to give every file in every torrentSummary
|
||||
// a progress bar and to keep the cursor in sync when playing a video
|
||||
setInterval(update, 1000)
|
||||
app = ReactDOM.render(<App state={state} />, document.querySelector('#body'))
|
||||
// Warn if the download dir is gone, eg b/c an external drive is unplugged
|
||||
checkDownloadPath()
|
||||
|
||||
// OS integrations:
|
||||
// ...drag and drop files/text to start torrenting or seeding
|
||||
@@ -212,6 +216,7 @@ const dispatchHandlers = {
|
||||
// Preferences screen
|
||||
'preferences': () => controllers.prefs.show(),
|
||||
'updatePreferences': (key, value) => controllers.prefs.update(key, value),
|
||||
'checkDownloadPath': checkDownloadPath,
|
||||
|
||||
// Update (check for new versions on Linux, where there's no auto updater)
|
||||
'updateAvailable': (version) => controllers.update.updateAvailable(version),
|
||||
@@ -433,3 +438,15 @@ function onFullscreenChanged (e, isFullScreen) {
|
||||
|
||||
update()
|
||||
}
|
||||
|
||||
function checkDownloadPath () {
|
||||
state.downloadPathStatus = undefined
|
||||
fs.stat(state.saved.prefs.downloadPath, function (err, stat) {
|
||||
if (err) {
|
||||
state.downloadPathStatus = 'missing'
|
||||
return console.error(err)
|
||||
}
|
||||
if (stat.isDirectory()) state.downloadPathStatus = 'ok'
|
||||
else state.downloadPathStatus = 'missing'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ function renderGeneralSection (state) {
|
||||
description: '',
|
||||
icon: 'settings'
|
||||
}, [
|
||||
renderDownloadDirSelector(state),
|
||||
renderDownloadPathSelector(state),
|
||||
renderFileHandlers(state)
|
||||
])
|
||||
}
|
||||
|
||||
function renderDownloadDirSelector (state) {
|
||||
function renderDownloadPathSelector (state) {
|
||||
return renderFileSelector({
|
||||
key: 'download-path',
|
||||
label: 'Download Path',
|
||||
|
||||
@@ -8,16 +8,36 @@ const {dispatcher} = require('../lib/dispatcher')
|
||||
module.exports = class TorrentList extends React.Component {
|
||||
render () {
|
||||
var state = this.props.state
|
||||
var torrentRows = state.saved.torrents.map(
|
||||
(torrentSummary) => this.renderTorrent(torrentSummary)
|
||||
)
|
||||
|
||||
return (
|
||||
<div key='torrent-list' className='torrent-list'>
|
||||
{torrentRows}
|
||||
var contents
|
||||
if (!state.downloadPathStatus) {
|
||||
contents = ''
|
||||
} else if (state.downloadPathStatus === 'missing') {
|
||||
contents = (
|
||||
<div>
|
||||
<p>Download path missing: {state.saved.prefs.downloadPath}</p>
|
||||
<p>Check that all drives are connected?</p>
|
||||
<p>Alternatively, choose a new download path in
|
||||
<a href='#' onClick={dispatcher('preferences')}>Preferences</a>
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
} else if (state.downloadPathStatus === 'ok') {
|
||||
contents = state.saved.torrents.map(
|
||||
(torrentSummary) => this.renderTorrent(torrentSummary)
|
||||
)
|
||||
contents.push(
|
||||
<div key='torrent-placeholder' className='torrent-placeholder'>
|
||||
<span className='ellipsis'>Drop a torrent file here or paste a magnet link</span>
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
throw new Error('Unhandled downloadPathStatus ' + state.downloadPathStatus)
|
||||
}
|
||||
|
||||
return (
|
||||
<div key='torrent-list' className='torrent-list'>
|
||||
{contents}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -551,6 +551,13 @@ input[type='text'] {
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
/*
|
||||
* TORRENT LIST: ERRORS
|
||||
*/
|
||||
.torrent-list p {
|
||||
padding: 5px 20px;
|
||||
}
|
||||
|
||||
/*
|
||||
* TORRENT LIST: DRAG-DROP TARGET
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user