Merge pull request #1406 from Borewit/code-style/merge

Code style/merge
This commit is contained in:
Diego Rodríguez Baquero
2018-06-03 18:46:26 -05:00
committed by GitHub
4 changed files with 65 additions and 74 deletions

View File

@@ -32,7 +32,7 @@
"location-history": "^1.0.0", "location-history": "^1.0.0",
"material-ui": "^0.17.0", "material-ui": "^0.17.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"music-metadata": "^1.0.0", "music-metadata": "^1.1.0",
"network-address": "^1.1.0", "network-address": "^1.1.0",
"parse-torrent": "^6.0.1", "parse-torrent": "^6.0.1",
"prettier-bytes": "^1.0.1", "prettier-bytes": "^1.0.1",

View File

@@ -25,7 +25,7 @@ function spawn (playerPath, url, title) {
if (playerPath != null) return spawnExternal(playerPath, [url]) if (playerPath != null) return spawnExternal(playerPath, [url])
// Try to find and use VLC if external player is not specified // 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') if (err) return windows.main.dispatch('externalPlayerNotFound')
const args = [ const args = [
'--play-and-exit', '--play-and-exit',
@@ -49,7 +49,7 @@ function spawnExternal (playerPath, args) {
if (process.platform === 'darwin' && path.extname(playerPath) === '.app') { if (process.platform === 'darwin' && path.extname(playerPath) === '.app') {
// Mac: Use executable in packaged .app bundle // 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'}) proc = cp.spawn(playerPath, args, {stdio: 'ignore'})
@@ -58,7 +58,7 @@ function spawnExternal (playerPath, args) {
const closeModalTimeout = setTimeout(() => const closeModalTimeout = setTimeout(() =>
windows.main.dispatch('exitModal'), 1000) windows.main.dispatch('exitModal'), 1000)
proc.on('close', function (code) { proc.on('close', code => {
clearTimeout(closeModalTimeout) clearTimeout(closeModalTimeout)
if (!proc) return // Killed if (!proc) return // Killed
log('External player exited with code ', code) log('External player exited with code ', code)
@@ -70,7 +70,7 @@ function spawnExternal (playerPath, args) {
proc = null proc = null
}) })
proc.on('error', function (e) { proc.on('error', err => {
log('External player error', e) log('External player error', err)
}) })
} }

View File

@@ -7,26 +7,24 @@ const config = require('../config')
const path = require('path') const path = require('path')
function install () { function install () {
if (process.platform === 'darwin') { switch (process.platform) {
installDarwin() case 'darwin': installDarwin()
} break
if (process.platform === 'win32') { case 'win32': installWin32()
installWin32() break
} case 'linux': installLinux()
if (process.platform === 'linux') { break
installLinux()
} }
} }
function uninstall () { function uninstall () {
if (process.platform === 'darwin') { switch (process.platform) {
uninstallDarwin() case 'darwin': uninstallDarwin()
} break
if (process.platform === 'win32') { case 'win32': uninstallWin32()
uninstallWin32() break
} case 'linux': uninstallLinux()
if (process.platform === 'linux') { break
uninstallLinux()
} }
} }
@@ -108,37 +106,37 @@ function installWin32 () {
setProtocol() setProtocol()
function setProtocol (err) { function setProtocol (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
protocolKey.set('', Registry.REG_SZ, name, setURLProtocol) protocolKey.set('', Registry.REG_SZ, name, setURLProtocol)
} }
function setURLProtocol (err) { function setURLProtocol (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
protocolKey.set('URL Protocol', Registry.REG_SZ, '', setIcon) protocolKey.set('URL Protocol', Registry.REG_SZ, '', setIcon)
} }
function setIcon (err) { function setIcon (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
const iconKey = new Registry({ const iconKey = new Registry({
hive: Registry.HKCU, hive: Registry.HKCU,
key: '\\Software\\Classes\\' + protocol + '\\DefaultIcon' key: `\\Software\\Classes\\${protocol}\\DefaultIcon`
}) })
iconKey.set('', Registry.REG_SZ, icon, setCommand) iconKey.set('', Registry.REG_SZ, icon, setCommand)
} }
function setCommand (err) { function setCommand (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
const commandKey = new Registry({ const commandKey = new Registry({
hive: Registry.HKCU, 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) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done)
} }
function done (err) { function done (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
} }
} }
@@ -163,43 +161,43 @@ function installWin32 () {
function setExt () { function setExt () {
const extKey = new Registry({ const extKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER hive: Registry.HKCU, // HKEY_CURRENT_USER
key: '\\Software\\Classes\\' + ext key: `\\Software\\Classes\\${ext}`
}) })
extKey.set('', Registry.REG_SZ, id, setId) extKey.set('', Registry.REG_SZ, id, setId)
} }
function setId (err) { function setId (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
const idKey = new Registry({ const idKey = new Registry({
hive: Registry.HKCU, hive: Registry.HKCU,
key: '\\Software\\Classes\\' + id key: `\\Software\\Classes\\${id}`
}) })
idKey.set('', Registry.REG_SZ, name, setIcon) idKey.set('', Registry.REG_SZ, name, setIcon)
} }
function setIcon (err) { function setIcon (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
const iconKey = new Registry({ const iconKey = new Registry({
hive: Registry.HKCU, hive: Registry.HKCU,
key: '\\Software\\Classes\\' + id + '\\DefaultIcon' key: `\\Software\\Classes\\${id}\\DefaultIcon`
}) })
iconKey.set('', Registry.REG_SZ, icon, setCommand) iconKey.set('', Registry.REG_SZ, icon, setCommand)
} }
function setCommand (err) { function setCommand (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
const commandKey = new Registry({ const commandKey = new Registry({
hive: Registry.HKCU, 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) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done)
} }
function done (err) { function done (err) {
if (err) log.error(err.message) if (err) return log.error(err.message)
} }
} }
} }
@@ -217,9 +215,9 @@ function uninstallWin32 () {
function getCommand () { function getCommand () {
const commandKey = new Registry({ const commandKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER 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) { if (!err && item.value.indexOf(commandToArgs(command)) >= 0) {
destroyProtocol() destroyProtocol()
} }
@@ -229,9 +227,9 @@ function uninstallWin32 () {
function destroyProtocol () { function destroyProtocol () {
const protocolKey = new Registry({ const protocolKey = new Registry({
hive: Registry.HKCU, hive: Registry.HKCU,
key: '\\Software\\Classes\\' + protocol key: `\\Software\\Classes\\${protocol}`
}) })
protocolKey.destroy(function () {}) protocolKey.destroy(() => {})
} }
} }
@@ -241,7 +239,7 @@ function uninstallWin32 () {
function eraseId () { function eraseId () {
const idKey = new Registry({ const idKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER hive: Registry.HKCU, // HKEY_CURRENT_USER
key: '\\Software\\Classes\\' + id key: `\\Software\\Classes\\${id}`
}) })
idKey.destroy(getExt) idKey.destroy(getExt)
} }
@@ -249,9 +247,9 @@ function uninstallWin32 () {
function getExt () { function getExt () {
const extKey = new Registry({ const extKey = new Registry({
hive: Registry.HKCU, 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) { if (!err && item.value === id) {
destroyExt() destroyExt()
} }
@@ -261,9 +259,9 @@ function uninstallWin32 () {
function destroyExt () { function destroyExt () {
const extKey = new Registry({ const extKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER 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) ? path.dirname(process.execPath)
: config.ROOT_PATH : config.ROOT_PATH
desktopFile = desktopFile.replace(/\$APP_NAME/g, config.APP_NAME) desktopFile = desktopFile
desktopFile = desktopFile.replace(/\$APP_PATH/g, appPath) .replace(/\$APP_NAME/g, config.APP_NAME)
desktopFile = desktopFile.replace(/\$EXEC_PATH/g, EXEC_COMMAND.join(' ')) .replace(/\$APP_PATH/g, appPath)
desktopFile = desktopFile.replace(/\$TRY_EXEC_PATH/g, process.execPath) .replace(/\$EXEC_PATH/g, EXEC_COMMAND.join(' '))
.replace(/\$TRY_EXEC_PATH/g, process.execPath)
const desktopFilePath = path.join( const desktopFilePath = path.join(
os.homedir(), os.homedir(),
@@ -313,7 +312,7 @@ function installLinux () {
'webtorrent-desktop.desktop' 'webtorrent-desktop.desktop'
) )
fs.mkdirp(path.dirname(desktopFilePath)) fs.mkdirp(path.dirname(desktopFilePath))
fs.writeFile(desktopFilePath, desktopFile, function (err) { fs.writeFile(desktopFilePath, desktopFile, err => {
if (err) return log.error(err.message) if (err) return log.error(err.message)
}) })
} }
@@ -335,9 +334,9 @@ function installLinux () {
'icons', 'icons',
'webtorrent-desktop.png' 'webtorrent-desktop.png'
) )
mkdirp(path.dirname(iconFilePath), (err) => { mkdirp(path.dirname(iconFilePath), err => {
if (err) return log.error(err.message) if (err) return log.error(err.message)
fs.writeFile(iconFilePath, iconFile, (err) => { fs.writeFile(iconFilePath, iconFile, err => {
if (err) log.error(err.message) if (err) log.error(err.message)
}) })
}) })

View File

@@ -57,7 +57,7 @@ function init (state, options) {
win.setSheetOffset(config.UI_HEADER_HEIGHT) win.setSheetOffset(config.UI_HEADER_HEIGHT)
} }
win.webContents.on('dom-ready', function () { win.webContents.on('dom-ready', () => {
menu.onToggleFullScreen(main.win.isFullScreen()) menu.onToggleFullScreen(main.win.isFullScreen())
}) })
@@ -73,27 +73,27 @@ function init (state, options) {
win.on('hide', onWindowBlur) win.on('hide', onWindowBlur)
win.on('show', onWindowFocus) win.on('show', onWindowFocus)
win.on('enter-full-screen', function () { win.on('enter-full-screen', () => {
menu.onToggleFullScreen(true) menu.onToggleFullScreen(true)
send('fullscreenChanged', true) send('fullscreenChanged', true)
win.setMenuBarVisibility(false) win.setMenuBarVisibility(false)
}) })
win.on('leave-full-screen', function () { win.on('leave-full-screen', () => {
menu.onToggleFullScreen(false) menu.onToggleFullScreen(false)
send('fullscreenChanged', false) send('fullscreenChanged', false)
win.setMenuBarVisibility(true) win.setMenuBarVisibility(true)
}) })
win.on('move', debounce(function (e) { win.on('move', debounce(e => {
send('windowBoundsChanged', e.sender.getBounds()) send('windowBoundsChanged', e.sender.getBounds())
}, 1000)) }, 1000))
win.on('resize', debounce(function (e) { win.on('resize', debounce(e => {
send('windowBoundsChanged', e.sender.getBounds()) send('windowBoundsChanged', e.sender.getBounds())
}, 1000)) }, 1000))
win.on('close', function (e) { win.on('close', e => {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
const tray = require('../tray') const tray = require('../tray')
if (!tray.hasTray()) { if (!tray.hasTray()) {
@@ -143,23 +143,15 @@ function setBounds (bounds, maximize) {
} }
// Maximize or minimize, if the second argument is present // Maximize or minimize, if the second argument is present
let willBeMaximized if (maximize === true && !main.win.isMaximized()) {
if (maximize === true) {
if (!main.win.isMaximized()) {
log('setBounds: maximizing') log('setBounds: maximizing')
main.win.maximize() main.win.maximize()
} } else if (maximize === false && main.win.isMaximized()) {
willBeMaximized = true
} else if (maximize === false) {
if (main.win.isMaximized()) {
log('setBounds: unmaximizing') log('setBounds: unmaximizing')
main.win.unmaximize() main.win.unmaximize()
} }
willBeMaximized = false
} else {
willBeMaximized = main.win.isMaximized()
}
const willBeMaximized = typeof maximize === 'boolean' ? maximize : main.win.isMaximized()
// Assuming we're not maximized or maximizing, set the window size // Assuming we're not maximized or maximizing, set the window size
if (!willBeMaximized) { if (!willBeMaximized) {
log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`) log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`)