fix: modernify code (#2068)

* fix: modernify code

* standard fix

* fixes
This commit is contained in:
Diego Rodríguez Baquero
2021-10-11 18:23:09 -05:00
committed by GitHub
parent c36e43eaa3
commit e42a515199
24 changed files with 134 additions and 161 deletions

View File

@@ -23,7 +23,7 @@ module.exports = class MediaController {
telemetry.logPlayAttempt('error')
state.playing.location = 'error'
ipcRenderer.send('checkForExternalPlayer', state.saved.prefs.externalPlayerPath)
ipcRenderer.once('checkForExternalPlayer', function (e, isInstalled) {
ipcRenderer.once('checkForExternalPlayer', (e, isInstalled) => {
state.modal = {
id: 'unsupported-media-modal',
error,
@@ -56,7 +56,7 @@ module.exports = class MediaController {
const state = this.state
state.playing.location = 'external'
const onServerRunning = function () {
const onServerRunning = () => {
state.playing.isReady = true
telemetry.logPlayAttempt('external')

View File

@@ -13,7 +13,7 @@ module.exports = class PrefsController {
const state = this.state
state.location.go({
url: 'preferences',
setup: function (cb) {
setup (cb) {
// initialize preferences
state.window.title = 'Preferences'
ipcRenderer.send('setAllowNav', false)

View File

@@ -37,12 +37,11 @@ module.exports = class SubtitlesController {
// Read the files concurrently, then add all resulting subtitle tracks
const tasks = files.map((file) => (cb) => loadSubtitle(file, cb))
parallel(tasks, function (err, tracks) {
parallel(tasks, (err, tracks) => {
if (err) return dispatch('error', err)
for (let i = 0; i < tracks.length; i++) {
// No dupes allowed
const track = tracks[i]
// No dupes allowed
tracks.forEach((track, i) => {
let trackIndex = subtitles.tracks.findIndex((t) =>
track.filePath === t.filePath)
@@ -55,7 +54,7 @@ module.exports = class SubtitlesController {
if (autoSelect && (i === 0 || isSystemLanguage(track.language))) {
subtitles.selectedIndex = trackIndex
}
}
})
// Finally, make sure no two tracks have the same label
relabelSubtitles(subtitles)
@@ -94,7 +93,7 @@ function loadSubtitle (file, cb) {
const vttStream = fs.createReadStream(filePath).pipe(srtToVtt())
concat(vttStream, function (err, buf) {
concat(vttStream, (err, buf) => {
if (err) return dispatch('error', 'Can\'t parse subtitles file.')
// Detect what language the subtitles are in
@@ -127,7 +126,7 @@ function isSystemLanguage (language) {
// Labels each track by language, eg 'German', 'English', 'English 2', ...
function relabelSubtitles (subtitles) {
const counts = {}
subtitles.tracks.forEach(function (track) {
subtitles.tracks.forEach(track => {
const lang = track.language
counts[lang] = (counts[lang] || 0) + 1
track.label = counts[lang] > 1 ? (lang + ' ' + counts[lang]) : lang

View File

@@ -177,7 +177,7 @@ function showDoneNotification (torrent) {
silent: true
})
notif.onclick = function () {
notif.onclick = () => {
ipcRenderer.send('show')
}

View File

@@ -94,7 +94,7 @@ module.exports = class TorrentListController {
if (!fileOrFolder) return start()
// Existing torrent: check that the path is still there
fs.stat(fileOrFolder, function (err) {
fs.stat(fileOrFolder, err => {
if (err) {
s.error = 'path-missing'
dispatch('backToList')
@@ -156,9 +156,7 @@ module.exports = class TorrentListController {
prioritizeTorrent (infoHash) {
this.state.saved.torrents
.filter((torrent) => { // We're interested in active torrents only.
return (['downloading', 'seeding'].indexOf(torrent.status) !== -1)
})
.filter(torrent => ['downloading', 'seeding'].includes(torrent.status)) // Active torrents only.
.forEach((torrent) => { // Pause all active torrents except the one that started playing.
if (infoHash === torrent.infoHash) return
@@ -331,9 +329,9 @@ module.exports = class TorrentListController {
if (!savePath) return // They clicked Cancel
console.log('Saving torrent ' + torrentKey + ' to ' + savePath)
const torrentPath = TorrentSummary.getTorrentPath(torrentSummary)
fs.readFile(torrentPath, function (err, torrentFile) {
fs.readFile(torrentPath, (err, torrentFile) => {
if (err) return dispatch('error', err)
fs.writeFile(savePath, torrentFile, function (err) {
fs.writeFile(savePath, torrentFile, err => {
if (err) return dispatch('error', err)
})
})
@@ -346,8 +344,8 @@ function findFilesRecursive (paths, cb_) {
if (paths.length > 1) {
let numComplete = 0
const ret = []
paths.forEach(function (path) {
findFilesRecursive([path], function (fileObjs) {
paths.forEach(path => {
findFilesRecursive([path], fileObjs => {
ret.push(...fileObjs)
if (++numComplete === paths.length) {
ret.sort((a, b) => a.path < b.path ? -1 : Number(a.path > b.path))
@@ -359,7 +357,7 @@ function findFilesRecursive (paths, cb_) {
}
const fileOrFolder = paths[0]
fs.stat(fileOrFolder, function (err, stat) {
fs.stat(fileOrFolder, (err, stat) => {
if (err) return dispatch('error', err)
// Files: return name, path, and size
@@ -374,7 +372,7 @@ function findFilesRecursive (paths, cb_) {
// Folders: recurse, make a list of all the files
const folderPath = fileOrFolder
fs.readdir(folderPath, function (err, fileNames) {
fs.readdir(folderPath, (err, fileNames) => {
if (err) return dispatch('error', err)
const paths = fileNames.map((fileName) => path.join(folderPath, fileName))
findFilesRecursive(paths, cb_)
@@ -384,7 +382,7 @@ function findFilesRecursive (paths, cb_) {
function deleteFile (path) {
if (!path) return
fs.unlink(path, function (err) {
fs.unlink(path, err => {
if (err) dispatch('error', err)
})
}