better startup and process management

This commit is contained in:
Job Evers-Meltzer 2017-01-18 10:32:01 -06:00
parent c6104f9a21
commit cafe34cbdc
6 changed files with 32 additions and 33 deletions

View file

@ -15,6 +15,6 @@ install:
- pip install pyinstaller - pip install pyinstaller
- wget https://nodejs.org/dist/v6.9.4/node-v6.9.4.pkg - wget https://nodejs.org/dist/v6.9.4/node-v6.9.4.pkg
- sudo installer -pkg node-v6.9.4.pkg -target / - sudo installer -pkg node-v6.9.4.pkg -target /
- npm install electron-packager -g - sudo npm install electron-packager -g
- ./build.sh - ./build.sh
- electron-packager --electron-version=1.4.14 --overwrite electron LBRY - electron-packager --electron-version=1.4.14 --overwrite electron LBRY

View file

@ -2,6 +2,8 @@
An electron version of the LBRY application. An electron version of the LBRY application.
This repo uses submodules, so clone it using --recursive
## Setup ## Setup
The lbrynet needs to be installed along with pyinstaller, and you The lbrynet needs to be installed along with pyinstaller, and you

View file

@ -20,11 +20,13 @@ pyinstaller lbry.py -y --windowed --onefile --icon=../lbry/packaging/osx/lbry-os
cd ../lbry-web-ui cd ../lbry-web-ui
git fetch git fetch
git reset --hard origin/master git reset --hard origin/master
# git reset --hard origin/development
git cherry-pick 06224b1d2cf4bf1f63d95031502260dd9c3ec5c1 git cherry-pick 06224b1d2cf4bf1f63d95031502260dd9c3ec5c1
npm install npm install
node_modules/.bin/node-sass --output dist/css --sourcemap=none scss/ node_modules/.bin/node-sass --output dist/css --sourcemap=none scss/
webpack node_modules/.bin/webpack
git reset --hard origin/master git reset --hard origin/master
# git reset --hard origin/development
cd .. cd ..
cp -R lbry-web-ui/dist electron/ cp -R lbry-web-ui/dist electron/

View file

@ -11,15 +11,14 @@ let subpy
function createWindow () { function createWindow () {
// Create the browser window. // Create the browser window.
win = new BrowserWindow({width: 800, height: 600}) //win = new BrowserWindow({x: 0, y: 0, width: 1440, height: 414, backgroundColor: '#155b4a'})
win = new BrowserWindow({backgroundColor: '#155b4a'})
win.maximize() win.maximize()
//win.webContents.openDevTools()
// and load the index.html of the app. // and load the index.html of the app.
win.loadURL(`file://${__dirname}/dist/index.html`) 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. // Emitted when the window is closed.
win.on('closed', () => { win.on('closed', () => {
@ -27,39 +26,28 @@ function createWindow () {
// in an array if your app supports multi windows, this is the time // in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element. // when you should delete the corresponding element.
win = null win = null
console.log('Loaded the index page')
subpy.kill('SIGINT');
}) })
};
function lauchDaemon() {
// TODO: check if the daemon is already running
subpy = require('child_process').spawn(`${__dirname}/dist/lbry`, ['--no-launch', '--log-to-console'], {stdio: ['ignore', process.stdout, process.stderr]})
subpy.on('exit', () => {
console.log('The daemon has exited. Quitting the app');
subpy = null;
app.quit();
});
console.log('lbrynet daemon has launched')
} }
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', function(){ app.on('ready', function(){
// call python? lauchDaemon();
subpy = require('child_process').spawn(`${__dirname}/dist/lbry`, ['--no-launch', '--log-to-console'], {stdio: ['ignore', process.stdout, process.stderr]}) createWindow();
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. // Quit when all windows are closed.
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
@ -70,6 +58,13 @@ app.on('window-all-closed', () => {
} }
}) })
app.on('before-quit', (event) => {
if (subpy != null) {
event.preventDefault()
subpy.kill('SIGINT');
}
})
app.on('activate', () => { app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the // 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. // dock icon is clicked and there are no other windows open.

2
lbry

@ -1 +1 @@
Subproject commit 8a026071eb1734d83c457e092b0676030026d9cd Subproject commit 91d673a539f5943cc219d9bec270fa840fa0895c

@ -1 +1 @@
Subproject commit b78b644826d0077417bfa3b35dcd17db4b1faedc Subproject commit 2aa10261d957a73144b86c2ecc70b71b8f7869e7