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:
Adam Gotlib
2016-07-08 05:27:05 +02:00
committed by DC
parent a373141a93
commit 50c47dd657
5 changed files with 36 additions and 28 deletions

View File

@@ -220,7 +220,7 @@ function getMenuTemplate () {
accelerator: process.platform === 'darwin'
? 'CmdOrCtrl+Alt+Right'
: 'Alt+Right',
click: () => windows.main.dispatch('skip', 1),
click: () => windows.main.dispatch('skip', 10),
enabled: false
},
{
@@ -228,7 +228,7 @@ function getMenuTemplate () {
accelerator: process.platform === 'darwin'
? 'CmdOrCtrl+Alt+Left'
: 'Alt+Left',
click: () => windows.main.dispatch('skip', -1),
click: () => windows.main.dispatch('skip', -10),
enabled: false
},
{

View File

@@ -86,6 +86,11 @@ module.exports = class PlaybackController {
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
skipTo (time) {
if (isCasting(this.state)) Cast.seek(time)

View File

@@ -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
toggleTorrent (infoHash) {
var torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
if (torrentSummary.status === 'paused') {
torrentSummary.status = 'new'
ipcRenderer.send('wt-start-torrenting', torrentSummary)
this.startTorrentingSummary(torrentSummary)
sound.play('ENABLE')
} else {
torrentSummary.status = 'paused'

View File

@@ -181,11 +181,13 @@ const dispatchHandlers = {
'toggleSelectTorrent': (infoHash) => controllers.torrentList.toggleSelectTorrent(infoHash),
'openTorrentContextMenu': (infoHash) => controllers.torrentList.openTorrentContextMenu(infoHash),
'startTorrentingSummary': startTorrentingSummary,
'startTorrentingSummary': (torrentSummary) =>
controllers.torrentList.startTorrentingSummary(torrentSummary),
// Playback
'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index),
'playPause': () => controllers.playback.playPause(),
'skip': (time) => controllers.playback.skip(time),
'skipTo': (time) => controllers.playback.skipTo(time),
'changePlaybackRate': (dir) => controllers.playback.changePlaybackRate(dir),
'changeVolume': (delta) => controllers.playback.changeVolume(delta),
@@ -317,7 +319,7 @@ function escapeBack () {
function resumeTorrents () {
state.saved.torrents
.filter((torrentSummary) => torrentSummary.status !== 'paused')
.forEach((torrentSummary) => startTorrentingSummary(torrentSummary))
.forEach((torrentSummary) => controllers.torrentList.startTorrentingSummary(torrentSummary))
}
function isTorrent (file) {
@@ -333,19 +335,6 @@ function getTorrentSummary (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) {
var torrentSummary = getTorrentSummary(torrentKey)
console.log('got infohash for %s torrent %s',

View File

@@ -14,7 +14,6 @@ var path = require('path')
var crashReporter = require('../crash-reporter')
var config = require('../config')
var torrentPoster = require('./lib/torrent-poster')
var TorrentSummary = require('./lib/torrent-summary')
// Report when the process crashes
crashReporter.init()
@@ -43,8 +42,8 @@ function init () {
client.on('warning', (err) => ipc.send('wt-warning', null, err.message))
client.on('error', (err) => ipc.send('wt-error', null, err.message))
ipc.on('wt-start-torrenting', (e, torrentSummary) =>
startTorrenting(torrentSummary))
ipc.on('wt-start-torrenting', (e, torrentKey, torrentID, path, fileModtimes, selections) =>
startTorrenting(torrentKey, torrentID, path, fileModtimes, selections))
ipc.on('wt-stop-torrenting', (e, infoHash) =>
stopTorrenting(infoHash))
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
// See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent-
function startTorrenting (torrentSummary) {
var s = torrentSummary
var torrentKey = s.torrentKey
var torrentID = TorrentSummary.getTorrentID(s)
function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections) {
console.log('starting torrent %s: %s', torrentKey, torrentID)
var torrent = client.add(torrentID, {
path: s.path,
fileModtimes: s.fileModtimes
path: path,
fileModtimes: fileModtimes
})
torrent.key = torrentKey
@@ -89,7 +85,7 @@ function startTorrenting (torrentSummary) {
addTorrentEvents(torrent)
// 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
}