Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Electron linting errors #929

Merged
merged 14 commits into from
Jan 15, 2018
Merged
25 changes: 2 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
/node_modules
/LBRY-darwin-x64
/dist

/src/main/dist
/src/main/locales
/src/main/node_modules
/src/renderer/dist
/build/venv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe build/venv is still used (by build.sh)

/build/daemon.ver
/lbry-app-venv
/lbry-app
/lbry-venv
/build/venv
*.pyc
/static/daemon/lbrynet*
/static/locales
/daemon/build
/daemon/venv
/daemon/requirements.txt
/.idea

*.pyc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to be here while upload_assets.py is still in use. if you want to rewrite that in JS instead, then we can drop python dependency completely, which would be sweet!

*.iml
.#*

build/daemon.zip
.vimrc

package-lock.json

.DS_Store
35 changes: 2 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ development and testing purposes.
* [Git](https://git-scm.com/downloads)
* [Node.js](https://nodejs.org/en/download/)
* [Yarn](https://yarnpkg.com/en/docs/install)
* `yarn --add-python-to-path install --global --production windows-build-tools` (Windows only)

### One-time Setup

Expand Down Expand Up @@ -61,40 +60,10 @@ The app can be run from the sources using the following command:

### On Windows

#### Windows Dependency

1. Download and install `git` from <a href="https://git-for-windows.github.io/">github.io<a>
(configure to use command prompt integration)
2. Download and install `npm` and `node` from
<a href="https://nodejs.org/en/download/current/">nodejs.org<a>
3. Download and install `python 2.7` from
<a href="https://www.python.org/downloads/windows/">python.org</a>
4. Download and Install `Microsoft Visual C++ Compiler for Python 2.7` from
<a href="https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266">Microsoft<a>
5. Download and install `.NET Framework 2.0 Software Development Kit (SDK) (x64)` from
<a href="https://www.microsoft.com/en-gb/download/details.aspx?id=15354">Microsoft<a> (may need
to extract setup.exe and install manually by running install.exe as Administrator)

#### One-time Setup

1. Open a command prompt as administrator and run the following:

```
npm install --global --production windows-build-tools
exit
```

2. Open a command prompt in the root of the project and run the following:

```
python -m pip install -r build\requirements.txt
npm install -g yarn
yarn install
yarn build
```

3. Download the lbry daemon and CLI [binaries](https://github.com/lbryio/lbry/releases) and place
them in `static\daemon`.
Download the lbry daemon and CLI [binaries](https://github.com/lbryio/lbry/releases) and place them
in `static\daemon`.

### Build

Expand Down
8 changes: 6 additions & 2 deletions build/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ set -eu
if $LINUX; then
INSTALL="$SUDO apt-get install --no-install-recommends -y"
$INSTALL build-essential libssl-dev libffi-dev libgmp3-dev python2.7-dev libsecret-1-dev curl
elif $OSX && ! cmd_exists brew ; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
elif $OSX; then
if ! cmd_exists brew; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
brew update
fi
fi


Expand Down
1 change: 1 addition & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"appId": "io.lbry.LBRY",
"productName": "LBRY",
"mac": {
"category": "public.app-category.entertainment"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"install": "^0.10.2",
"jayson": "^2.0.2",
"jshashes": "^1.0.7",
"keytar": "^4.0.3",
"keytar-prebuild": "^4.0.4",
"localforage": "^1.5.0",
"npm": "^5.5.1",
"qrcode.react": "^0.7.2",
Expand Down
92 changes: 59 additions & 33 deletions src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable no-console */
// Module imports
import Path from 'path';
import Url from 'url';
import path from 'path';
import url from 'url';
import Jayson from 'jayson';
import Semver from 'semver';
import Https from 'https';
import Keytar from 'keytar';
import SemVer from 'semver';
import https from 'https';
import keytar from 'keytar-prebuild';
import ChildProcess from 'child_process';
import Assert from 'assert';
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, Tray } from 'electron';
import assert from 'assert';
import { app, BrowserWindow, globalShortcut, ipcMain, Menu, Tray, dialog } from 'electron';
import mainMenu from './menu/mainMenu';
import contextMenu from './menu/contextMenu';

Expand All @@ -18,9 +18,9 @@ const localVersion = app.getVersion();
const isDevelopment = process.env.NODE_ENV === 'development';

// Misc constants
const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
const DAEMON_PATH = process.env.LBRY_DAEMON || Path.join(__static, 'daemon/lbrynet-daemon');
const rendererUrl = isDevelopment
const latestReleaseAPIURL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
const daemonPath = process.env.LBRY_DAEMON || path.join(__static, 'daemon/lbrynet-daemon');
const rendererURL = isDevelopment
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
: `file://${__dirname}/index.html`;

Expand All @@ -47,7 +47,7 @@ let readyToQuit = false;

// 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.
let openUri = null;
let openURI = null;

// Set this to true to minimize on clicking close
// false for normal action
Expand All @@ -56,7 +56,7 @@ let minimize = true;
// Keep the tray also, it is getting GC'd if put in createTray()
let tray = null;

function processRequestedUri(uri) {
function processRequestedURI(URI) {
// Windows normalizes URIs when they're passed in from other apps. On Windows,
// this function tries to restore the original URI that was typed.
// - If the URI has no path, Windows adds a trailing slash. LBRY URIs
Expand All @@ -67,9 +67,9 @@ function processRequestedUri(uri) {
// On Linux and Mac, we just return the URI as given.

if (process.platform === 'win32') {
return uri.replace(/\/$/, '').replace('/#', '#');
return URI.replace(/\/$/, '').replace('/#', '#');
}
return uri;
return URI;
}

/*
Expand Down Expand Up @@ -162,14 +162,18 @@ function createWindow() {
if (isDevelopment) {
window.webContents.openDevTools();
}
window.loadURL(rendererUrl);
if (openUri) {
window.loadURL(rendererURL);
if (openURI) {
// 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.send('open-uri-requested', openUri, true);
window.webContents.send('open-uri-requested', openURI, true);
});
}

window.webContents.on('crashed', () => {
safeQuit();
});

window.removeAllListeners();

window.on('close', event => {
Expand Down Expand Up @@ -211,6 +215,23 @@ function createWindow() {
window.webContents.send('window-is-focused', null);
});

window.on('unresponsive', () => {
dialog.showMessageBox(
window,
{
type: 'warning',
buttons: ['Wait', 'Quit'],
title: 'LBRY Unresponsive',
defaultId: 1,
message: 'LBRY is not responding. Would you like to quit?',
cancelId: 0,
},
buttonIndex => {
if (buttonIndex === 1) safeQuit();
}
);
});

mainMenu();

return window;
Expand All @@ -223,9 +244,9 @@ function createTray() {
if (process.platform === 'darwin') {
// 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
iconPath = Path.join(__static, '/img/fav/macTemplate@2x.png');
iconPath = path.join(__static, '/img/fav/macTemplate@2x.png');
} else {
iconPath = Path.join(__static, '/img/fav/32x32.png');
iconPath = path.join(__static, '/img/fav/32x32.png');
}

tray = new Tray(iconPath);
Expand All @@ -236,10 +257,10 @@ function createTray() {
});
}

function handleOpenUriRequested(uri) {
function handleOpenURIRequested(URI) {
if (!rendererWindow) {
// Window not created yet, so store up requested URI for when it is
openUri = processRequestedUri(uri);
openURI = processRequestedURI(URI);
} else {
if (rendererWindow.isMinimized()) {
rendererWindow.restore();
Expand All @@ -248,7 +269,7 @@ function handleOpenUriRequested(uri) {
}

rendererWindow.focus();
rendererWindow.webContents.send('open-uri-requested', processRequestedUri(uri));
rendererWindow.webContents.send('open-uri-requested', processRequestedURI(URI));
}
}

Expand Down Expand Up @@ -282,10 +303,10 @@ function handleDaemonSubprocessExited() {
}

function launchDaemon() {
Assert(!daemonSubprocess, 'Tried to launch daemon twice');
assert(!daemonSubprocess, 'Tried to launch daemon twice');

console.log('Launching daemon:', DAEMON_PATH);
daemonSubprocess = ChildProcess.spawn(DAEMON_PATH);
console.log('Launching daemon:', daemonPath);
daemonSubprocess = ChildProcess.spawn(daemonPath);
// Need to handle the data event instead of attaching to
// process.stdout because the latter doesn't work. I believe on
// windows it buffers stdout and we don't get any meaningful output
Expand All @@ -300,7 +321,7 @@ function launchDaemon() {

const isSecondaryInstance = app.makeSingleInstance(argv => {
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) {
if (rendererWindow.isMinimized()) {
rendererWindow.restore();
Expand Down Expand Up @@ -443,11 +464,11 @@ app.on('activate', () => {
});

if (process.platform === 'darwin') {
app.on('open-url', (event, uri) => {
handleOpenUriRequested(uri);
app.on('open-url', (event, URI) => {
handleOpenURIRequested(URI);
});
} else if (process.argv.length >= 2) {
handleOpenUriRequested(process.argv[1]);
handleOpenURIRequested(process.argv[1]);
}

ipcMain.on('upgrade', (event, installerPath) => {
Expand Down Expand Up @@ -485,7 +506,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 => {
result += data;
});
Expand All @@ -497,7 +518,7 @@ ipcMain.on('version-info-requested', () => {
rendererWindow.webContents.send('version-info-received', null);
}
} else {
const upgradeAvailable = Semver.gt(formatRc(remoteVersion), formatRc(localVersion));
const upgradeAvailable = SemVer.gt(formatRc(remoteVersion), formatRc(localVersion));
if (rendererWindow) {
rendererWindow.webContents.send('version-info-received', {
remoteVersion,
Expand All @@ -518,13 +539,18 @@ ipcMain.on('version-info-requested', () => {
});

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);
});
});

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);
});

process.on('uncaughtException', error => {
console.error(error);
safeQuit();
});

export { contextMenu };
37 changes: 15 additions & 22 deletions src/renderer/component/video/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import React from "react";
import { connect } from "react-redux";
import { doChangeVolume } from "redux/actions/app";
import { selectVolume } from "redux/selectors/app";
import { doPlayUri, doSetPlayingUri } from "redux/actions/content";
import { doPlay, doPause, savePosition } from "redux/actions/media";
import {
makeSelectMetadataForUri,
makeSelectContentTypeForUri,
} from "redux/selectors/claims";
import React from 'react';
import { connect } from 'react-redux';
import { doChangeVolume } from 'redux/actions/app';
import { selectVolume } from 'redux/selectors/app';
import { doPlayUri, doSetPlayingUri } from 'redux/actions/content';
import { doPlay, doPause, savePosition } from 'redux/actions/media';
import { makeSelectMetadataForUri, makeSelectContentTypeForUri } from 'redux/selectors/claims';
import {
makeSelectFileInfoForUri,
makeSelectLoadingForUri,
makeSelectDownloadingForUri,
} from "redux/selectors/file_info";
import { makeSelectCostInfoForUri } from "redux/selectors/cost_info";
import { selectShowNsfw } from "redux/selectors/settings";
import {
selectMediaPaused,
makeSelectMediaPositionForUri,
} from "redux/selectors/media";
import Video from "./view";
import { selectPlayingUri } from "redux/selectors/content";
import { makeSelectClaimForUri } from "redux/selectors/claims";
} from 'redux/selectors/file_info';
import { makeSelectCostInfoForUri } from 'redux/selectors/cost_info';
import { selectShowNsfw } from 'redux/selectors/settings';
import { selectMediaPaused, makeSelectMediaPositionForUri } from 'redux/selectors/media';
import Video from './view';
import { selectPlayingUri } from 'redux/selectors/content';
import { makeSelectClaimForUri } from 'redux/selectors/claims';

const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
Expand All @@ -44,8 +38,7 @@ const perform = dispatch => ({
changeVolume: volume => dispatch(doChangeVolume(volume)),
doPlay: () => dispatch(doPlay()),
doPause: () => dispatch(doPause()),
savePosition: (claimId, position) =>
dispatch(savePosition(claimId, position)),
savePosition: (claimId, position) => dispatch(savePosition(claimId, position)),
});

export default connect(select, perform)(Video);
Loading