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

@@ -82,7 +82,7 @@ function openTorrentFile () {
const selectedPaths = dialog.showOpenDialogSync(windows.main.win, opts)
resetTitle()
if (!Array.isArray(selectedPaths)) return
selectedPaths.forEach(function (selectedPath) {
selectedPaths.forEach(selectedPath => {
windows.main.dispatch('addTorrent', selectedPath)
})
}

View File

@@ -110,13 +110,13 @@ function init () {
ipc.init()
app.once('ipcReady', function () {
app.once('ipcReady', () => {
log('Command line args:', argv)
processArgv(argv)
console.timeEnd('init')
})
app.on('before-quit', function (e) {
app.on('before-quit', e => {
if (app.isQuitting) return
app.isQuitting = true
@@ -129,7 +129,7 @@ function init () {
}, 4000) // quit after 4 secs, at most
})
app.on('activate', function () {
app.on('activate', () => {
if (isReady) windows.main.show()
})
}
@@ -207,7 +207,7 @@ function sliceArgv (argv) {
function processArgv (argv) {
const torrentIds = []
argv.forEach(function (arg) {
argv.forEach(arg => {
if (arg === '-n' || arg === '-o' || arg === '-u') {
// Critical path: Only load the 'dialog' package if it is needed
const dialog = require('./dialog')

View File

@@ -21,16 +21,16 @@ function setModule (name, module) {
}
function init () {
ipcMain.once('ipcReady', function (e) {
ipcMain.once('ipcReady', e => {
app.ipcReady = true
app.emit('ipcReady')
})
ipcMain.once('ipcReadyWebTorrent', function (e) {
ipcMain.once('ipcReadyWebTorrent', e => {
app.ipcReadyWebTorrent = true
log('sending %d queued messages from the main win to the webtorrent window',
messageQueueMainToWebTorrent.length)
messageQueueMainToWebTorrent.forEach(function (message) {
messageQueueMainToWebTorrent.forEach(message => {
windows.webtorrent.send(message.name, ...message.args)
log('webtorrent: sent queued %s', message.name)
})
@@ -66,7 +66,7 @@ function init () {
* Player Events
*/
ipcMain.on('onPlayerOpen', function () {
ipcMain.on('onPlayerOpen', () => {
const powerSaveBlocker = require('./power-save-blocker')
const shortcuts = require('./shortcuts')
const thumbar = require('./thumbar')
@@ -77,14 +77,14 @@ function init () {
thumbar.enable()
})
ipcMain.on('onPlayerUpdate', function (e, ...args) {
ipcMain.on('onPlayerUpdate', (e, ...args) => {
const thumbar = require('./thumbar')
menu.onPlayerUpdate(...args)
thumbar.onPlayerUpdate(...args)
})
ipcMain.on('onPlayerClose', function () {
ipcMain.on('onPlayerClose', () => {
const powerSaveBlocker = require('./power-save-blocker')
const shortcuts = require('./shortcuts')
const thumbar = require('./thumbar')
@@ -95,7 +95,7 @@ function init () {
thumbar.disable()
})
ipcMain.on('onPlayerPlay', function () {
ipcMain.on('onPlayerPlay', () => {
const powerSaveBlocker = require('./power-save-blocker')
const thumbar = require('./thumbar')
@@ -103,7 +103,7 @@ function init () {
thumbar.onPlayerPlay()
})
ipcMain.on('onPlayerPause', function () {
ipcMain.on('onPlayerPause', () => {
const powerSaveBlocker = require('./power-save-blocker')
const thumbar = require('./thumbar')
@@ -115,7 +115,7 @@ function init () {
* Folder Watcher Events
*/
ipcMain.on('startFolderWatcher', function () {
ipcMain.on('startFolderWatcher', () => {
if (!modules.folderWatcher) {
log('IPC ERR: folderWatcher module is not defined.')
return
@@ -124,7 +124,7 @@ function init () {
modules.folderWatcher.start()
})
ipcMain.on('stopFolderWatcher', function () {
ipcMain.on('stopFolderWatcher', () => {
if (!modules.folderWatcher) {
log('IPC ERR: folderWatcher module is not defined.')
return
@@ -190,10 +190,10 @@ function init () {
* External Media Player
*/
ipcMain.on('checkForExternalPlayer', function (e, path) {
ipcMain.on('checkForExternalPlayer', (e, path) => {
const externalPlayer = require('./external-player')
externalPlayer.checkInstall(path, function (err) {
externalPlayer.checkInstall(path, err => {
windows.main.send('checkForExternalPlayer', !err)
})
})
@@ -219,7 +219,7 @@ function init () {
*/
const oldEmit = ipcMain.emit
ipcMain.emit = function (name, e, ...args) {
ipcMain.emit = (name, e, ...args) => {
// Relay messages between the main window and the WebTorrent hidden window
if (name.startsWith('wt-') && !app.isQuitting) {
console.dir(e.sender.getTitle())

View File

@@ -68,11 +68,9 @@ function onToggleFullScreen (flag) {
}
function getMenuItem (label) {
for (let i = 0; i < menu.items.length; i++) {
const menuItem = menu.items[i].submenu.items.find(function (item) {
return item.label === label
})
if (menuItem) return menuItem
for (const menuItem of menu.items) {
const submenuItem = menuItem.submenu.items.find(item => item.label === label)
if (submenuItem) return submenuItem
}
return {}
}

View File

@@ -38,5 +38,5 @@ function showItemInFolder (path) {
*/
function moveItemToTrash (path) {
log(`moveItemToTrash: ${path}`)
shell.moveItemToTrash(path)
shell.trashItem(path)
}

View File

@@ -12,7 +12,7 @@ const handlers = require('./handlers')
const EXE_NAME = path.basename(process.execPath)
const UPDATE_EXE = path.join(process.execPath, '..', '..', 'Update.exe')
const run = function (args, done) {
const run = (args, done) => {
spawn(UPDATE_EXE, args, { detached: true })
.on('close', done)
}

View File

@@ -34,7 +34,7 @@ function setWindowFocus (flag) {
}
function initLinux () {
checkLinuxTraySupport(function (err) {
checkLinuxTraySupport(err => {
if (!err) createTray()
})
}
@@ -50,7 +50,7 @@ function checkLinuxTraySupport (cb) {
const cp = require('child_process')
// Check that libappindicator libraries are installed in system.
cp.exec('ldconfig -p | grep libappindicator', function (err, stdout) {
cp.exec('ldconfig -p | grep libappindicator', (err, stdout) => {
if (err) return cb(err)
cb(null)
})

View File

@@ -37,7 +37,7 @@ function init () {
win.loadURL(config.WINDOW_ABOUT)
win.once('ready-to-show', function () {
win.once('ready-to-show', () => {
win.show()
// No menu on the About window
// Hack: BrowserWindow removeMenu method not working on electron@7
@@ -45,7 +45,7 @@ function init () {
win.setMenuBarVisibility(false)
})
win.once('closed', function () {
win.once('closed', () => {
about.win = null
})
}

View File

@@ -38,7 +38,7 @@ function init () {
win.loadURL(config.WINDOW_WEBTORRENT)
// Prevent killing the WebTorrent process
win.on('close', function (e) {
win.on('close', e => {
if (app.isQuitting) {
return
}