From dd04b4ab62edb79731e687a22b71bb2632ba2beb Mon Sep 17 00:00:00 2001 From: DC Date: Mon, 14 Mar 2016 09:52:28 -0700 Subject: [PATCH] Fix chromecast button Next step: Chromecast and Airplay play/pause, scrub, and state management When casting, the correct cast button should be lit up and the video should be replaced with a title image and text --- renderer/index.js | 15 +++++++++------ renderer/views/player.js | 5 ++--- renderer/views/torrent-list.js | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/renderer/index.js b/renderer/index.js index 53774fc3..2e8c43be 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -190,10 +190,10 @@ function dispatch (action, ...args) { toggleSelectTorrent(args[0] /* infoHash */) } if (action === 'openChromecast') { - openChromecast(args[0] /* infoHash */) + openChromecast() } if (action === 'openAirplay') { - openAirplay(args[0] /* infoHash */) + openAirplay() } if (action === 'setDimensions') { setDimensions(args[0] /* dimensions */) @@ -283,6 +283,9 @@ function loadState (callback) { // populate defaults if they're not there state.saved = Object.assign({}, state.defaultSavedState, data) + state.saved.torrents.forEach(function (torrentSummary) { + if (torrentSummary.displayName) torrentSummary.name = torrentSummary.displayName + }) if (callback) callback() }) @@ -424,7 +427,7 @@ function addTorrentEvents (torrent) { var torrentSummary = getTorrentSummary(torrent.infoHash) torrentSummary.status = 'downloading' torrentSummary.ready = true - torrentSummary.name = torrent.name + torrentSummary.name = torrentSummary.displayName || torrent.name torrentSummary.infoHash = torrent.infoHash if (!torrentSummary.posterURL) { @@ -595,8 +598,8 @@ function toggleSelectTorrent (infoHash) { update() } -function openChromecast (infoHash) { - var torrentSummary = getTorrentSummary(infoHash) +function openChromecast () { + var torrentSummary = getTorrentSummary(state.playing.infoHash) state.devices.chromecast.play(state.server.networkURL, { title: config.APP_NAME + ' — ' + torrentSummary.name }) @@ -607,7 +610,7 @@ function openChromecast (infoHash) { update() } -function openAirplay (infoHash) { +function openAirplay () { state.devices.airplay.play(state.server.networkURL, 0, function () { // TODO: handle airplay errors }) diff --git a/renderer/views/player.js b/renderer/views/player.js index 794eb207..4cd1599b 100644 --- a/renderer/views/player.js +++ b/renderer/views/player.js @@ -64,7 +64,6 @@ function Player (state, dispatch) { function renderPlayerControls (state, dispatch) { var positionPercent = 100 * state.video.currentTime / state.video.duration var playbackCursorStyle = { left: 'calc(' + positionPercent + '% - 8px)' } - var torrent = state.client.get(state.playing.infoHash) var elements = [ hx` @@ -88,7 +87,7 @@ function renderPlayerControls (state, dispatch) { if (state.devices.chromecast) { elements.push(hx` dispatch('openChromecast', torrent)}> + onclick=${() => dispatch('openChromecast')}> cast `) @@ -96,7 +95,7 @@ function renderPlayerControls (state, dispatch) { if (state.devices.airplay) { elements.push(hx` dispatch('openAirplay', torrent)}> + onclick=${() => dispatch('openAirplay')}> airplay `) diff --git a/renderer/views/torrent-list.js b/renderer/views/torrent-list.js index af0004dd..1607867f 100644 --- a/renderer/views/torrent-list.js +++ b/renderer/views/torrent-list.js @@ -54,7 +54,7 @@ function TorrentList (state, dispatch) { // Show name, download status, % complete function renderTorrentMetadata (torrent, torrentSummary) { - var name = torrentSummary.displayName || torrentSummary.name || 'Loading torrent...' + var name = torrentSummary.name || 'Loading torrent...' var elements = [hx`
${name}
`]