Files
webtorrent-desktop/main/views/app.js
Feross Aboukhadijeh 1bfecb80a2 move webtorrent back into main window
We keep webtorrent running when the window is “closed” by hiding the
window instead.
2016-03-01 20:48:22 -08:00

57 lines
1.3 KiB
JavaScript

module.exports = App
var h = require('virtual-dom/h')
function App (state, handler) {
if (state.player) {
return h('.player', [
h('video', {
src: state.player.url,
autoplay: true,
controls: true
}),
h('button.close', {
onclick: closePlayer
}, 'Close')
])
} else {
var list = state.torrents.map(function (torrent) {
var style = {}
if (torrent.posterURL) {
style['background-image'] = 'url("' + torrent.posterURL + '")'
}
return h('.torrent', {
style: style
}, [
h('.name', torrent.name),
h('.progress', String(torrent.progress * 100) + '%'),
h('button.play', {
disabled: !torrent.ready,
onclick: openPlayer
}, 'Play')
])
function openPlayer () {
handler('openPlayer', torrent)
}
})
return h('.app', [
h('.torrent-list', list),
h('.add', [
h('button', {
onclick: onAddTorrent
}, 'Add New Torrent')
])
])
}
function onAddTorrent (e) {
var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4'
handler('addTorrent', torrentId)
}
function closePlayer () {
handler('closePlayer')
}
}