update files

This commit is contained in:
nuintun 2015-12-03 19:22:43 +08:00
parent 53891db655
commit b82707608e
4 changed files with 136 additions and 145 deletions

View File

@ -69,4 +69,40 @@ function normalizeExecArgs(command, options){
}; };
} }
module.exports = Emulator; // thread
process.on('message', function (project){
var stream;
var emulator = new Emulator({
cwd: project.path,
command: project.command.value
});
stream = emulator.start();
stream.stdout.on('data', function (data){
process.send({
event: 'data',
project: project,
data: data.toString()
});
});
stream.stderr.on('data', function (error){
emulator.stop();
process.send({
event: 'error',
project: project,
data: error.toString()
});
});
stream.on('close', function (signal){
emulator.stop();
process.send({
event: 'close',
project: project,
data: signal.toString()
});
});
});

View File

@ -4,24 +4,24 @@
'use strict'; 'use strict';
var cluster = require('cluster'); var path = require('path');
var ipc = require('ipc-main'); var ipc = require('ipc-main');
var fork = require('child_process').fork;
// cache // cache
var workers = {}; var threads = {};
/** /**
* killWorker * killThread
* @param name * @param name
*/ */
function killWorker(name){ function killThread(name){
var worker = workers[name]; var thread = threads[name];
if (worker && !worker.isDead()) { if (thread && thread.connected) {
worker.kill('SIGTERM'); thread.kill('SIGTERM');
delete workers[name]; delete threads[name];
} }
} }
@ -29,11 +29,11 @@ module.exports = {
start: function (){ start: function (){
ipc.on('emulator', function (event, project, action){ ipc.on('emulator', function (event, project, action){
var key = project.name + '-' + project.command.name; var key = project.name + '-' + project.command.name;
var worker = workers[key]; var thread = threads[key];
switch (action) { switch (action) {
case 'start': case 'start':
if (!worker || worker.isDead()) { if (!thread || !thread.connected) {
var env = {}; var env = {};
Object.keys(process.env).forEach(function (key){ Object.keys(process.env).forEach(function (key){
@ -44,29 +44,31 @@ module.exports = {
env[item.name] = item.value; env[item.name] = item.value;
}); });
worker = cluster.fork(env); thread = fork(path.join(__dirname, 'emulator'), {
env: env
});
worker.on('message', function (message){ thread.on('message', function (message){
event.sender.send('emulator', message.event, message.project, message.data); event.sender.send('emulator', message.event, message.project, message.data);
}); });
worker.on('error', function (){ thread.on('error', function (){
killWorker(project.name); killThread(project.name);
}); });
delete project.env; delete project.env;
worker.send(project); thread.send(project);
workers[project.name] = worker; threads[project.name] = thread;
} else { } else {
delete project.env; delete project.env;
worker.send(project); thread.send(project);
} }
break; break;
case 'stop': case 'stop':
killWorker(project.name); killThread(project.name);
break; break;
} }
}); });

99
main.js
View File

@ -4,40 +4,37 @@
'use strict'; 'use strict';
var cluster = require('cluster'); // node module
var path = require('path');
// module to control application life
var app = require('app');
var Menu = require('menu');
var Tray = require('tray');
// module to create native browser window
var BrowserWindow = require('browser-window');
// custom module
var windowControl = require('./bin/window-control');
var openDirectory = require('./bin/open-directory');
var AppConfigure = require('./bin/app-configure');
var thread = require('./bin/thread');
if (cluster.isMaster) { // keep a global reference of the window object, if you don't, the window will
// node module // be closed automatically when the javascript object is GCed
var path = require('path'); var mainTray = null;
// module to control application life var mainWindow = null;
var app = require('app'); // const var
var Menu = require('menu'); const APPNAME = '命令管理器';
var Tray = require('tray'); const ICON = path.join(__dirname, './app.ico');
// module to create native browser window const INDEX = 'file:///' + path.join(__dirname, 'index.html');
var BrowserWindow = require('browser-window');
// custom module
var windowControl = require('./bin/window-control');
var openDirectory = require('./bin/open-directory');
var AppConfigure = require('./bin/app-configure');
var thread = require('./bin/thread');
// keep a global reference of the window object, if you don't, the window will // quit when all windows are closed
// be closed automatically when the javascript object is GCed app.on('window-all-closed', function (){
var mainTray = null;
var mainWindow = null;
// const var
const APPNAME = '命令管理器';
const ICON = path.join(__dirname, './app.ico');
const INDEX = 'file:///' + path.join(__dirname, 'index.html');
// quit when all windows are closed
app.on('window-all-closed', function (){
app.quit(); app.quit();
}); });
// this method will be called when atom-shell has done everything // this method will be called when atom-shell has done everything
// initialization and ready for creating browser windows // initialization and ready for creating browser windows
app.on('ready', function (){ app.on('ready', function (){
// create the tray window // create the tray window
mainTray = new Tray(ICON); mainTray = new Tray(ICON);
@ -94,44 +91,4 @@ if (cluster.isMaster) {
// emulator start // emulator start
thread.start(); thread.start();
}); });
} else {
var Emulator = require('./bin/emulator');
process.on('message', function (project){
var stream;
var emulator = new Emulator({
cwd: project.path,
command: project.command.value
});
stream = emulator.start();
stream.stdout.on('data', function (data){
process.send({
event: 'data',
project: project,
data: data.toString()
});
});
stream.stderr.on('data', function (error){
emulator.stop();
process.send({
event: 'error',
project: project,
data: error.toString()
});
});
stream.on('close', function (signal){
emulator.stop();
process.send({
event: 'close',
project: project,
data: signal.toString()
});
});
});
}

View File

@ -494,7 +494,3 @@ header [class*=" icon-"] {
height: calc(100% - 32px); height: calc(100% - 32px);
background: url(../images/no-data.png) center no-repeat; background: url(../images/no-data.png) center no-repeat;
} }
.ui-terminal-cursor {
background: #fff;
color: #181818;
}