diff --git a/main/menu.js b/main/menu.js index a79e0394..f8fac0c9 100644 --- a/main/menu.js +++ b/main/menu.js @@ -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 }, { diff --git a/renderer/controllers/playback-controller.js b/renderer/controllers/playback-controller.js index 3439aa00..de6c49fe 100644 --- a/renderer/controllers/playback-controller.js +++ b/renderer/controllers/playback-controller.js @@ -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) diff --git a/renderer/controllers/torrent-list-controller.js b/renderer/controllers/torrent-list-controller.js index 78a99841..29727052 100644 --- a/renderer/controllers/torrent-list-controller.js +++ b/renderer/controllers/torrent-list-controller.js @@ -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' diff --git a/renderer/main.js b/renderer/main.js index c16aa01b..874d7669 100644 --- a/renderer/main.js +++ b/renderer/main.js @@ -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', diff --git a/renderer/webtorrent.js b/renderer/webtorrent.js index 62d9471d..bce25a42 100644 --- a/renderer/webtorrent.js +++ b/renderer/webtorrent.js @@ -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 }