Refactor main.js: controllers.playback.skip() (#706)
* Fixes bug with Step Forward/Backward commands not working * Fix 'invalid torrent identifier' error
This commit is contained in:
@@ -220,7 +220,7 @@ function getMenuTemplate () {
|
|||||||
accelerator: process.platform === 'darwin'
|
accelerator: process.platform === 'darwin'
|
||||||
? 'CmdOrCtrl+Alt+Right'
|
? 'CmdOrCtrl+Alt+Right'
|
||||||
: 'Alt+Right',
|
: 'Alt+Right',
|
||||||
click: () => windows.main.dispatch('skip', 1),
|
click: () => windows.main.dispatch('skip', 10),
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -228,7 +228,7 @@ function getMenuTemplate () {
|
|||||||
accelerator: process.platform === 'darwin'
|
accelerator: process.platform === 'darwin'
|
||||||
? 'CmdOrCtrl+Alt+Left'
|
? 'CmdOrCtrl+Alt+Left'
|
||||||
: 'Alt+Left',
|
: 'Alt+Left',
|
||||||
click: () => windows.main.dispatch('skip', -1),
|
click: () => windows.main.dispatch('skip', -10),
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -86,6 +86,11 @@ module.exports = class PlaybackController {
|
|||||||
ipcRenderer.send('onPlayerPause')
|
ipcRenderer.send('onPlayerPause')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip specified number of seconds (backwards if negative)
|
||||||
|
skip (time) {
|
||||||
|
this.skipTo(this.state.playing.currentTime + time)
|
||||||
|
}
|
||||||
|
|
||||||
// Skip (aka seek) to a specific point, in seconds
|
// Skip (aka seek) to a specific point, in seconds
|
||||||
skipTo (time) {
|
skipTo (time) {
|
||||||
if (isCasting(this.state)) Cast.seek(time)
|
if (isCasting(this.state)) Cast.seek(time)
|
||||||
|
|||||||
@@ -65,12 +65,30 @@ module.exports = class TorrentListController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starts downloading and/or seeding a given torrentSummary.
|
||||||
|
startTorrentingSummary (torrentSummary) {
|
||||||
|
var s = torrentSummary
|
||||||
|
|
||||||
|
// Backward compatibility for config files save before we had torrentKey
|
||||||
|
if (!s.torrentKey) s.torrentKey = this.state.nextTorrentKey++
|
||||||
|
|
||||||
|
// Use Downloads folder by default
|
||||||
|
if (!s.path) s.path = this.state.saved.prefs.downloadPath
|
||||||
|
|
||||||
|
ipcRenderer.send('wt-start-torrenting',
|
||||||
|
s.torrentKey,
|
||||||
|
TorrentSummary.getTorrentID(s),
|
||||||
|
s.path,
|
||||||
|
s.fileModtimes,
|
||||||
|
s.selections)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: use torrentKey, not infoHash
|
// TODO: use torrentKey, not infoHash
|
||||||
toggleTorrent (infoHash) {
|
toggleTorrent (infoHash) {
|
||||||
var torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
var torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
||||||
if (torrentSummary.status === 'paused') {
|
if (torrentSummary.status === 'paused') {
|
||||||
torrentSummary.status = 'new'
|
torrentSummary.status = 'new'
|
||||||
ipcRenderer.send('wt-start-torrenting', torrentSummary)
|
this.startTorrentingSummary(torrentSummary)
|
||||||
sound.play('ENABLE')
|
sound.play('ENABLE')
|
||||||
} else {
|
} else {
|
||||||
torrentSummary.status = 'paused'
|
torrentSummary.status = 'paused'
|
||||||
|
|||||||
@@ -181,11 +181,13 @@ const dispatchHandlers = {
|
|||||||
'toggleSelectTorrent': (infoHash) => controllers.torrentList.toggleSelectTorrent(infoHash),
|
'toggleSelectTorrent': (infoHash) => controllers.torrentList.toggleSelectTorrent(infoHash),
|
||||||
'openTorrentContextMenu': (infoHash) => controllers.torrentList.openTorrentContextMenu(infoHash),
|
'openTorrentContextMenu': (infoHash) => controllers.torrentList.openTorrentContextMenu(infoHash),
|
||||||
|
|
||||||
'startTorrentingSummary': startTorrentingSummary,
|
'startTorrentingSummary': (torrentSummary) =>
|
||||||
|
controllers.torrentList.startTorrentingSummary(torrentSummary),
|
||||||
|
|
||||||
// Playback
|
// Playback
|
||||||
'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index),
|
'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index),
|
||||||
'playPause': () => controllers.playback.playPause(),
|
'playPause': () => controllers.playback.playPause(),
|
||||||
|
'skip': (time) => controllers.playback.skip(time),
|
||||||
'skipTo': (time) => controllers.playback.skipTo(time),
|
'skipTo': (time) => controllers.playback.skipTo(time),
|
||||||
'changePlaybackRate': (dir) => controllers.playback.changePlaybackRate(dir),
|
'changePlaybackRate': (dir) => controllers.playback.changePlaybackRate(dir),
|
||||||
'changeVolume': (delta) => controllers.playback.changeVolume(delta),
|
'changeVolume': (delta) => controllers.playback.changeVolume(delta),
|
||||||
@@ -317,7 +319,7 @@ function escapeBack () {
|
|||||||
function resumeTorrents () {
|
function resumeTorrents () {
|
||||||
state.saved.torrents
|
state.saved.torrents
|
||||||
.filter((torrentSummary) => torrentSummary.status !== 'paused')
|
.filter((torrentSummary) => torrentSummary.status !== 'paused')
|
||||||
.forEach((torrentSummary) => startTorrentingSummary(torrentSummary))
|
.forEach((torrentSummary) => controllers.torrentList.startTorrentingSummary(torrentSummary))
|
||||||
}
|
}
|
||||||
|
|
||||||
function isTorrent (file) {
|
function isTorrent (file) {
|
||||||
@@ -333,19 +335,6 @@ function getTorrentSummary (torrentKey) {
|
|||||||
return TorrentSummary.getByKey(state, torrentKey)
|
return TorrentSummary.getByKey(state, torrentKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starts downloading and/or seeding a given torrentSummary. Returns WebTorrent object
|
|
||||||
function startTorrentingSummary (torrentSummary) {
|
|
||||||
var s = torrentSummary
|
|
||||||
|
|
||||||
// Backward compatibility for config files save before we had torrentKey
|
|
||||||
if (!s.torrentKey) s.torrentKey = state.nextTorrentKey++
|
|
||||||
|
|
||||||
// Use Downloads folder by default
|
|
||||||
if (!s.path) s.path = state.saved.prefs.downloadPath
|
|
||||||
|
|
||||||
ipcRenderer.send('wt-start-torrenting', s)
|
|
||||||
}
|
|
||||||
|
|
||||||
function torrentInfoHash (torrentKey, infoHash) {
|
function torrentInfoHash (torrentKey, infoHash) {
|
||||||
var torrentSummary = getTorrentSummary(torrentKey)
|
var torrentSummary = getTorrentSummary(torrentKey)
|
||||||
console.log('got infohash for %s torrent %s',
|
console.log('got infohash for %s torrent %s',
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ var path = require('path')
|
|||||||
var crashReporter = require('../crash-reporter')
|
var crashReporter = require('../crash-reporter')
|
||||||
var config = require('../config')
|
var config = require('../config')
|
||||||
var torrentPoster = require('./lib/torrent-poster')
|
var torrentPoster = require('./lib/torrent-poster')
|
||||||
var TorrentSummary = require('./lib/torrent-summary')
|
|
||||||
|
|
||||||
// Report when the process crashes
|
// Report when the process crashes
|
||||||
crashReporter.init()
|
crashReporter.init()
|
||||||
@@ -43,8 +42,8 @@ function init () {
|
|||||||
client.on('warning', (err) => ipc.send('wt-warning', null, err.message))
|
client.on('warning', (err) => ipc.send('wt-warning', null, err.message))
|
||||||
client.on('error', (err) => ipc.send('wt-error', null, err.message))
|
client.on('error', (err) => ipc.send('wt-error', null, err.message))
|
||||||
|
|
||||||
ipc.on('wt-start-torrenting', (e, torrentSummary) =>
|
ipc.on('wt-start-torrenting', (e, torrentKey, torrentID, path, fileModtimes, selections) =>
|
||||||
startTorrenting(torrentSummary))
|
startTorrenting(torrentKey, torrentID, path, fileModtimes, selections))
|
||||||
ipc.on('wt-stop-torrenting', (e, infoHash) =>
|
ipc.on('wt-stop-torrenting', (e, infoHash) =>
|
||||||
stopTorrenting(infoHash))
|
stopTorrenting(infoHash))
|
||||||
ipc.on('wt-create-torrent', (e, torrentKey, options) =>
|
ipc.on('wt-create-torrent', (e, torrentKey, options) =>
|
||||||
@@ -73,15 +72,12 @@ function init () {
|
|||||||
|
|
||||||
// Starts a given TorrentID, which can be an infohash, magnet URI, etc. Returns WebTorrent object
|
// Starts a given TorrentID, which can be an infohash, magnet URI, etc. Returns WebTorrent object
|
||||||
// See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent-
|
// See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent-
|
||||||
function startTorrenting (torrentSummary) {
|
function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections) {
|
||||||
var s = torrentSummary
|
|
||||||
var torrentKey = s.torrentKey
|
|
||||||
var torrentID = TorrentSummary.getTorrentID(s)
|
|
||||||
console.log('starting torrent %s: %s', torrentKey, torrentID)
|
console.log('starting torrent %s: %s', torrentKey, torrentID)
|
||||||
|
|
||||||
var torrent = client.add(torrentID, {
|
var torrent = client.add(torrentID, {
|
||||||
path: s.path,
|
path: path,
|
||||||
fileModtimes: s.fileModtimes
|
fileModtimes: fileModtimes
|
||||||
})
|
})
|
||||||
torrent.key = torrentKey
|
torrent.key = torrentKey
|
||||||
|
|
||||||
@@ -89,7 +85,7 @@ function startTorrenting (torrentSummary) {
|
|||||||
addTorrentEvents(torrent)
|
addTorrentEvents(torrent)
|
||||||
|
|
||||||
// Only download the files the user wants, not necessarily all files
|
// Only download the files the user wants, not necessarily all files
|
||||||
torrent.once('ready', () => selectFiles(torrent, s.selections))
|
torrent.once('ready', () => selectFiles(torrent, selections))
|
||||||
|
|
||||||
return torrent
|
return torrent
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user