diff --git a/renderer/views/create-torrent-page.js b/renderer/views/create-torrent-page.js index 82fe517e..495b33a2 100644 --- a/renderer/views/create-torrent-page.js +++ b/renderer/views/create-torrent-page.js @@ -8,7 +8,7 @@ var createTorrent = require('create-torrent') var path = require('path') var prettyBytes = require('prettier-bytes') -var {dispatch} = require('../lib/dispatcher') +var {dispatch, dispatcher} = require('../lib/dispatcher') function CreateTorrentPage (state) { var info = state.location.current() @@ -17,17 +17,14 @@ function CreateTorrentPage (state) { var files = info.files .filter((f) => !f.name.startsWith('.')) .map((f) => ({name: f.name, path: f.path, size: f.size})) + if (files.length === 0) return CreateTorrentErrorPage() // First, extract the base folder that the files are all in var pathPrefix = info.folderPath if (!pathPrefix) { - if (files.length > 0) { - pathPrefix = files.map((x) => x.path).reduce(findCommonPrefix) - if (!pathPrefix.endsWith('/') && !pathPrefix.endsWith('\\')) { - pathPrefix = path.dirname(pathPrefix) - } - } else { - pathPrefix = files[0] + pathPrefix = files.map((x) => x.path).reduce(findCommonPrefix) + if (!pathPrefix.endsWith('/') && !pathPrefix.endsWith('\\')) { + pathPrefix = path.dirname(pathPrefix) } } @@ -133,6 +130,27 @@ function CreateTorrentPage (state) { } } +function CreateTorrentErrorPage () { + return hx` +
+

Create torrent

+

+

+ Sorry, you must select at least one file that is not a hidden file. +

+

+ Hidden files, starting with a . character, are not included. +

+

+

+ +

+
+ ` +} + // Finds the longest common prefix function findCommonPrefix (a, b) { for (var i = 0; i < a.length && i < b.length; i++) { diff --git a/renderer/views/player.js b/renderer/views/player.js index 8fe5366d..039848df 100644 --- a/renderer/views/player.js +++ b/renderer/views/player.js @@ -37,7 +37,8 @@ function renderMedia (state) { // Unfortunately, play/pause can't be done just by modifying HTML. // Instead, grab the DOM node and play/pause it if necessary - var mediaElement = document.querySelector(state.playing.type) /* get the