Comply naming with Airbnb guide

This commit is contained in:
Igor Gassmann 2018-01-08 00:46:22 -03:00
parent a212b8d908
commit 8b37ec6b72

View file

@ -1,13 +1,13 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
// Module imports // Module imports
import Path from 'path'; import path from 'path';
import Url from 'url'; import url from 'url';
import Jayson from 'jayson'; import Jayson from 'jayson';
import Semver from 'semver'; import SemVer from 'semver';
import Https from 'https'; import https from 'https';
import Keytar from 'keytar'; import keytar from 'keytar';
import ChildProcess from 'child_process'; import ChildProcess from 'child_process';
import Assert from 'assert'; import assert from 'assert';
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, Tray } from 'electron'; import { app, BrowserWindow, globalShortcut, ipcMain, Menu, Tray } from 'electron';
import mainMenu from './menu/mainMenu'; import mainMenu from './menu/mainMenu';
@ -18,9 +18,9 @@ export { contextMenu as Default } from './menu/contextMenu';
const isDevelopment = process.env.NODE_ENV === 'development'; const isDevelopment = process.env.NODE_ENV === 'development';
// Misc constants // Misc constants
const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest'; const latestReleaseAPIURL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
const DAEMON_PATH = process.env.LBRY_DAEMON || Path.join(__static, 'daemon/lbrynet-daemon'); const daemonPath = process.env.LBRY_DAEMON || path.join(__static, 'daemon/lbrynet-daemon');
const rendererUrl = isDevelopment const rendererURL = isDevelopment
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
: `file://${__dirname}/index.html`; : `file://${__dirname}/index.html`;
@ -47,7 +47,7 @@ let readyToQuit = false;
// If we receive a URI to open from an external app but there's no window to // If we receive a URI to open from an external app but there's no window to
// sendCredits it to, it's cached in this variable. // sendCredits it to, it's cached in this variable.
let openUri = null; let openURI = null;
// Set this to true to minimize on clicking close // Set this to true to minimize on clicking close
// false for normal action // false for normal action
@ -56,7 +56,7 @@ let minimize = true;
// Keep the tray also, it is getting GC'd if put in createTray() // Keep the tray also, it is getting GC'd if put in createTray()
let tray = null; let tray = null;
function processRequestedUri(uri) { function processRequestedURI(URI) {
// Windows normalizes URIs when they're passed in from other apps. On Windows, // Windows normalizes URIs when they're passed in from other apps. On Windows,
// this function tries to restore the original URI that was typed. // this function tries to restore the original URI that was typed.
// - If the URI has no path, Windows adds a trailing slash. LBRY URIs // - If the URI has no path, Windows adds a trailing slash. LBRY URIs
@ -67,9 +67,9 @@ function processRequestedUri(uri) {
// On Linux and Mac, we just return the URI as given. // On Linux and Mac, we just return the URI as given.
if (process.platform === 'win32') { if (process.platform === 'win32') {
return uri.replace(/\/$/, '').replace('/#', '#'); return URI.replace(/\/$/, '').replace('/#', '#');
} }
return uri; return URI;
} }
/* /*
@ -163,11 +163,11 @@ function createWindow() {
if (isDevelopment) { if (isDevelopment) {
window.webContents.openDevTools(); window.webContents.openDevTools();
} }
window.loadURL(rendererUrl); window.loadURL(rendererURL);
if (openUri) { if (openURI) {
// We stored and received a URI that an external app requested before we had a window object // We stored and received a URI that an external app requested before we had a window object
window.webContents.on('did-finish-load', () => { window.webContents.on('did-finish-load', () => {
window.webContents.send('open-uri-requested', openUri); window.webContents.send('open-uri-requested', openURI);
}); });
} }
@ -224,9 +224,9 @@ function createTray() {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
// Using @2x for mac retina screens so the icon isn't blurry // Using @2x for mac retina screens so the icon isn't blurry
// file name needs to include "Template" at the end for dark menu bar // file name needs to include "Template" at the end for dark menu bar
iconPath = Path.join(__static, '/img/fav/macTemplate@2x.png'); iconPath = path.join(__static, '/img/fav/macTemplate@2x.png');
} else { } else {
iconPath = Path.join(__static, '/img/fav/32x32.png'); iconPath = path.join(__static, '/img/fav/32x32.png');
} }
tray = new Tray(iconPath); tray = new Tray(iconPath);
@ -237,10 +237,10 @@ function createTray() {
}); });
} }
function handleOpenUriRequested(uri) { function handleOpenURIRequested(URI) {
if (!rendererWindow) { if (!rendererWindow) {
// Window not created yet, so store up requested URI for when it is // Window not created yet, so store up requested URI for when it is
openUri = processRequestedUri(uri); openURI = processRequestedURI(URI);
} else { } else {
if (rendererWindow.isMinimized()) { if (rendererWindow.isMinimized()) {
rendererWindow.restore(); rendererWindow.restore();
@ -249,7 +249,7 @@ function handleOpenUriRequested(uri) {
} }
rendererWindow.focus(); rendererWindow.focus();
rendererWindow.webContents.send('open-uri-requested', processRequestedUri(uri)); rendererWindow.webContents.send('open-uri-requested', processRequestedURI(URI));
} }
} }
@ -283,10 +283,10 @@ function handleDaemonSubprocessExited() {
} }
function launchDaemon() { function launchDaemon() {
Assert(!daemonSubprocess, 'Tried to launch daemon twice'); assert(!daemonSubprocess, 'Tried to launch daemon twice');
console.log('Launching daemon:', DAEMON_PATH); console.log('Launching daemon:', daemonPath);
daemonSubprocess = ChildProcess.spawn(DAEMON_PATH); daemonSubprocess = ChildProcess.spawn(daemonPath);
// Need to handle the data event instead of attaching to // Need to handle the data event instead of attaching to
// process.stdout because the latter doesn't work. I believe on // process.stdout because the latter doesn't work. I believe on
// windows it buffers stdout and we don't get any meaningful output // windows it buffers stdout and we don't get any meaningful output
@ -301,7 +301,7 @@ function launchDaemon() {
const isSecondaryInstance = app.makeSingleInstance(argv => { const isSecondaryInstance = app.makeSingleInstance(argv => {
if (argv.length >= 2) { if (argv.length >= 2) {
handleOpenUriRequested(argv[1]); // This will handle restoring and focusing the window handleOpenURIRequested(argv[1]); // This will handle restoring and focusing the window
} else if (rendererWindow) { } else if (rendererWindow) {
if (rendererWindow.isMinimized()) { if (rendererWindow.isMinimized()) {
rendererWindow.restore(); rendererWindow.restore();
@ -444,11 +444,11 @@ app.on('activate', () => {
}); });
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
app.on('open-url', (event, uri) => { app.on('open-url', (event, URI) => {
handleOpenUriRequested(uri); handleOpenURIRequested(URI);
}); });
} else if (process.argv.length >= 2) { } else if (process.argv.length >= 2) {
handleOpenUriRequested(process.argv[1]); handleOpenURIRequested(process.argv[1]);
} }
ipcMain.on('upgrade', (event, installerPath) => { ipcMain.on('upgrade', (event, installerPath) => {
@ -486,7 +486,7 @@ ipcMain.on('version-info-requested', () => {
}, },
}; };
const req = Https.get(Object.assign(opts, Url.parse(LATEST_RELEASE_API_URL)), res => { const req = https.get(Object.assign(opts, url.parse(latestReleaseAPIURL)), res => {
res.on('data', data => { res.on('data', data => {
result += data; result += data;
}); });
@ -498,7 +498,7 @@ ipcMain.on('version-info-requested', () => {
rendererWindow.webContents.send('version-info-received', null); rendererWindow.webContents.send('version-info-received', null);
} }
} else { } else {
const upgradeAvailable = Semver.gt(formatRc(remoteVersion), formatRc(localVersion)); const upgradeAvailable = SemVer.gt(formatRc(remoteVersion), formatRc(localVersion));
if (rendererWindow) { if (rendererWindow) {
rendererWindow.webContents.send('version-info-received', { rendererWindow.webContents.send('version-info-received', {
remoteVersion, remoteVersion,
@ -519,11 +519,11 @@ ipcMain.on('version-info-requested', () => {
}); });
ipcMain.on('get-auth-token', event => { ipcMain.on('get-auth-token', event => {
Keytar.getPassword('LBRY', 'auth_token').then(token => { keytar.getPassword('LBRY', 'auth_token').then(token => {
event.sender.send('auth-token-response', token ? token.toString().trim() : null); event.sender.send('auth-token-response', token ? token.toString().trim() : null);
}); });
}); });
ipcMain.on('set-auth-token', (event, token) => { ipcMain.on('set-auth-token', (event, token) => {
Keytar.setPassword('LBRY', 'auth_token', token ? token.toString().trim() : null); keytar.setPassword('LBRY', 'auth_token', token ? token.toString().trim() : null);
}); });