Resolve posterURL and torrentPath at runtime
Fixes bug where posters and torrent files can’t be found in the built app.
This commit is contained in:
@@ -22,6 +22,7 @@ var errors = require('./lib/errors')
|
|||||||
var config = require('../config')
|
var config = require('../config')
|
||||||
var TorrentPlayer = require('./lib/torrent-player')
|
var TorrentPlayer = require('./lib/torrent-player')
|
||||||
var torrentPoster = require('./lib/torrent-poster')
|
var torrentPoster = require('./lib/torrent-poster')
|
||||||
|
var util = require('./util')
|
||||||
|
|
||||||
// These two dependencies are the slowest-loading, so we lazy load them
|
// These two dependencies are the slowest-loading, so we lazy load them
|
||||||
// This cuts time from icon click to rendered window from ~550ms to ~150ms on my laptop
|
// This cuts time from icon click to rendered window from ~550ms to ~150ms on my laptop
|
||||||
@@ -478,7 +479,8 @@ function addTorrentToList (torrent) {
|
|||||||
function startTorrentingSummary (torrentSummary) {
|
function startTorrentingSummary (torrentSummary) {
|
||||||
var s = torrentSummary
|
var s = torrentSummary
|
||||||
if (s.torrentPath) {
|
if (s.torrentPath) {
|
||||||
var ret = startTorrentingID(s.torrentPath, s.path)
|
var torrentPath = util.getAbsoluteStaticPath(s.torrentPath)
|
||||||
|
var ret = startTorrentingID(torrentPath, s.path)
|
||||||
if (s.infoHash) state.pendingTorrents[s.infoHash] = ret
|
if (s.infoHash) state.pendingTorrents[s.infoHash] = ret
|
||||||
return ret
|
return ret
|
||||||
} else if (s.magnetURI) {
|
} else if (s.magnetURI) {
|
||||||
@@ -614,7 +616,7 @@ function generateTorrentPoster (torrent, torrentSummary) {
|
|||||||
fs.writeFile(posterFilePath, buf, function (err) {
|
fs.writeFile(posterFilePath, buf, function (err) {
|
||||||
if (err) return onWarning(err)
|
if (err) return onWarning(err)
|
||||||
// show the poster
|
// show the poster
|
||||||
torrentSummary.posterURL = 'file:///' + posterFilePath
|
torrentSummary.posterURL = posterFilePath
|
||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -874,7 +876,8 @@ function saveTorrentFileAs (torrentSummary) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
dialog.showSaveDialog(remote.getCurrentWindow(), opts, (savePath) => {
|
dialog.showSaveDialog(remote.getCurrentWindow(), opts, (savePath) => {
|
||||||
fs.readFile(torrentSummary.torrentPath, function (err, torrentFile) {
|
var torrentPath = util.getAbsoluteStaticPath(torrentSummary.torrentPath)
|
||||||
|
fs.readFile(torrentPath, function (err, torrentFile) {
|
||||||
if (err) return onError(err)
|
if (err) return onError(err)
|
||||||
fs.writeFile(savePath, torrentFile, function (err) {
|
fs.writeFile(savePath, torrentFile, function (err) {
|
||||||
if (err) return onError(err)
|
if (err) return onError(err)
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ module.exports = {
|
|||||||
infoHash: '88594aaacbde40ef3e2510c47374ec0aa396c08e',
|
infoHash: '88594aaacbde40ef3e2510c47374ec0aa396c08e',
|
||||||
magnetURI: 'magnet:?xt=urn:btih:88594aaacbde40ef3e2510c47374ec0aa396c08e&dn=bbb_sunflower_1080p_30fps_normal.mp4&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=http%3A%2F%2Fdistribution.bbb3d.renderfarming.net%2Fvideo%2Fmp4%2Fbbb_sunflower_1080p_30fps_normal.mp4',
|
magnetURI: 'magnet:?xt=urn:btih:88594aaacbde40ef3e2510c47374ec0aa396c08e&dn=bbb_sunflower_1080p_30fps_normal.mp4&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=http%3A%2F%2Fdistribution.bbb3d.renderfarming.net%2Fvideo%2Fmp4%2Fbbb_sunflower_1080p_30fps_normal.mp4',
|
||||||
displayName: 'Big Buck Bunny',
|
displayName: 'Big Buck Bunny',
|
||||||
posterURL: path.join('..', 'static', 'bigBuckBunny.jpg'),
|
posterURL: 'bigBuckBunny.jpg',
|
||||||
torrentPath: path.join('.', 'static', 'bigBuckBunny.torrent'),
|
torrentPath: 'bigBuckBunny.torrent',
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
'name': 'bbb_sunflower_1080p_30fps_normal.mp4',
|
'name': 'bbb_sunflower_1080p_30fps_normal.mp4',
|
||||||
@@ -82,8 +82,8 @@ module.exports = {
|
|||||||
infoHash: '6a9759bffd5c0af65319979fb7832189f4f3c35d',
|
infoHash: '6a9759bffd5c0af65319979fb7832189f4f3c35d',
|
||||||
magnetURI: 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4',
|
magnetURI: 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4',
|
||||||
displayName: 'Sintel',
|
displayName: 'Sintel',
|
||||||
posterURL: path.join('..', 'static', 'sintel.jpg'),
|
posterURL: 'sintel.jpg',
|
||||||
torrentPath: path.join('.', 'static', 'sintel.torrent'),
|
torrentPath: 'sintel.torrent',
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
'name': 'sintel.mp4',
|
'name': 'sintel.mp4',
|
||||||
@@ -98,8 +98,8 @@ module.exports = {
|
|||||||
infoHash: '02767050e0be2fd4db9a2ad6c12416ac806ed6ed',
|
infoHash: '02767050e0be2fd4db9a2ad6c12416ac806ed6ed',
|
||||||
magnetURI: 'magnet:?xt=urn:btih:02767050e0be2fd4db9a2ad6c12416ac806ed6ed&dn=tears_of_steel_1080p.webm&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io',
|
magnetURI: 'magnet:?xt=urn:btih:02767050e0be2fd4db9a2ad6c12416ac806ed6ed&dn=tears_of_steel_1080p.webm&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io',
|
||||||
displayName: 'Tears of Steel',
|
displayName: 'Tears of Steel',
|
||||||
posterURL: path.join('..', 'static', 'tearsOfSteel.jpg'),
|
posterURL: 'tearsOfSteel.jpg',
|
||||||
torrentPath: path.join('.', 'static', 'tearsOfSteel.torrent'),
|
torrentPath: 'tearsOfSteel.torrent',
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
'name': 'tears_of_steel_1080p.webm',
|
'name': 'tears_of_steel_1080p.webm',
|
||||||
|
|||||||
9
renderer/util.js
Normal file
9
renderer/util.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
var path = require('path')
|
||||||
|
|
||||||
|
var config = require('../config')
|
||||||
|
|
||||||
|
exports.getAbsoluteStaticPath = function (filePath) {
|
||||||
|
return path.isAbsolute(filePath)
|
||||||
|
? filePath
|
||||||
|
: path.join(config.STATIC_PATH, filePath)
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ var h = require('virtual-dom/h')
|
|||||||
var hyperx = require('hyperx')
|
var hyperx = require('hyperx')
|
||||||
var hx = hyperx(h)
|
var hx = hyperx(h)
|
||||||
|
|
||||||
|
var util = require('../util')
|
||||||
|
|
||||||
// Shows a streaming video player. Standard features + Chromecast + Airplay
|
// Shows a streaming video player. Standard features + Chromecast + Airplay
|
||||||
function Player (state, dispatch) {
|
function Player (state, dispatch) {
|
||||||
@@ -153,7 +154,8 @@ function renderCastScreen (state, dispatch) {
|
|||||||
function cssBackgroundImagePoster (state) {
|
function cssBackgroundImagePoster (state) {
|
||||||
var torrentSummary = getPlayingTorrentSummary(state)
|
var torrentSummary = getPlayingTorrentSummary(state)
|
||||||
if (!torrentSummary || !torrentSummary.posterURL) return ''
|
if (!torrentSummary || !torrentSummary.posterURL) return ''
|
||||||
var cleanURL = torrentSummary.posterURL.replace(/\\/g, '/')
|
var posterURL = util.getAbsoluteStaticPath(torrentSummary.posterURL)
|
||||||
|
var cleanURL = posterURL.replace(/\\/g, '/')
|
||||||
return 'radial-gradient(circle at center, ' +
|
return 'radial-gradient(circle at center, ' +
|
||||||
'rgba(0,0,0,0.4) 0%, rgba(0,0,0,1) 100%)' +
|
'rgba(0,0,0,0.4) 0%, rgba(0,0,0,1) 100%)' +
|
||||||
`, url(${cleanURL})`
|
`, url(${cleanURL})`
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ var hyperx = require('hyperx')
|
|||||||
var hx = hyperx(h)
|
var hx = hyperx(h)
|
||||||
var prettyBytes = require('prettier-bytes')
|
var prettyBytes = require('prettier-bytes')
|
||||||
|
|
||||||
|
var util = require('../util')
|
||||||
|
|
||||||
var TorrentPlayer = require('../lib/torrent-player')
|
var TorrentPlayer = require('../lib/torrent-player')
|
||||||
|
|
||||||
function TorrentList (state, dispatch) {
|
function TorrentList (state, dispatch) {
|
||||||
@@ -35,9 +37,10 @@ function TorrentList (state, dispatch) {
|
|||||||
var gradient = isSelected
|
var gradient = isSelected
|
||||||
? 'linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.4) 100%)'
|
? 'linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.4) 100%)'
|
||||||
: 'linear-gradient(to bottom, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%)'
|
: 'linear-gradient(to bottom, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%)'
|
||||||
|
var posterURL = util.getAbsoluteStaticPath(torrentSummary.posterURL)
|
||||||
// Work around a Chrome bug (reproduced in vanilla Chrome, not just Electron):
|
// Work around a Chrome bug (reproduced in vanilla Chrome, not just Electron):
|
||||||
// Backslashes in URLS in CSS cause bizarre string encoding issues
|
// Backslashes in URLS in CSS cause bizarre string encoding issues
|
||||||
var cleanURL = torrentSummary.posterURL.replace(/\\/g, '/')
|
var cleanURL = posterURL.replace(/\\/g, '/')
|
||||||
style.backgroundImage = gradient + `, url('${cleanURL}')`
|
style.backgroundImage = gradient + `, url('${cleanURL}')`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user