From cafe34cbdce6040ed43bacbca540a6eb00b3a26c Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Wed, 18 Jan 2017 10:32:01 -0600 Subject: [PATCH] better startup and process management --- .travis.yml | 2 +- README.md | 2 ++ build.sh | 4 +++- electron/main.js | 53 ++++++++++++++++++++++-------------------------- lbry | 2 +- lbry-web-ui | 2 +- 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83c8a0743..36a29909e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,6 @@ install: - pip install pyinstaller - wget https://nodejs.org/dist/v6.9.4/node-v6.9.4.pkg - sudo installer -pkg node-v6.9.4.pkg -target / - - npm install electron-packager -g + - sudo npm install electron-packager -g - ./build.sh - electron-packager --electron-version=1.4.14 --overwrite electron LBRY diff --git a/README.md b/README.md index 4e9e510b2..81bbccaf1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ An electron version of the LBRY application. +This repo uses submodules, so clone it using --recursive + ## Setup The lbrynet needs to be installed along with pyinstaller, and you diff --git a/build.sh b/build.sh index fe4435a9f..3e654dc30 100755 --- a/build.sh +++ b/build.sh @@ -20,11 +20,13 @@ pyinstaller lbry.py -y --windowed --onefile --icon=../lbry/packaging/osx/lbry-os cd ../lbry-web-ui git fetch git reset --hard origin/master +# git reset --hard origin/development git cherry-pick 06224b1d2cf4bf1f63d95031502260dd9c3ec5c1 npm install 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/development cd .. cp -R lbry-web-ui/dist electron/ diff --git a/electron/main.js b/electron/main.js index 10d400359..a0fb29565 100644 --- a/electron/main.js +++ b/electron/main.js @@ -11,15 +11,14 @@ let subpy function createWindow () { // 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.webContents.openDevTools() + // 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', () => { @@ -27,39 +26,28 @@ function createWindow () { // 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'); }) +}; + +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 // 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(); + lauchDaemon(); + createWindow(); }) -// 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', () => { @@ -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', () => { // 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. diff --git a/lbry b/lbry index 8a026071e..91d673a53 160000 --- a/lbry +++ b/lbry @@ -1 +1 @@ -Subproject commit 8a026071eb1734d83c457e092b0676030026d9cd +Subproject commit 91d673a539f5943cc219d9bec270fa840fa0895c diff --git a/lbry-web-ui b/lbry-web-ui index b78b64482..2aa10261d 160000 --- a/lbry-web-ui +++ b/lbry-web-ui @@ -1 +1 @@ -Subproject commit b78b644826d0077417bfa3b35dcd17db4b1faedc +Subproject commit 2aa10261d957a73144b86c2ecc70b71b8f7869e7