initial electron app

This commit is contained in:
Job Evers-Meltzer 2017-01-16 14:06:53 -05:00
parent 7f77fa0b4e
commit c0847cc420
5 changed files with 160 additions and 0 deletions

44
README.md Normal file
View file

@ -0,0 +1,44 @@
# LBRY Electron
An electron version of the LBRY application.
## Setup
Need to have the lbry-web-ui and lbry repos in a folder next to
lbry-electron. For example, my directory structure looks like
```
$HOME/projects/lbryio/lbry
$HOME/projects/lbryio/lbry-web-ui
$HOME/projects/lbryio/lbry-electron
```
Additionally, lbrynet needs to be installed along with pyinstaller, and you
need everything to be able to build the lbry-web-ui
## Build
run `./build.sh` to create a lbry executable, bundle the front-end and move
everything into the the electron repo
## Run
`electron electron`
## Package
To build a distributable package for OSX, run (on an OSX machine):
`electron-packager --electron-version=1.4.14 --overwrite electron LBRY`
This also probably works for windows and linux, but I haven't tested it
## TODO
This app works by launching the lbrynet daemon in a seperate process. Currently the
process management is very poor and the lbrynet process might not be shut-down when the app
is closed. Also, if the lbrynet daemon dies, there is no attempt to restart it.

22
build.sh Executable file
View file

@ -0,0 +1,22 @@
#! /bin/bash
set -o xtrace
set -eu
cd lbrynet
pyinstaller lbry.py -y --windowed --onefile --icon=../../lbry/packaging/osx/lbry-osx-app/app.icns
cd ../../lbry-web-ui
git checkout master
git pull --rebase
git cherry-pick 06224b1d2cf4bf1f63d95031502260dd9c3ec5c1
node_modules/.bin/node-sass --output dist/css --sourcemap=none scss/
webpack
git reset --hard origin/master
cd ../lbry-electron/
cp -R ../lbry-web-ui/dist electron/
mv lbrynet/dist/lbry electron/dist
echo 'Build complete. Run `electron electron` to launch the app'

82
electron/main.js Normal file
View file

@ -0,0 +1,82 @@
const {app, BrowserWindow} = require('electron')
var jayson = require('jayson');
var client = jayson.client.http('http://localhost:5279/lbryapi');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
// Also keep the daemon subprocess alive
let subpy
function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})
win.maximize()
// and load the index.html of the app.
win.loadURL(`file://${__dirname}/dist/index.html`)
console.log('Loaded the index page')
// Open the DevTools.
//win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
console.log('Loaded the index page')
subpy.kill('SIGINT');
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', function(){
// call python?
subpy = require('child_process').spawn(`${__dirname}/dist/lbry`, ['--no-launch', '--log-to-console'], {stdio: ['ignore', process.stdout, process.stderr]})
console.log('lbrynet daemon has launched')
launchWindowWhenDaemonHasStarted();
})
// TODO: incorporate this into the LBRY module
function launchWindowWhenDaemonHasStarted() {
client.request(
'status', [],
function (err, res) {
// Did it all work ?
if (err) {
console.log(err);
console.log('Will try again in half a second');
setTimeout(launchWindowWhenDaemonHasStarted, 500);
}
else {
console.log(res);
createWindow();
}
}
);
}
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
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.
if (win === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

8
electron/package.json Normal file
View file

@ -0,0 +1,8 @@
{
"name": "LBRY",
"version": "0.1.0",
"main": "main.js",
"dependencies": {
"jayson": "^2.0.2"
}
}

4
lbrynet/lbry.py Normal file
View file

@ -0,0 +1,4 @@
from lbrynet.lbrynet_daemon import DaemonControl
if __name__ == '__main__':
DaemonControl.start()