Démarrage des applications en mode daemon

Les applications sont désormais lancées en mode "détachées".
Une limite "dure" de 2 secondes est appliquées pour l'animation de lancement sur les tuiles.

Fixes #5
This commit is contained in:
wpetit 2017-07-24 14:58:05 +02:00
parent 53431deba9
commit ef57e28dab
3 changed files with 73 additions and 11 deletions

View File

@ -104,10 +104,16 @@ var LauncherView = React.createClass({
var el = evt.currentTarget;
el.classList.add('pulse');
let startAnim = Date.now();
let endAnim = startAnim + 2000;
this.props.dispatch(actions.launcher.runApp(item.exec))
.then(function() {
el.classList.remove('pulse');
let now = Date.now();
if(endAnim > now) {
setTimeout(() => el.classList.remove('pulse'), endAnim - now)
} else {
el.classList.remove('pulse')
}
})
.catch(function() {
el.classList.remove('pulse');

View File

@ -1,6 +1,7 @@
var Util = require('../../util');
var logger = Util.Logger;
var remote = require('electron').Remote;
var LoggerStream = Util.LoggerStream;
var remote = require('electron').remote;
var RUN_APP = exports.RUN_APP = 'RUN_APP';
var RUN_APP_SUCCESS = exports.RUN_APP_SUCCESS = 'RUN_APP_SUCCESS';
@ -14,7 +15,13 @@ exports.runApp = function(execPath) {
dispatch({ type: RUN_APP, execPath: execPath });
return Util.System.runApp(execPath, { clearFreeDesktopFlags: true })
var opts = {
clearFreeDesktopFlags: true,
stdout: process.stdout,
stderr: process.stderr
}
return Util.System.runApp(execPath, opts)
.then(function() {
dispatch({ type: RUN_APP_SUCCESS, execPath: execPath });
// Hypothetical fix

View File

@ -98,15 +98,64 @@ exports.runApp = function(execPath, opts) {
opts = opts || {};
return new Promise(function(resolve, reject) {
try {
if(opts.clearFreeDesktopFlags) {
execPath = exports.clearFreeDesktopFlags(execPath);
}
return new Promise(function(resolve, reject) {
cp.exec(execPath, function(err) {
if(err) return reject(err);
return resolve();
var isDev = process.env.NODE_ENV === 'development';
var child = cp.spawn(execPath, {
detached: true,
shell: true,
stdio: [
'ignore',
isDev ? process.stdout : 'ignore',
isDev ? process.stderr : 'ignore'
]
});
// Detach the child process
child.unref();
} catch(err) {
return reject(err);
}
// Execute the rest after all I/O operations in this tick
let immediateId = setImmediate(() => {
// We do not want to be notified of child events after launch
child.removeAllListeners();
try {
// Check if the child process is still alive, should throw otherwise
child.kill(0);
} catch(err) {
return reject(err);
}
return resolve(child);
});
// If the child process exit with an exit code != 0, reject the promise
child.once('close', code => {
if(code === 0) return;
clearImmediate(immediateId);
child.removeAllListeners();
return reject(`Program exited with a exit code "${code}"`);
});
// If an error occurs during the process launch, reject the promise
child.once('error', err => {
clearImmediate(immediateId);
child.removeAllListeners();
return reject(err);
});
});
};