Merge pull request #824 from lbryio/restructuring

Support Hot Module Replacement
This commit is contained in:
Sean Yesmunt 2017-12-08 14:05:59 -05:00 committed by GitHub
commit 204fd60f95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
339 changed files with 7799 additions and 10265 deletions

View file

@ -16,11 +16,7 @@ values =
rc
production
[bumpversion:file:src/main/package.json]
search = "version": "{current_version}"
replace = "version": "{new_version}"
[bumpversion:file:src/renderer/package.json]
[bumpversion:file:package.json]
search = "version": "{current_version}"
replace = "version": "{new_version}"

20
.flowconfig Normal file
View file

@ -0,0 +1,20 @@
[ignore]
.*/node_modules/**
[include]
[libs]
flow-typed
[lints]
[options]
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
module.name_mapper='^constants\(.*\)$' -> '<PROJECT_ROOT>/src/renderer/constants\1'
module.name_mapper='^util\(.*\)$' -> '<PROJECT_ROOT>/src/renderer/util\1'
module.name_mapper='^redux\(.*\)$' -> '<PROJECT_ROOT>/src/renderer/redux\1'
module.name_mapper='^types\(.*\)$' -> '<PROJECT_ROOT>/src/renderer/types\1'
module.name_mapper='^component\(.*\)$' -> '<PROJECT_ROOT>/src/renderer/component\1'
[strict]

8
.gitignore vendored
View file

@ -2,13 +2,6 @@
/LBRY-darwin-x64
/dist
/src/renderer/dist/css/*
/src/renderer/dist/js/*
!/src/renderer/dist/js/mediaelement
/src/renderer/node_modules
/src/renderer/.sass-cache
/src/main/dist
/src/main/locales
/src/main/node_modules
@ -17,6 +10,7 @@
/lbry-app-venv
/lbry-app
/lbry-venv
/static/daemon/lbrynet*
/daemon/build
/daemon/venv
/daemon/requirements.txt

View file

@ -2,7 +2,7 @@
host = https://www.transifex.com
[lbry-app.app-strings]
file_filter = src/main/dist/locales/<lang>.json
source_file = src/main/dist/locales/en.json
file_filter = dist/locales/<lang>.json
source_file = dist/locales/en.json
source_lang = en
type = KEYVALUEJSON

View file

@ -27,22 +27,17 @@ To install from source or make changes to the application, continue reading belo
This will download and install the LBRY app and its dependencies, including [the LBRY daemon](https://github.com/lbryio/lbry) and command line utilities like `node` and `yarn`. The LBRY app requires Node >= 6; if you have an earlier version of Node installed and want to keep it, you can use [nvm](https://github.com/creationix/nvm) to switch back and forth.
### Running
Run `./node_modules/.bin/electron src/main`
### Ongoing Development
1. `cd src/renderer`
2. `./watch.sh`
Run `yarn dev`
This will set up a monitor that will automatically compile any changes to JS or CSS folders inside of the `src/renderer` folder. This allows you to make changes and see them immediately by reloading the app.
This will set up a server that will automatically compile any changes made inside `src\` folder and automatically reload the app without losing the state.
### Packaging
We use [electron-builder](https://github.com/electron-userland/electron-builder)
to create distributable packages, which is run by calling:
Run `yarn dist`
`node_modules/.bin/build -p never`
We use [electron-builder](https://github.com/electron-userland/electron-builder)
to create distributable packages.
## Development on Windows
@ -65,38 +60,18 @@ exit
python -m pip install -r build\requirements.txt
npm install -g yarn
yarn install
yarn dist
```
3. Change directory to `src\main` and run the following:
```
yarn install
node_modules\.bin\electron-rebuild
node_modules\.bin\electron-rebuild
cd ..\..
```
4. Change directory to `src\renderer` and run the following:
```
yarn install
npm rebuild node-sass
node node_modules\node-sass\bin\node-sass --output dist\css --sourcemap=none scss\
node_modules\.bin\webpack --config webpack.dev.config.js
xcopy /E dist ..\main\dist
cd ..\..
```
4. Download the lbry daemon and cli [binaries](https://github.com/lbryio/lbry/releases) and place them in `src\main\dist\`
3. Download the lbry daemon and cli [binaries](https://github.com/lbryio/lbry/releases) and place them in `dist\`
### Building lbry-app
1. run `node_modules\.bin\build -p never` from the root of the project.
### Running the electron app
1. Run `node_modules\.bin\electron src\main`
Run `yarn dist`
### Ongoing Development
1. `cd src\renderer`
2. `watch.bat`
Run `yarn dev`
This will set up a monitor that will automatically compile any changes to JS or CSS folders inside of the `src\renderer` folder. This allows you to make changes and see them immediately by reloading the app.
This will set up a server that will automatically compile any changes made inside `src\` folder and automatically reload the app without losing the state.
## Internationalization
If you want to help translating the lbry-app, you can copy the en.json file in /src/main/locales and modify the values while leaving the keys as their original English strings. An example for this would be: `"Skip": "Überspringen",` Translations should automatically show up in options.
If you want to help translating the lbry-app, you can copy the `en.json` file in `/dist/locales/` and modify the values while leaving the keys as their original English strings. An example for this would be: `"Skip": "Überspringen",` Translations should automatically show up in options.

View file

@ -5,41 +5,26 @@ Install-Product node $env:nodejs_version
npm install -g yarn
yarn install
# do app
cd src\main
yarn install
# necessary to ensure native Node modules (e.g. keytar) are built against the correct version of Node)
# yes, it needs to be run twice. it fails the first time, not sure why
node_modules\.bin\electron-rebuild
node_modules\.bin\electron-rebuild
cd ..\..
# build ui
cd src\renderer
yarn install
npm rebuild node-sass
node_modules\.bin\node-sass --output dist\css --sourcemap=none scss\
node_modules\.bin\webpack --config webpack.prod.js
Copy-Item dist ..\main\ -recurse
cd ..\..
# clean dist\
if (Test-Path -Path dist\) {
Remove-Item -Recurse -Force dist\
}
New-Item -ItemType directory -Path dist\
# get daemon and cli executable
$package_settings = (Get-Content src\main\package.json -Raw | ConvertFrom-Json).lbrySettings
$package_settings = (Get-Content package.json -Raw | ConvertFrom-Json).lbrySettings
$daemon_ver = $package_settings.lbrynetDaemonVersion
$daemon_url_template = $package_settings.lbrynetDaemonUrlTemplate
$daemon_url = $daemon_url_template.Replace('OSNAME', 'windows').Replace('DAEMONVER', $daemon_ver)
Invoke-WebRequest -Uri $daemon_url -OutFile daemon.zip
Expand-Archive daemon.zip -DestinationPath src\main\dist\
dir src\main\dist\ # verify that daemon binary is there
Expand-Archive daemon.zip -DestinationPath static\daemon\
dir static\daemon\ # verify that daemon binary is there
rm daemon.zip
# build electron app
node_modules\.bin\build -p never
$binary_name = Get-ChildItem -Path dist -Filter '*.exe' -Name
yarn dist
$binary_name = Get-ChildItem -Path dist -Filter 'LBRY Setup*.exe' -Name
$new_name = $binary_name -replace '^LBRY Setup (.*)\.exe$', 'LBRY_$1.exe'
Rename-Item -Path "dist\$binary_name" -NewName $new_name
dir dist # verify that binary was built/named correctly

View file

@ -40,30 +40,9 @@ else
fi
[ -d "$ROOT/dist" ] && rm -rf "$ROOT/dist"
mkdir -p "$ROOT/dist"
[ -d "$ROOT/src/main/dist" ] && rm -rf "$ROOT/src/main/dist"
mkdir -p "$ROOT/src/main/dist"
yarn install
############
# UI #
############
echo -e "\033[0;32mCompiling UI\x1b[m"
(
cd "$ROOT/src/renderer"
yarn install
npm rebuild node-sass
node extractLocals.js
node_modules/.bin/node-sass --output dist/css --sourcemap=none scss/
node_modules/.bin/webpack --config webpack.prod.js
cp -r dist/* "$ROOT/src/main/dist/"
)
####################
# daemon and cli #
####################
@ -73,14 +52,14 @@ if $OSX; then
else
OSNAME="linux"
fi
DAEMON_VER=$(node -e "console.log(require(\"$ROOT/src/main/package.json\").lbrySettings.lbrynetDaemonVersion)")
DAEMON_URL_TEMPLATE=$(node -e "console.log(require(\"$ROOT/src/main/package.json\").lbrySettings.lbrynetDaemonUrlTemplate)")
DAEMON_VER=$(node -e "console.log(require(\"$ROOT/package.json\").lbrySettings.lbrynetDaemonVersion)")
DAEMON_URL_TEMPLATE=$(node -e "console.log(require(\"$ROOT/package.json\").lbrySettings.lbrynetDaemonUrlTemplate)")
DAEMON_URL=$(echo ${DAEMON_URL_TEMPLATE//DAEMONVER/$DAEMON_VER} | sed "s/OSNAME/$OSNAME/g")
DAEMON_VER_PATH="$BUILD_DIR/daemon.ver"
echo "$DAEMON_VER_PATH"
if [[ ! -f $DAEMON_VER_PATH || ! -f $ROOT/src/main/dist/lbrynet-daemon || "$(< "$DAEMON_VER_PATH")" != "$DAEMON_VER" ]]; then
if [[ ! -f $DAEMON_VER_PATH || ! -f $ROOT/static/daemon/lbrynet-daemon || "$(< "$DAEMON_VER_PATH")" != "$DAEMON_VER" ]]; then
curl -sL -o "$BUILD_DIR/daemon.zip" "$DAEMON_URL"
unzip "$BUILD_DIR/daemon.zip" -d "$ROOT/src/main/dist/"
unzip "$BUILD_DIR/daemon.zip" -d "$ROOT/static/daemon/"
rm "$BUILD_DIR/daemon.zip"
echo "$DAEMON_VER" > "$DAEMON_VER_PATH"
else
@ -93,26 +72,12 @@ fi
###################
# Build the app #
###################
echo -e '\033[0;32mBuilding Lbry-app\x1b[m'
(
cd "$ROOT/src/main"
yarn install
# necessary to ensure native Node modules (e.g. keytar) are built against the correct version of Node)
# yes, it needs to be run twice. it fails the first time, not sure why
set +e
# DEBUG=electron-rebuild node_modules/.bin/electron-rebuild .
node_modules/.bin/electron-rebuild "$ROOT/src/main"
set -e
node_modules/.bin/electron-rebuild "$ROOT/src/main"
)
if [ "$FULL_BUILD" == "true" ]; then
if $OSX; then
security unlock-keychain -p ${KEYCHAIN_PASSWORD} osx-build.keychain
fi
node_modules/.bin/build -p never
yarn dist
if $OSX; then
binary_name=$(find "$ROOT/dist" -iname "*dmg")
@ -133,5 +98,5 @@ if [ "$FULL_BUILD" == "true" ]; then
echo -e '\033[0;32mBuild and packaging complete.\x1b[m'
else
echo -e 'Build complete. Run \033[1;31m./node_modules/.bin/electron src/main\x1b[m to launch the app'
echo -e 'Build complete. Run \033[1;31myarn dev\x1b[m to launch the app'
fi

View file

@ -17,7 +17,7 @@ import github
import changelog
ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
APP_PACKAGE_JSON_FILE = os.path.join(ROOT, 'src', 'main', 'package.json')
APP_PACKAGE_JSON_FILE = os.path.join(ROOT, 'package.json')
def main():

View file

@ -19,7 +19,7 @@ def get_asset_filename():
this_dir = os.path.dirname(os.path.realpath(__file__))
system = platform.system()
if system == 'Darwin':
return glob.glob(this_dir + '/../dist/mac/LBRY*.dmg')[0]
return glob.glob(this_dir + '/../dist/LBRY*.dmg')[0]
elif system == 'Linux':
return glob.glob(this_dir + '/../dist/LBRY*.deb')[0]
elif system == 'Windows':

54
electron-builder.json Normal file
View file

@ -0,0 +1,54 @@
{
"appId": "io.lbry.LBRY",
"mac": {
"category": "public.app-category.entertainment",
},
"dmg": {
"iconSize": 128,
"contents": [
{
"x": 115,
"y": 164
},
{
"x": 387,
"y": 164,
"type": "link",
"path": "/Applications"
}
],
"window": {
"x": 200,
"y": 200,
"width": 500,
"height": 300
},
"background": "build/background.png"
},
"protocols": [
{
"name": "lbry",
"schemes": ["lbry"],
"role": "Viewer"
}
],
"linux": {
"target": "deb",
"desktop": {
"MimeType": "x-scheme-handler/lbry",
"Exec": "/opt/LBRY/lbry %U"
}
},
"deb": {
"depends": [
"gconf2",
"gconf-service",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libsecret-1-0"
]
},
"artifactName": "${productName}_${version}_${arch}.${ext}"
}

5
electron-webpack.json Normal file
View file

@ -0,0 +1,5 @@
{
"renderer": {
"webpackConfig": "webpack.renderer.additions.js"
}
}

View file

@ -1,80 +1,108 @@
{
"postinstall": "install-app-deps",
"build": {
"asar": false,
"directories": {
"app": "src/main"
},
"appId": "io.lbry.LBRY",
"mac": {
"category": "public.app-category.utilities",
"target": "dmg"
},
"dmg": {
"iconSize": 128,
"contents": [
{
"x": 115,
"y": 164
},
{
"x": 387,
"y": 164,
"type": "link",
"path": "/Applications"
}
],
"window": {
"x": 200,
"y": 200,
"width": 500,
"height": 300
},
"backgroundColor": "155B4A"
},
"protocols": [
{
"name": "lbry",
"role": "Viewer",
"schemes": [
"lbry"
]
}
],
"linux": {
"target": "deb",
"desktop": {
"MimeType": "x-scheme-handler/lbry",
"Exec": "/opt/LBRY/lbry %U"
}
},
"deb": {
"depends": [
"gconf2",
"gconf-service",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libsecret-1-0"
]
},
"win": {
"target": "nsis"
},
"nsis": {
"perMachine": true
}
"name": "LBRY",
"version": "0.18.2",
"description": "A browser for the LBRY network, a digital marketplace controlled by its users.",
"author": {
"name": "LBRY Inc.",
"email": "hello@lbry.io"
},
"homepage": "https://lbry.io/",
"scripts": {
"start": "./node_modules/.bin/electron src/main"
"extract-langs": "node src/renderer/extractLocals.js",
"dev": "electron-webpack dev",
"compile": "electron-webpack && yarn extract-langs",
"dist": "yarn compile && electron-builder",
"dist:dir": "yarn dist -- --dir -c.compression=store -c.mac.identity=null",
"postinstall": "electron-builder install-app-deps",
"precommit": "lint-staged",
"prettier": "prettier --trailing-comma es5 --write js/**/*.{js,jsx}"
},
"main": "src/main/main.js",
"repository": {
"type": "git",
"url": "https://github.com/lbryio/lbry-app"
},
"bugs": {
"url": "https://github.com/lbryio/lbry-app/issues"
},
"keywords": [
"lbry"
],
"dependencies": {
"amplitude-js": "^4.0.0",
"classnames": "^2.2.5",
"electron-dl": "^1.6.0",
"formik": "^0.10.4",
"from2": "^2.3.0",
"install": "^0.8.7",
"jayson": "^2.0.2",
"jshashes": "^1.0.7",
"keytar": "^4.0.3",
"localforage": "^1.5.0",
"npm": "^5.5.1",
"qrcode.react": "^0.7.2",
"rc-progress": "^2.0.6",
"react": "^15.4.0",
"react-dom": "^15.4.0",
"react-markdown": "^2.5.0",
"react-modal": "^1.5.2",
"react-paginate": "^4.4.3",
"react-redux": "^5.0.3",
"react-simplemde-editor": "^3.6.11",
"redux": "^3.6.0",
"redux-action-buffer": "^1.1.0",
"redux-logger": "^3.0.1",
"redux-persist": "^4.8.0",
"redux-persist-transform-compress": "^4.2.0",
"redux-persist-transform-filter": "0.0.10",
"redux-thunk": "^2.2.0",
"render-media": "^2.10.0",
"reselect": "^3.0.0",
"semver": "^5.3.0",
"shapeshift.io": "^1.3.1",
"source-map-support": "^0.5.0",
"tree-kill": "^1.1.0",
"y18n": "^3.2.1"
},
"devDependencies": {
"babel-plugin-module-resolver": "^3.0.0",
"babel-plugin-react-require": "^3.0.0",
"babel-polyfill": "^6.20.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.18.0",
"bluebird": "^3.5.1",
"devtron": "^1.4.0",
"electron": "^1.7.9",
"electron-builder": "^11.7.0",
"electron-debug": "^1.4.0",
"electron-devtools-installer": "^2.2.1"
"electron-builder": "^19.48.2",
"electron-devtools-installer": "^2.2.1",
"electron-webpack": "^1.11.0",
"flow-babel-webpack-plugin": "^1.1.0",
"flow-bin": "^0.60.1",
"flow-typed": "^2.2.3",
"husky": "^0.13.4",
"i18n-extract": "^0.4.4",
"json-loader": "^0.5.4",
"lint-staged": "^3.6.0",
"node-loader": "^0.6.0",
"node-sass": "^4.7.2",
"prettier": "^1.4.2",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0",
"webpack-build-notifier": "^0.1.18"
},
"license": "MIT"
"resolutions": {
"webpack/webpack-sources": "1.0.1"
},
"license": "MIT",
"lint-staged": {
"src/renderer/js/**/*.{jsx,js}": [
"prettier --trailing-comma es5 --write",
"git add"
]
},
"lbrySettings": {
"lbrynetDaemonVersion": "0.18.0",
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-daemon-vDAEMONVER-OSNAME.zip"
}
}

0
src/common/.gitkeep Normal file
View file

View file

@ -1,4 +1,3 @@
module.exports = { safeQuit };
// Module imports
const {app, BrowserWindow, ipcMain, Menu, Tray, globalShortcut} = require('electron');
const path = require('path');
@ -12,16 +11,15 @@ const keytar = require('keytar');
const kill = require('tree-kill');
const child_process = require('child_process');
const assert = require('assert');
const {version: localVersion} = require(app.getAppPath() + '/package.json');
const localVersion = app.getVersion();
const setMenu = require('./menu/main-menu.js');
export const contextMenu = require('./menu/context-menu');
// Debug configs
const isDebug = process.env.NODE_ENV === 'development';
if (isDebug) {
const isDevelopment = process.env.NODE_ENV === 'development';
if (isDevelopment) {
try
{
require('electron-debug')({showDevTools: true});
const { default: installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = require('electron-devtools-installer');
app.on('ready', () => {
[REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS].forEach(extension => {
@ -31,7 +29,7 @@ if (isDebug) {
});
});
}
catch (err) // electron-debug is in devDependencies, but some
catch (err)
{
console.error(err)
}
@ -39,7 +37,10 @@ if (isDebug) {
// 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(__dirname, 'dist', 'lbrynet-daemon');
const DAEMON_PATH = 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`;
let client = jayson.client.http({
host: 'localhost',
@ -83,56 +84,13 @@ function processRequestedUri(uri) {
// lbry://channel/#claimid. We remove the slash here as well.
// On Linux and Mac, we just return the URI as given.
if (process.platform == 'win32') {
if (process.platform === 'win32') {
return uri.replace(/\/$/, '').replace('/#', '#');
} else {
return uri;
}
}
function checkForNewVersion(callback) {
function formatRc(ver) {
// Adds dash if needed to make RC suffix semver friendly
return ver.replace(/([^-])rc/, '$1-rc');
}
let result = '';
const opts = {
headers: {
'User-Agent': `LBRY/${localVersion}`,
}
};
const req = https.get(Object.assign(opts, url.parse(LATEST_RELEASE_API_URL)), (res) => {
res.on('data', (data) => {
result += data;
});
res.on('end', () => {
const tagName = JSON.parse(result).tag_name;
const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
if (!remoteVersion) {
if (win) {
win.webContents.send('version-info-received', null);
}
} else {
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
if (win) {
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
}
}
})
});
req.on('error', (err) => {
console.log('Failed to get current version from GitHub. Error:', err);
if (win) {
win.webContents.send('version-info-received', null);
}
});
}
ipcMain.on('version-info-requested', checkForNewVersion);
/*
* Replacement for Electron's shell.openItem. The Electron version doesn't
* reliably work from the main process, and we need to be able to run it
@ -145,11 +103,11 @@ function openItem(fullPath) {
};
let child;
if (process.platform == 'darwin') {
if (process.platform === 'darwin') {
child = child_process.spawn('open', [fullPath], subprocOptions);
} else if (process.platform == 'linux') {
} else if (process.platform === 'linux') {
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
} else if (process.platform == 'win32') {
} else if (process.platform === 'win32') {
child = child_process.spawn(fullPath, Object.assign({}, subprocOptions, {shell: true}));
}
@ -158,7 +116,7 @@ function openItem(fullPath) {
}
function getPidsForProcessName(name) {
if (process.platform == 'win32') {
if (process.platform === 'win32') {
const tasklistOut = child_process.execSync(`tasklist /fi "Imagename eq ${name}.exe" /nh`, {encoding: 'utf8'});
if (tasklistOut.startsWith('INFO')) {
return [];
@ -172,15 +130,18 @@ function getPidsForProcessName(name) {
}
function createWindow () {
win = new BrowserWindow({backgroundColor: '#155B4A', minWidth: 800, minHeight: 600 }) //$color-primary
// Disable renderer process's webSecurity on development to enable CORS.
win = isDevelopment
? new BrowserWindow({backgroundColor: '#155B4A', minWidth: 800, minHeight: 600, webPreferences: {webSecurity: false}})
: new BrowserWindow({backgroundColor: '#155B4A', minWidth: 800, minHeight: 600});
win.webContents.session.setUserAgent(`LBRY/${localVersion}`);
win.maximize()
if (isDebug) {
if (isDevelopment) {
win.webContents.openDevTools();
}
win.loadURL(`file://${__dirname}/dist/index.html`)
win.loadURL(rendererUrl)
if (openUri) { // We stored and received a URI that an external app requested before we had a window object
win.webContents.on('did-finish-load', () => {
win.webContents.send('open-uri-requested', openUri);
@ -230,7 +191,7 @@ function createWindow () {
// Menu bar
win.setAutoHideMenuBar(true);
win.setMenuBarVisibility(isDebug);
win.setMenuBarVisibility(isDevelopment);
setMenu();
};
@ -242,9 +203,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(app.getAppPath(), "/dist/img/fav/macTemplate@2x.png");
iconPath = path.join(__static, "/img/fav/macTemplate@2x.png");
} else {
iconPath = path.join(app.getAppPath(), "/dist/img/fav/32x32.png");
iconPath = path.join(__static, "/img/fav/32x32.png");
}
tray = new Tray(iconPath);
@ -317,7 +278,7 @@ function handleDaemonSubprocessExited() {
// TODO: maybe it would be better to restart the daemon?
if (win) {
console.log('Did not request daemon stop, so quitting in 5 seconds.');
win.loadURL(`file://${__dirname}/dist/warning.html`);
win.loadURL(`file://${__static}/warning.html`);
setTimeout(quitNow, 5000);
} else {
console.log('Did not request daemon stop, so quitting.');
@ -326,7 +287,6 @@ function handleDaemonSubprocessExited() {
}
}
function launchDaemon() {
assert(!daemonSubprocess, 'Tried to launch daemon twice');
@ -340,11 +300,10 @@ function launchDaemon() {
daemonSubprocess.on('exit', handleDaemonSubprocessExited);
}
/*
* Quits by first killing the daemon, the calling quitting for real.
*/
function safeQuit() {
export function safeQuit() {
minimize = false;
app.quit();
}
@ -374,22 +333,8 @@ const isSecondaryInstance = app.makeSingleInstance((argv) => {
if (isSecondaryInstance) { // We're not in the original process, so quit
quitNow();
return;
}
app.on('ready', function() {
launchDaemonIfNotRunning();
if (process.platform === "linux") {
checkLinuxTraySupport( err => {
if (!err) createTray();
else minimize = false;
})
} else {
createTray();
}
createWindow();
});
function launchDaemonIfNotRunning() {
// Check if the daemon is already running. If we get
// an error its because its not running
@ -439,6 +384,20 @@ function forceKillAllDaemonsAndQuit() {
}
}
app.setAsDefaultProtocolClient('lbry');
app.on('ready', function() {
launchDaemonIfNotRunning();
if (process.platform === "linux") {
checkLinuxTraySupport( err => {
if (!err) createTray();
else minimize = false;
})
} else {
createTray();
}
createWindow();
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
@ -461,7 +420,6 @@ app.on('before-quit', (event) => {
}
});
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
@ -470,6 +428,14 @@ app.on('activate', () => {
}
});
if (process.platform === 'darwin') {
app.on('open-url', (event, uri) => {
handleOpenUriRequested(uri);
});
} else if (process.argv.length >= 2) {
handleOpenUriRequested(process.argv[1]);
}
// When a quit is attempted, this is called. It attempts to shutdown the daemon,
// then calls quitNow() to quit for real.
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
@ -500,26 +466,6 @@ function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
// If not, we should wait until the daemon is closed before we start the install.
}
function upgrade(event, installerPath) {
app.on('quit', () => {
console.log('Launching upgrade installer at', installerPath);
// This gets triggered called after *all* other quit-related events, so
// we'll only get here if we're fully prepared and quitting for real.
openItem(installerPath);
});
if (win) {
win.loadURL(`file://${__dirname}/dist/upgrade.html`);
}
shutdownDaemonAndQuit(true);
// wait for daemon to shut down before upgrading
// what to do if no shutdown in a long time?
console.log('Update downloaded to', installerPath);
console.log('The app will close, and you will be prompted to install the latest version of LBRY.');
console.log('After the install is complete, please reopen the app.');
}
// Taken from webtorrent-desktop
function checkLinuxTraySupport (cb) {
// Check that we're on Ubuntu (or another debian system) and that we have
@ -536,18 +482,67 @@ function checkLinuxTraySupport (cb) {
})
}
ipcMain.on('upgrade', upgrade);
app.setAsDefaultProtocolClient('lbry');
if (process.platform == 'darwin') {
app.on('open-url', (event, uri) => {
handleOpenUriRequested(uri);
ipcMain.on('upgrade', (event, installerPath) => {
app.on('quit', () => {
console.log('Launching upgrade installer at', installerPath);
// This gets triggered called after *all* other quit-related events, so
// we'll only get here if we're fully prepared and quitting for real.
openItem(installerPath);
});
} else if (process.argv.length >= 2) {
handleOpenUriRequested(process.argv[1]);
if (win) {
win.loadURL(`file://${__static}/upgrade.html`);
}
shutdownDaemonAndQuit(true);
// wait for daemon to shut down before upgrading
// what to do if no shutdown in a long time?
console.log('Update downloaded to', installerPath);
console.log('The app will close, and you will be prompted to install the latest version of LBRY.');
console.log('After the install is complete, please reopen the app.');
});
ipcMain.on('version-info-requested', () => {
function formatRc(ver) {
// Adds dash if needed to make RC suffix semver friendly
return ver.replace(/([^-])rc/, '$1-rc');
}
let result = '';
const opts = {
headers: {
'User-Agent': `LBRY/${localVersion}`,
}
};
const req = https.get(Object.assign(opts, url.parse(LATEST_RELEASE_API_URL)), (res) => {
res.on('data', (data) => {
result += data;
});
res.on('end', () => {
const tagName = JSON.parse(result).tag_name;
const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
if (!remoteVersion) {
if (win) {
win.webContents.send('version-info-received', null);
}
} else {
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
if (win) {
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
}
}
})
});
req.on('error', (err) => {
console.log('Failed to get current version from GitHub. Error:', err);
if (win) {
win.webContents.send('version-info-received', null);
}
});
});
ipcMain.on('get-auth-token', (event) => {
keytar.getPassword("LBRY", "auth_token").then(token => {
event.sender.send('auth-token-response', token ? token.toString().trim() : null)

View file

@ -1,28 +0,0 @@
{
"name": "LBRY",
"version": "0.18.2",
"main": "main.js",
"description": "A browser for the LBRY network, a digital marketplace controlled by its users.",
"homepage": "https://github.com/lbryio/lbry-app",
"author": {
"name": "LBRY Inc.",
"email": "hello@lbry.io"
},
"dependencies": {
"electron-dl": "^1.6.0",
"install": "^0.8.7",
"jayson": "^2.0.2",
"keytar": "^4.0.3",
"npm": "^4.2.0",
"semver": "^5.3.0",
"tree-kill": "^1.1.0"
},
"devDependencies": {
"electron-rebuild": "^1.5.11"
},
"lbrySettings": {
"lbrynetDaemonVersion": "0.18.0",
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-daemon-vDAEMONVER-OSNAME.zip"
},
"license": "MIT"
}

File diff suppressed because it is too large Load diff

View file

@ -1,9 +0,0 @@
{
"presets": [
"es2015",
"react"
],
"plugins" : [
"transform-flow-comments"
]
}

View file

@ -1,239 +0,0 @@
module.exports = {
"extends": "airbnb",
"plugins": [
"react",
"jsx-a11y",
"import"
],
"env": {
"browser": true,
},
// Grabbed from https://gist.github.com/cletusw/e01a85e399ab563b1236
"rules": {
////////// Possible Errors //////////
"no-comma-dangle": 0, // disallow trailing commas in object literals
"no-cond-assign": 0, // disallow assignment in conditional expressions
"no-console": 0, // disallow use of console (off by default in the node environment)
"no-constant-condition": 0, // disallow use of constant expressions in conditions
"no-control-regex": 0, // disallow control characters in regular expressions
"no-debugger": 0, // disallow use of debugger
"no-dupe-keys": 0, // disallow duplicate keys when creating object literals
"no-empty": 0, // disallow empty statements
"no-empty-class": 0, // disallow the use of empty character classes in regular expressions
"no-ex-assign": 0, // disallow assigning to the exception in a catch block
"no-extra-boolean-cast": 0, // disallow double-negation boolean casts in a boolean context
"no-extra-parens": 0, // disallow unnecessary parentheses (off by default)
"no-extra-semi": 0, // disallow unnecessary semicolons
"no-func-assign": 0, // disallow overwriting functions written as function declarations
"no-inner-declarations": 0, // disallow function or variable declarations in nested blocks
"no-invalid-regexp": 0, // disallow invalid regular expression strings in the RegExp constructor
"no-irregular-whitespace": 0, // disallow irregular whitespace outside of strings and comments
"no-negated-in-lhs": 0, // disallow negation of the left operand of an in expression
"no-obj-calls": 0, // disallow the use of object properties of the global object (Math and JSON) as functions
"no-regex-spaces": 0, // disallow multiple spaces in a regular expression literal
"no-reserved-keys": 0, // disallow reserved words being used as object literal keys (off by default)
"no-sparse-arrays": 0, // disallow sparse arrays
"no-unreachable": 0, // disallow unreachable statements after a return, throw, continue, or break statement
"use-isnan": 0, // disallow comparisons with the value NaN
"valid-jsdoc": 0, // Ensure JSDoc comments are valid (off by default)
"valid-typeof": 0, // Ensure that the results of typeof are compared against a valid string
////////// Best Practices //////////
"block-scoped-var": 0, // treat var statements as if they were block scoped (off by default)
"complexity": 0, // specify the maximum cyclomatic complexity allowed in a program (off by default)
"consistent-return": 0, // require return statements to either always or never specify values
"curly": 0, // specify curly brace conventions for all control statements
"default-case": 0, // require default case in switch statements (off by default)
"dot-notation": 0, // encourages use of dot notation whenever possible
"eqeqeq": 0, // require the use of === and !==
"guard-for-in": 0, // make sure for-in loops have an if statement (off by default)
"no-alert": 0, // disallow the use of alert, confirm, and prompt
"no-caller": 0, // disallow use of arguments.caller or arguments.callee
"no-div-regex": 0, // disallow division operators explicitly at beginning of regular expression (off by default)
"no-else-return": 0, // disallow else after a return in an if (off by default)
"no-empty-label": 0, // disallow use of labels for anything other then loops and switches
"no-eq-null": 0, // disallow comparisons to null without a type-checking operator (off by default)
"no-eval": 0, // disallow use of eval()
"no-extend-native": 0, // disallow adding to native types
"no-extra-bind": 0, // disallow unnecessary function binding
"no-fallthrough": 0, // disallow fallthrough of case statements
"no-floating-decimal": 0, // disallow the use of leading or trailing decimal points in numeric literals (off by default)
"no-implied-eval": 0, // disallow use of eval()-like methods
"no-iterator": 0, // disallow usage of __iterator__ property
"no-labels": 0, // disallow use of labeled statements
"no-lone-blocks": 0, // disallow unnecessary nested blocks
"no-loop-func": 0, // disallow creation of functions within loops
"no-multi-spaces": 0, // disallow use of multiple spaces
"no-multi-str": 0, // disallow use of multiline strings
"no-native-reassign": 0, // disallow reassignments of native objects
"no-new": 0, // disallow use of new operator when not part of the assignment or comparison
"no-new-func": 0, // disallow use of new operator for Function object
"no-new-wrappers": 0, // disallows creating new instances of String, Number, and Boolean
"no-octal": 0, // disallow use of octal literals
"no-octal-escape": 0, // disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
"no-process-env": 0, // disallow use of process.env (off by default)
"no-proto": 0, // disallow usage of __proto__ property
"no-redeclare": 0, // disallow declaring the same variable more then once
"no-return-assign": 0, // disallow use of assignment in return statement
"no-script-url": 0, // disallow use of javascript: urls.
"no-self-compare": 0, // disallow comparisons where both sides are exactly the same (off by default)
"no-sequences": 0, // disallow use of comma operator
"no-unused-expressions": 0, // disallow usage of expressions in statement position
"no-void": 0, // disallow use of void operator (off by default)
"no-warning-comments": 0, // disallow usage of configurable warning terms in comments, e.g. TODO or FIXME (off by default)
"no-with": 0, // disallow use of the with statement
"radix": 0, // require use of the second argument for parseInt() (off by default)
"vars-on-top": 0, // requires to declare all vars on top of their containing scope (off by default)
"wrap-iife": 0, // require immediate function invocation to be wrapped in parentheses (off by default)
"yoda": 0, // require or disallow Yoda conditions
////////// Strict Mode //////////
"global-strict": 0, // (deprecated) require or disallow the "use strict" pragma in the global scope (off by default in the node environment)
"no-extra-strict": 0, // (deprecated) disallow unnecessary use of "use strict"; when already in strict mode
"strict": 0, // controls location of Use Strict Directives
////////// Variables //////////
"no-catch-shadow": 0, // disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment)
"no-delete-var": 0, // disallow deletion of variables
"no-label-var": 0, // disallow labels that share a name with a variable
"no-shadow": 0, // disallow declaration of variables already declared in the outer scope
"no-shadow-restricted-names": 0, // disallow shadowing of names such as arguments
"no-undef": 1, // disallow use of undeclared variables unless mentioned in a /*global */ block
"no-undef-init": 0, // disallow use of undefined when initializing variables
"no-undefined": 0, // disallow use of undefined variable (off by default)
"no-unused-vars": 0, // disallow declaration of variables that are not used in the code
"no-use-before-define": 0, // disallow use of variables before they are defined
////////// Node.js //////////
"handle-callback-err": 0, // enforces error handling in callbacks (off by default) (on by default in the node environment)
"no-mixed-requires": 0, // disallow mixing regular variable and require declarations (off by default) (on by default in the node environment)
"no-new-require": 0, // disallow use of new operator with the require function (off by default) (on by default in the node environment)
"no-path-concat": 0, // disallow string concatenation with __dirname and __filename (off by default) (on by default in the node environment)
"no-process-exit": 0, // disallow process.exit() (on by default in the node environment)
"no-restricted-modules": 0, // restrict usage of specified node modules (off by default)
"no-sync": 0, // disallow use of synchronous methods (off by default)
////////// Stylistic Issues //////////
"brace-style": 0, // enforce one true brace style (off by default)
"camelcase": 0, // require camel case names
"comma-spacing": 0, // enforce spacing before and after comma
"comma-style": 0, // enforce one true comma style (off by default)
"consistent-this": 0, // enforces consistent naming when capturing the current execution context (off by default)
"eol-last": 0, // enforce newline at the end of file, with no multiple empty lines
"func-names": 0, // require function expressions to have a name (off by default)
"func-style": 0, // enforces use of function declarations or expressions (off by default)
"key-spacing": 0, // enforces spacing between keys and values in object literal properties
"max-nested-callbacks": 0, // specify the maximum depth callbacks can be nested (off by default)
"new-cap": 0, // require a capital letter for constructors
"new-parens": 0, // disallow the omission of parentheses when invoking a constructor with no arguments
"no-array-constructor": 0, // disallow use of the Array constructor
"no-inline-comments": 0, // disallow comments inline after code (off by default)
"no-lonely-if": 0, // disallow if as the only statement in an else block (off by default)
"no-mixed-spaces-and-tabs": 0, // disallow mixed spaces and tabs for indentation
"no-multiple-empty-lines": 0, // disallow multiple empty lines (off by default)
"no-nested-ternary": 0, // disallow nested ternary expressions (off by default)
"no-new-object": 0, // disallow use of the Object constructor
"no-space-before-semi": 0, // disallow space before semicolon
"no-spaced-func": 0, // disallow space between function identifier and application
"no-ternary": 0, // disallow the use of ternary operators (off by default)
"no-trailing-spaces": 0, // disallow trailing whitespace at the end of lines
"no-underscore-dangle": 0, // disallow dangling underscores in identifiers
"no-wrap-func": 0, // disallow wrapping of non-IIFE statements in parens
"one-var": 0, // allow just one var statement per function (off by default)
"operator-assignment": 0, // require assignment operator shorthand where possible or prohibit it entirely (off by default)
"padded-blocks": 0, // enforce padding within blocks (off by default)
"quote-props": 0, // require quotes around object literal property names (off by default)
"quotes": 0, // specify whether double or single quotes should be used
"semi": 0, // require or disallow use of semicolons instead of ASI
"sort-vars": 0, // sort variables within the same declaration block (off by default)
"space-after-function-name": 0, // require a space after function names (off by default)
"space-after-keywords": 0, // require a space after certain keywords (off by default)
"space-before-blocks": 0, // require or disallow space before blocks (off by default)
"space-in-brackets": 0, // require or disallow spaces inside brackets (off by default)
"space-in-parens": 0, // require or disallow spaces inside parentheses (off by default)
"space-infix-ops": 0, // require spaces around operators
"space-return-throw-case": 0, // require a space after return, throw, and case
"space-unary-ops": 0, // Require or disallow spaces before/after unary operators (words on by default, nonwords off by default)
"spaced-line-comment": 0, // require or disallow a space immediately following the // in a line comment (off by default)
"wrap-regex": 0, // require regex literals to be wrapped in parentheses (off by default)
////////// ECMAScript 6 //////////
"no-var": 0, // require let or const instead of var (off by default)
"generator-star": 0, // enforce the position of the * in generator functions (off by default)
////////// Legacy //////////
"max-depth": 0, // specify the maximum depth that blocks can be nested (off by default)
"max-len": 0, // specify the maximum length of a line in your program (off by default)
"max-params": 0, // limits the number of parameters that can be used in the function declaration. (off by default)
"max-statements": 0, // specify the maximum number of statement allowed in a function (off by default)
"no-bitwise": 0, // disallow use of bitwise operators (off by default)
"no-plusplus": 0, // disallow use of unary operators, ++ and -- (off by default)
// There were other errors that were being thrown
"import/newline-after-import": 0,
"object-curly-spacing": 0,
"space-before-function-paren": 0,
"no-restricted-syntax": 0,
"no-unneeded-ternary": 0,
"react/prefer-es6-class": 0,
"arrow-parens": 0,
"jsx-quotes": 0,
"react/sort-comp": 0,
"react/no-unescaped-entities": 0,
"object-shorthand": 0,
"jsx-a11y/label-has-for": 0,
"no-mixed-operators": 0,
"react/jsx-no-bind": 0,
"no-duplicate-case": 0,
"react/jsx-filename-extension": 0,
"jsx-a11y/img-has-alt": 0,
"react/self-closing-comp": 0,
"prefer-const": 0,
"one-var-declaration-per-line": 0,
"react/jsx-indent": 0,
"react/jsx-curly-spacing": 0,
"react/prefer-stateless-function": 0,
"react/jsx-indent-props": 0,
"react/no-find-dom-node": 0,
"react/no-unused-prop-types": 0,
"react/jsx-no-undef": 0,
"react/no-string-refs": 0,
"react/jsx-first-prop-new-line": 0,
"comma-dangle": 0,
"react/no-multi-comp": 0,
"spaced-comment": 0,
"jsx-a11y/anchor-has-content": 0,
"semi-spacing": 0,
"no-param-reassign": 0,
"react/jsx-no-target-blank": 0,
"prefer-arrow-callback": 0,
"react/jsx-space-before-closing": 0,
"react/forbid-prop-types": 0,
"indent": 0,
"import/no-unresolved": 0,
"react/jsx-boolean-value": 0,
"prefer-template": 0,
"react/jsx-wrap-multilines": 0,
"keyword-spacing": 0,
"react/jsx-closing-bracket-location": 0,
"react/react-in-jsx-scope": 0,
"no-useless-escape": 0,
"no-continue": 0,
"react/prop-types": 0
}
};

View file

@ -1,20 +0,0 @@
[ignore]
.*/node_modules/**
[include]
[libs]
flow-typed
[lints]
[options]
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
module.name_mapper='^constants\(.*\)$' -> '<PROJECT_ROOT>/js/constants\1'
module.name_mapper='^util\(.*\)$' -> '<PROJECT_ROOT>/js/util\1'
module.name_mapper='^redux\(.*\)$' -> '<PROJECT_ROOT>/js/redux\1'
module.name_mapper='^types\(.*\)$' -> '<PROJECT_ROOT>/js/types\1'
module.name_mapper='^component\(.*\)$' -> '<PROJECT_ROOT>/js/component\1'
[strict]

View file

@ -1,6 +0,0 @@
## Development Setup
- Install node and npm (linux users: [use this](https://github.com/nodesource/distributions). if that doesn't work, [this gist may be useful](https://gist.github.com/isaacs/579814))
- `npm install -g yarn` (or see https://yarnpkg.com/en/docs/install)
- Run `./watch.sh` (this will `yarn install` dependencies)

View file

@ -1,7 +1,7 @@
import store from "store.js";
import { remote } from "electron";
const env = ENV;
const env = process.env.NODE_ENV || "production";
const config = {
...require(`./config/${env}`),
};

Some files were not shown because too many files have changed in this diff Show more