From 8108c407d3bd0fc452f4819c855c031de33b0ce1 Mon Sep 17 00:00:00 2001 From: DC Date: Mon, 14 Mar 2016 00:51:00 -0700 Subject: [PATCH] Torrent details Show file list, open folder containing downloaded files, open individual files, play/pause individual videos --- main/ipc.js | 11 +- renderer/index.css | 65 +++++-- renderer/index.js | 70 ++++--- renderer/lib/torrent-player.js | 13 ++ renderer/state.js | 17 +- renderer/views/player.js | 4 +- renderer/views/torrent-list.js | 332 ++++++++++++++++++--------------- 7 files changed, 316 insertions(+), 196 deletions(-) create mode 100644 renderer/lib/torrent-player.js diff --git a/main/ipc.js b/main/ipc.js index 7c34c7b3..81e51b2c 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -4,13 +4,13 @@ module.exports = { var debug = require('debug')('webtorrent-app:ipcMain') var electron = require('electron') -var menu = require('./menu') -var windows = require('./windows') - var app = electron.app var ipcMain = electron.ipcMain var powerSaveBlocker = electron.powerSaveBlocker +var menu = require('./menu') +var windows = require('./windows') + // has to be a number, not a boolean, and undefined throws an error var powerSaveBlocked = 0 @@ -56,6 +56,11 @@ function init () { powerSaveBlocker.stop(powerSaveBlocked) } }) + + ipcMain.on('openItem', function (e, path) { + console.log('opening file or folder: ' + path) + electron.shell.openItem(path) + }) } function setBounds (bounds) { diff --git a/renderer/index.css b/renderer/index.css index 7a3ca34f..5d3812e2 100644 --- a/renderer/index.css +++ b/renderer/index.css @@ -145,12 +145,14 @@ table { * BUTTONS */ -a, i { +a, +i { cursor: default; -webkit-app-region: no-drag; } -a:not(.disabled):hover, i:not(.disabled):hover { +a:not(.disabled):hover, +i:not(.disabled):hover { -webkit-filter: brightness(1.3); } @@ -210,7 +212,7 @@ a:not(.disabled):hover, i:not(.disabled):hover { .header .nav { font-weight: bold; - margin-right: 7px; + margin-right: 9px; } .header .nav.left { @@ -237,7 +239,8 @@ a:not(.disabled):hover, i:not(.disabled):hover { opacity: 1; } -.header .nav .back, .header .nav .forward { +.header .nav .back, +.header .nav .forward { font-size: 30px; margin-top: -3px; } @@ -370,7 +373,8 @@ input { animation: fadein .4s; } -.torrent, .torrent-placeholder { +.torrent, +.torrent-placeholder { height: 120px; } @@ -390,11 +394,14 @@ input { text-shadow: rgba(0, 0, 0, 0.5) 0 0 4px; } +.torrent .metadata span:not(:last-child)::after { + content: ' — '; +} + .torrent .buttons { position: absolute; top: 25px; - right: 0; - height: 100%; + right: 10px; display: none; } @@ -403,7 +410,7 @@ input { } .torrent .buttons > * { - margin-right: 6px; /* space buttons apart, align the Xs under the + */ + margin-left: 6px; /* space buttons apart */ } .torrent .buttons .download { @@ -413,7 +420,6 @@ input { border-radius: 14px; font-size: 18px; padding-top: 6px; - margin-right: 10px; /* download and play btns need more space to look good */ } .torrent .buttons .download.downloading { @@ -467,24 +473,27 @@ input { } .torrent .buttons .delete { + position: relative; + top: 2px; opacity: 0.5; } +.torrent .buttons .delete:hover { + opacity: 0.7; +} + .torrent .name { font-size: 1.5em; font-weight: bold; line-height: 1.5em; } -.torrent .status, .torrent .status2 { +.torrent .status, +.torrent .status2 { font-size: 1em; line-height: 1.5em; } -.torrent span:not(:last-child)::after { - content: ' — '; -} - /* * TORRENT LIST: DRAG-DROP TARGET */ @@ -520,10 +529,20 @@ body.drag .torrent-placeholder span { padding: 8em 20px 20px 20px; } +.torrent-details .open-folder { + float: right; +} + .torrent-details table { width: 100%; - max-width: 1000px; white-space: nowrap; + border: none; + border-spacing: 0; +} + +.torrent-details tr:hover, +.torrent-details .open-folder:hover { + background-color: rgba(200, 200, 200, 0.3); } .torrent-details td { @@ -531,6 +550,16 @@ body.drag .torrent-placeholder span { padding: 0; } +.torrent-details td.col-icon { + width: 2em; +} + +.torrent-details td.col-icon .icon { + font-size: 18px; + position: relative; + top: 3px; +} + .torrent-details td.col-name { width: auto; text-overflow: ellipsis; @@ -667,7 +696,8 @@ body.drag .torrent-placeholder span { font-size: 16px; line-height: 1.5em; } - .torrent, .torrent-placeholder { + .torrent, + .torrent-placeholder { height: 150px; } } @@ -677,7 +707,8 @@ body.drag .torrent-placeholder span { font-size: 18px; line-height: 1.5em; } - .torrent, .torrent-placeholder { + .torrent, + .torrent-placeholder { height: 180px; } } diff --git a/renderer/index.js b/renderer/index.js index 5126e09f..53774fc3 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -21,6 +21,7 @@ var patch = require('virtual-dom/patch') var App = require('./views/app') var config = require('../config') var torrentPoster = require('./lib/torrent-poster') +var TorrentPlayer = require('./lib/torrent-player') // Electron apps have two processes: a main process (node) runs first and starts // a renderer process (essentially a Chrome window). We're in the renderer process, @@ -169,8 +170,15 @@ function dispatch (action, ...args) { if (action === 'seed') { seed(args[0] /* files */) } - if (action === 'openPlayer') { - openPlayer(args[0] /* torrentSummary */) + if (action === 'play') { + // TODO: handle audio. video only for now. + openPlayer(args[0] /* torrentSummary */, args[1] /* index */) + } + if (action === 'openFile') { + openFile(args[0] /* torrentSummary */, args[1] /* index */) + } + if (action === 'openFolder') { + openFolder(args[0] /* torrentSummary */) } if (action === 'toggleTorrent') { toggleTorrent(args[0] /* torrentSummary */) @@ -453,32 +461,33 @@ function generateTorrentPoster (torrent, torrentSummary) { }) } -function startServer (infoHash, cb) { +function startServer (infoHash, index, cb) { if (state.server) return cb() var torrent = getTorrent(infoHash) if (!torrent) torrent = startTorrenting(infoHash) - if (torrent.ready) startServerFromReadyTorrent(torrent, cb) - else torrent.on('ready', () => startServerFromReadyTorrent(torrent, cb)) + if (torrent.ready) startServerFromReadyTorrent(torrent, index, cb) + else torrent.on('ready', () => startServerFromReadyTorrent(torrent, index, cb)) } -function startServerFromReadyTorrent (torrent, cb) { - // filter out file formats that the