Refactor main.js: torrent list controller

This commit is contained in:
DC
2016-06-30 19:19:10 -07:00
parent 4319ef2853
commit f85e0a61b1
5 changed files with 422 additions and 347 deletions

View File

@@ -116,6 +116,12 @@ function getApproxNumTorrents (state) {
// An uncaught error happened in the main process or in one of the windows
function logUncaughtError (procName, err) {
console.error('uncaught error', procName, err)
// Not initialized yet? Ignore.
// Hopefully uncaught errors immediately on startup are fixed in dev
if (!telemetry) return
var message, stack
if (typeof err === 'string') {
message = err

View File

@@ -1,6 +1,8 @@
module.exports = {
getPosterPath,
getTorrentPath
getTorrentPath,
getByKey,
getTorrentID
}
var path = require('path')
@@ -22,3 +24,22 @@ function getPosterPath (torrentSummary) {
// Backslashes in URLS in CSS cause bizarre string encoding issues
return posterPath.replace(/\\/g, '/')
}
// Expects a torrentSummary
// Returns a torrentID: filename, magnet URI, or infohash
function getTorrentID (torrentSummary) {
var s = torrentSummary
if (s.torrentFileName) { // Load torrent file from disk
return getTorrentPath(s)
} else { // Load torrent from DHT
return s.magnetURI || s.infoHash
}
}
// Expects a torrentKey or infoHash
// Returns the corresponding torrentSummary, or undefined
function getByKey (state, torrentKey) {
if (!torrentKey) return undefined
return state.saved.torrents.find((x) =>
x.torrentKey === torrentKey || x.infoHash === torrentKey)
}