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:
@@ -98,15 +98,64 @@ exports.runApp = function(execPath, opts) {
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
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();
|
||||
try {
|
||||
|
||||
if(opts.clearFreeDesktopFlags) {
|
||||
execPath = exports.clearFreeDesktopFlags(execPath);
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user