diff --git a/package.json b/package.json index 069aaf9e..e9c6d59f 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "location-history": "^1.0.0", "material-ui": "^0.17.0", "mkdirp": "^0.5.1", - "music-metadata": "^1.0.0", + "music-metadata": "^1.1.0", "network-address": "^1.1.0", "parse-torrent": "^6.0.1", "prettier-bytes": "^1.0.1", diff --git a/src/main/external-player.js b/src/main/external-player.js index c6858120..d378a623 100644 --- a/src/main/external-player.js +++ b/src/main/external-player.js @@ -25,7 +25,7 @@ function spawn (playerPath, url, title) { if (playerPath != null) return spawnExternal(playerPath, [url]) // Try to find and use VLC if external player is not specified - vlcCommand(function (err, vlcPath) { + vlcCommand((err, vlcPath) => { if (err) return windows.main.dispatch('externalPlayerNotFound') const args = [ '--play-and-exit', @@ -49,7 +49,7 @@ function spawnExternal (playerPath, args) { if (process.platform === 'darwin' && path.extname(playerPath) === '.app') { // Mac: Use executable in packaged .app bundle - playerPath += '/Contents/MacOS/' + path.basename(playerPath, '.app') + playerPath += `/Contents/MacOS/${path.basename(playerPath, '.app')}` } proc = cp.spawn(playerPath, args, {stdio: 'ignore'}) @@ -58,7 +58,7 @@ function spawnExternal (playerPath, args) { const closeModalTimeout = setTimeout(() => windows.main.dispatch('exitModal'), 1000) - proc.on('close', function (code) { + proc.on('close', code => { clearTimeout(closeModalTimeout) if (!proc) return // Killed log('External player exited with code ', code) @@ -70,7 +70,7 @@ function spawnExternal (playerPath, args) { proc = null }) - proc.on('error', function (e) { - log('External player error', e) + proc.on('error', err => { + log('External player error', err) }) } diff --git a/src/main/handlers.js b/src/main/handlers.js index 805cd5ce..3c42e443 100644 --- a/src/main/handlers.js +++ b/src/main/handlers.js @@ -7,26 +7,24 @@ const config = require('../config') const path = require('path') function install () { - if (process.platform === 'darwin') { - installDarwin() - } - if (process.platform === 'win32') { - installWin32() - } - if (process.platform === 'linux') { - installLinux() + switch (process.platform) { + case 'darwin': installDarwin() + break + case 'win32': installWin32() + break + case 'linux': installLinux() + break } } function uninstall () { - if (process.platform === 'darwin') { - uninstallDarwin() - } - if (process.platform === 'win32') { - uninstallWin32() - } - if (process.platform === 'linux') { - uninstallLinux() + switch (process.platform) { + case 'darwin': uninstallDarwin() + break + case 'win32': uninstallWin32() + break + case 'linux': uninstallLinux() + break } } @@ -108,37 +106,37 @@ function installWin32 () { setProtocol() function setProtocol (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) protocolKey.set('', Registry.REG_SZ, name, setURLProtocol) } function setURLProtocol (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) protocolKey.set('URL Protocol', Registry.REG_SZ, '', setIcon) } function setIcon (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) const iconKey = new Registry({ hive: Registry.HKCU, - key: '\\Software\\Classes\\' + protocol + '\\DefaultIcon' + key: `\\Software\\Classes\\${protocol}\\DefaultIcon` }) iconKey.set('', Registry.REG_SZ, icon, setCommand) } function setCommand (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) const commandKey = new Registry({ hive: Registry.HKCU, - key: '\\Software\\Classes\\' + protocol + '\\shell\\open\\command' + key: `\\Software\\Classes\\${protocol}\\shell\\open\\command` }) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done) } function done (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) } } @@ -163,43 +161,43 @@ function installWin32 () { function setExt () { const extKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER - key: '\\Software\\Classes\\' + ext + key: `\\Software\\Classes\\${ext}` }) extKey.set('', Registry.REG_SZ, id, setId) } function setId (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) const idKey = new Registry({ hive: Registry.HKCU, - key: '\\Software\\Classes\\' + id + key: `\\Software\\Classes\\${id}` }) idKey.set('', Registry.REG_SZ, name, setIcon) } function setIcon (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) const iconKey = new Registry({ hive: Registry.HKCU, - key: '\\Software\\Classes\\' + id + '\\DefaultIcon' + key: `\\Software\\Classes\\${id}\\DefaultIcon` }) iconKey.set('', Registry.REG_SZ, icon, setCommand) } function setCommand (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) const commandKey = new Registry({ hive: Registry.HKCU, - key: '\\Software\\Classes\\' + id + '\\shell\\open\\command' + key: `\\Software\\Classes\\${id}\\shell\\open\\command` }) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done) } function done (err) { - if (err) log.error(err.message) + if (err) return log.error(err.message) } } } @@ -217,9 +215,9 @@ function uninstallWin32 () { function getCommand () { const commandKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER - key: '\\Software\\Classes\\' + protocol + '\\shell\\open\\command' + key: `\\Software\\Classes\\${protocol}\\shell\\open\\command` }) - commandKey.get('', function (err, item) { + commandKey.get('', (err, item) => { if (!err && item.value.indexOf(commandToArgs(command)) >= 0) { destroyProtocol() } @@ -229,9 +227,9 @@ function uninstallWin32 () { function destroyProtocol () { const protocolKey = new Registry({ hive: Registry.HKCU, - key: '\\Software\\Classes\\' + protocol + key: `\\Software\\Classes\\${protocol}` }) - protocolKey.destroy(function () {}) + protocolKey.destroy(() => {}) } } @@ -241,7 +239,7 @@ function uninstallWin32 () { function eraseId () { const idKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER - key: '\\Software\\Classes\\' + id + key: `\\Software\\Classes\\${id}` }) idKey.destroy(getExt) } @@ -249,9 +247,9 @@ function uninstallWin32 () { function getExt () { const extKey = new Registry({ hive: Registry.HKCU, - key: '\\Software\\Classes\\' + ext + key: `\\Software\\Classes\\${ext}` }) - extKey.get('', function (err, item) { + extKey.get('', (err, item) => { if (!err && item.value === id) { destroyExt() } @@ -261,9 +259,9 @@ function uninstallWin32 () { function destroyExt () { const extKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER - key: '\\Software\\Classes\\' + ext + key: `\\Software\\Classes\\${ext}` }) - extKey.destroy(function () {}) + extKey.destroy(() => {}) } } } @@ -300,10 +298,11 @@ function installLinux () { ? path.dirname(process.execPath) : config.ROOT_PATH - desktopFile = desktopFile.replace(/\$APP_NAME/g, config.APP_NAME) - desktopFile = desktopFile.replace(/\$APP_PATH/g, appPath) - desktopFile = desktopFile.replace(/\$EXEC_PATH/g, EXEC_COMMAND.join(' ')) - desktopFile = desktopFile.replace(/\$TRY_EXEC_PATH/g, process.execPath) + desktopFile = desktopFile + .replace(/\$APP_NAME/g, config.APP_NAME) + .replace(/\$APP_PATH/g, appPath) + .replace(/\$EXEC_PATH/g, EXEC_COMMAND.join(' ')) + .replace(/\$TRY_EXEC_PATH/g, process.execPath) const desktopFilePath = path.join( os.homedir(), @@ -313,7 +312,7 @@ function installLinux () { 'webtorrent-desktop.desktop' ) fs.mkdirp(path.dirname(desktopFilePath)) - fs.writeFile(desktopFilePath, desktopFile, function (err) { + fs.writeFile(desktopFilePath, desktopFile, err => { if (err) return log.error(err.message) }) } @@ -335,9 +334,9 @@ function installLinux () { 'icons', 'webtorrent-desktop.png' ) - mkdirp(path.dirname(iconFilePath), (err) => { + mkdirp(path.dirname(iconFilePath), err => { if (err) return log.error(err.message) - fs.writeFile(iconFilePath, iconFile, (err) => { + fs.writeFile(iconFilePath, iconFile, err => { if (err) log.error(err.message) }) }) diff --git a/src/main/windows/main.js b/src/main/windows/main.js index 6898ebfd..f310ad70 100644 --- a/src/main/windows/main.js +++ b/src/main/windows/main.js @@ -57,7 +57,7 @@ function init (state, options) { win.setSheetOffset(config.UI_HEADER_HEIGHT) } - win.webContents.on('dom-ready', function () { + win.webContents.on('dom-ready', () => { menu.onToggleFullScreen(main.win.isFullScreen()) }) @@ -73,27 +73,27 @@ function init (state, options) { win.on('hide', onWindowBlur) win.on('show', onWindowFocus) - win.on('enter-full-screen', function () { + win.on('enter-full-screen', () => { menu.onToggleFullScreen(true) send('fullscreenChanged', true) win.setMenuBarVisibility(false) }) - win.on('leave-full-screen', function () { + win.on('leave-full-screen', () => { menu.onToggleFullScreen(false) send('fullscreenChanged', false) win.setMenuBarVisibility(true) }) - win.on('move', debounce(function (e) { + win.on('move', debounce(e => { send('windowBoundsChanged', e.sender.getBounds()) }, 1000)) - win.on('resize', debounce(function (e) { + win.on('resize', debounce(e => { send('windowBoundsChanged', e.sender.getBounds()) }, 1000)) - win.on('close', function (e) { + win.on('close', e => { if (process.platform !== 'darwin') { const tray = require('../tray') if (!tray.hasTray()) { @@ -143,23 +143,15 @@ function setBounds (bounds, maximize) { } // Maximize or minimize, if the second argument is present - let willBeMaximized - if (maximize === true) { - if (!main.win.isMaximized()) { - log('setBounds: maximizing') - main.win.maximize() - } - willBeMaximized = true - } else if (maximize === false) { - if (main.win.isMaximized()) { - log('setBounds: unmaximizing') - main.win.unmaximize() - } - willBeMaximized = false - } else { - willBeMaximized = main.win.isMaximized() + if (maximize === true && !main.win.isMaximized()) { + log('setBounds: maximizing') + main.win.maximize() + } else if (maximize === false && main.win.isMaximized()) { + log('setBounds: unmaximizing') + main.win.unmaximize() } + const willBeMaximized = typeof maximize === 'boolean' ? maximize : main.win.isMaximized() // Assuming we're not maximized or maximizing, set the window size if (!willBeMaximized) { log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`)