allow render process to trigger a shutdown
This commit is contained in:
parent
0f65170361
commit
f09bf620b2
3 changed files with 34 additions and 19 deletions
49
app/main.js
49
app/main.js
|
@ -1,4 +1,4 @@
|
||||||
const {app, BrowserWindow} = require('electron');
|
const {app, BrowserWindow, ipcMain} = require('electron');
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ let subpy
|
||||||
// set to true when the quitting sequence has started
|
// set to true when the quitting sequence has started
|
||||||
let quitting = false;
|
let quitting = false;
|
||||||
|
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow () {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
//win = new BrowserWindow({x: 0, y: 0, width: 1440, height: 414, backgroundColor: '#155b4a'})
|
//win = new BrowserWindow({x: 0, y: 0, width: 1440, height: 414, backgroundColor: '#155b4a'})
|
||||||
|
@ -44,7 +45,7 @@ function lauchDaemon() {
|
||||||
}
|
}
|
||||||
console.log(`${__dirname}`);
|
console.log(`${__dirname}`);
|
||||||
executable = path.join(__dirname, 'dist', 'lbrynet-daemon');
|
executable = path.join(__dirname, 'dist', 'lbrynet-daemon');
|
||||||
subpy = require('child_process').spawn(executable)//, {stdio: ['ignore', process.stdout, process.stderr]});
|
subpy = require('child_process').spawn(executable)
|
||||||
// Need to handle the data event instead of attaching to
|
// Need to handle the data event instead of attaching to
|
||||||
// process.stdout because the latter doesn't work. I believe on
|
// process.stdout because the latter doesn't work. I believe on
|
||||||
// windows it buffers stdout and we don't get any meaningful output
|
// windows it buffers stdout and we don't get any meaningful output
|
||||||
|
@ -56,6 +57,7 @@ function lauchDaemon() {
|
||||||
if (quitting) {
|
if (quitting) {
|
||||||
app.quit();
|
app.quit();
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: maybe it would be better to restart the daemon?
|
||||||
win.loadURL(`file://${__dirname}/dist/warning.html`);
|
win.loadURL(`file://${__dirname}/dist/warning.html`);
|
||||||
setTimeout(app.quit, 5000)
|
setTimeout(app.quit, 5000)
|
||||||
}
|
}
|
||||||
|
@ -71,9 +73,8 @@ app.on('ready', function(){
|
||||||
// an error its because its not running
|
// an error its because its not running
|
||||||
console.log('Checking for lbrynet daemon')
|
console.log('Checking for lbrynet daemon')
|
||||||
client.request(
|
client.request(
|
||||||
'status', [],
|
'status', [],
|
||||||
function (err, res) {
|
function (err, res) {
|
||||||
// Did it all work ?
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('lbrynet daemon needs to be launched')
|
console.log('lbrynet daemon needs to be launched')
|
||||||
lauchDaemon();
|
lauchDaemon();
|
||||||
|
@ -96,19 +97,14 @@ app.on('window-all-closed', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('before-quit', (event) => {
|
app.on('before-quit', (event) => {
|
||||||
if (subpy != null) {
|
if (subpy == null) {
|
||||||
event.preventDefault()
|
return
|
||||||
if (win) {
|
|
||||||
win.loadURL(`file://${__dirname}/dist/quit.html`);
|
|
||||||
}
|
|
||||||
quitting = true;
|
|
||||||
console.log('Killing lbrynet-daemon process');
|
|
||||||
kill(subpy.pid, undefined, (err) => {
|
|
||||||
console.log('Killed lbrynet-daemon process');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
shutdownDaemon();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
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.
|
||||||
|
@ -117,5 +113,24 @@ app.on('activate', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 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.
|
function shutdownDaemon() {
|
||||||
|
console.log('Shutdown triggered');
|
||||||
|
if (subpy == null) {
|
||||||
|
// TODO: In this case, we didn't start the process so I'm hesitant
|
||||||
|
// to shut it down. We might want to send a stop command
|
||||||
|
// though instead of just letting it run.
|
||||||
|
console.log('Not killing lbrynet because we did not start it')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (win) {
|
||||||
|
win.loadURL(`file://${__dirname}/dist/quit.html`);
|
||||||
|
}
|
||||||
|
quitting = true;
|
||||||
|
console.log('Killing lbrynet-daemon process');
|
||||||
|
kill(subpy.pid, undefined, (err) => {
|
||||||
|
console.log('Killed lbrynet-daemon process');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMain.on('shutdown', shutdownDaemon);
|
||||||
|
|
2
lbry
2
lbry
|
@ -1 +1 @@
|
||||||
Subproject commit 14b4c069696bede86bfd473f6e634000ad397661
|
Subproject commit a1650d7f036eec01364214985d471f9322e259cd
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5b454a383798f19aa11b661d770e183dc6b76336
|
Subproject commit 86351d17362148168507958d33aad6111fd634aa
|
Loading…
Reference in a new issue