Explorar el Código

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
develop
wpetit hace 2 años
padre
commit
ef57e28dab
Se han modificado 3 ficheros con 73 adiciones y 11 borrados
  1. +8
    -2
      src/components/launcher/launcher-view.js
  2. +9
    -2
      src/store/actions/launcher.js
  3. +56
    -7
      src/util/system.js

+ 8
- 2
src/components/launcher/launcher-view.js Ver fichero

@@ -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');

+ 9
- 2
src/store/actions/launcher.js Ver fichero

@@ -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

+ 56
- 7
src/util/system.js Ver fichero

@@ -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);
});

});
};


Cargando…
Cancelar
Guardar