From ee8fe1e7ff9065ca1f9d8bdf5da97c3477e368a6 Mon Sep 17 00:00:00 2001 From: Michael George Attard Date: Mon, 30 Oct 2017 22:42:22 +0100 Subject: [PATCH 1/9] Cleaned up `external-player.js` --- src/main/external-player.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/external-player.js b/src/main/external-player.js index 39b80061..79c82393 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', @@ -40,17 +40,17 @@ function spawn (playerPath, url, title) { function kill () { if (!proc) return - log('Killing external player, pid ' + proc.pid) + log(`Killing external player, pid ${proc.pid}`) proc.kill('SIGKILL') // kill -9 proc = null } function spawnExternal (playerPath, args) { - log('Running external media player:', playerPath + ' ' + args.join(' ')) + log('Running external media player:', `${playerPath} ${args.join(' ')}`) 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'}) @@ -59,7 +59,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) @@ -71,7 +71,7 @@ function spawnExternal (playerPath, args) { proc = null }) - proc.on('error', function (e) { + proc.on('error', e => { log('External player error', e) }) } From bd6f2c2faf9c07dd9ffdd40215cb7f90b0f8441a Mon Sep 17 00:00:00 2001 From: Michael George Attard Date: Mon, 30 Oct 2017 22:46:33 +0100 Subject: [PATCH 2/9] Clean up of `main.js` --- src/main/windows/main.js | 41 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/windows/main.js b/src/main/windows/main.js index 104ac132..eb222f64 100644 --- a/src/main/windows/main.js +++ b/src/main/windows/main.js @@ -28,7 +28,10 @@ function init (state, options) { return main.win.show() } - const initialBounds = Object.assign(config.WINDOW_INITIAL_BOUNDS, state.saved.bounds) + const initialBounds = { + ...config.WINDOW_INITIAL_BOUNDS, + ...state.saved.bounds + } const win = main.win = new electron.BrowserWindow({ backgroundColor: '#282828', @@ -57,7 +60,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 +76,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()) { @@ -138,28 +141,20 @@ function setAspectRatio (aspectRatio) { function setBounds (bounds, maximize) { // Do nothing in fullscreen if (!main.win || main.win.isFullScreen()) { - log('setBounds: not setting bounds because we\'re in full screen') + log(`setBounds: not setting bounds because we're in full screen`) return } // 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)) From 962c563f2e6faeed66fb0afbcc1314b72239d43a Mon Sep 17 00:00:00 2001 From: Michael George Attard Date: Mon, 30 Oct 2017 22:49:34 +0100 Subject: [PATCH 3/9] Clean up `handlers.js` --- src/main/handlers.js | 93 ++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/src/main/handlers.js b/src/main/handlers.js index e3dff9a9..cc5d2820 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 } } @@ -42,9 +40,9 @@ function installDarwin () { // File handlers are defined in `Info.plist`. } -function uninstallDarwin () {} +function uninstallDarwin () { } -const EXEC_COMMAND = [ process.execPath ] +const EXEC_COMMAND = [process.execPath] if (!config.IS_PRODUCTION) { EXEC_COMMAND.push(config.ROOT_PATH) @@ -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) }) } From a30eedbec9eb2d9aeaf1def03fd9c7f99614e5c3 Mon Sep 17 00:00:00 2001 From: Borewit Date: Wed, 23 May 2018 21:00:55 +0200 Subject: [PATCH 4/9] Update music-metadata to 1.1.0, which I expected to be part of #1396. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4dcfebc..f43d270f 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": "^5.7.3", "prettier-bytes": "^1.0.1", From 4b51fb9255e4f2e436fb071d5822d4ee81df2327 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 25 May 2018 00:20:39 -0700 Subject: [PATCH 5/9] e -> err --- src/main/external-player.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/external-player.js b/src/main/external-player.js index 58e4925f..d378a623 100644 --- a/src/main/external-player.js +++ b/src/main/external-player.js @@ -70,7 +70,7 @@ function spawnExternal (playerPath, args) { proc = null }) - proc.on('error', e => { - log('External player error', e) + proc.on('error', err => { + log('External player error', err) }) } From 2c9b30572168488039c00ab2cfcb04083ca935a2 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 25 May 2018 00:28:14 -0700 Subject: [PATCH 6/9] style --- src/main/handlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/handlers.js b/src/main/handlers.js index dfef92c8..22bc65c6 100644 --- a/src/main/handlers.js +++ b/src/main/handlers.js @@ -229,7 +229,7 @@ function uninstallWin32 () { hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}` }) - protocolKey.destroy(() => { }) + protocolKey.destroy(() => {}) } } From 7251967ef520c0c31597bc81ba36b89e843bf605 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 25 May 2018 00:28:46 -0700 Subject: [PATCH 7/9] style --- src/main/handlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/handlers.js b/src/main/handlers.js index 22bc65c6..3c42e443 100644 --- a/src/main/handlers.js +++ b/src/main/handlers.js @@ -261,7 +261,7 @@ function uninstallWin32 () { hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${ext}` }) - extKey.destroy(() => { }) + extKey.destroy(() => {}) } } } From 6bf38611e8747c860bf74dc8f24ea0613a9ddd7f Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 25 May 2018 00:30:54 -0700 Subject: [PATCH 8/9] fix bug, function needs to be invoked --- src/main/windows/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/windows/main.js b/src/main/windows/main.js index c9a20333..f310ad70 100644 --- a/src/main/windows/main.js +++ b/src/main/windows/main.js @@ -151,7 +151,7 @@ function setBounds (bounds, maximize) { main.win.unmaximize() } - const willBeMaximized = typeof maximize === 'boolean' ? maximize : main.win.isMaximized + 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)}`) From fc51b230c4589a4a23f5e37118e8a4bda5e96e0f Mon Sep 17 00:00:00 2001 From: Michael George Attard Date: Sun, 27 May 2018 22:33:07 +0200 Subject: [PATCH 9/9] rename parameter --- src/main/external-player.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/external-player.js b/src/main/external-player.js index 58e4925f..d378a623 100644 --- a/src/main/external-player.js +++ b/src/main/external-player.js @@ -70,7 +70,7 @@ function spawnExternal (playerPath, args) { proc = null }) - proc.on('error', e => { - log('External player error', e) + proc.on('error', err => { + log('External player error', err) }) }