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

199
main.js
View File

@ -4,134 +4,91 @@
'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) {
// 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');
// keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed
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');
// keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed
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();
});
// quit when all windows are closed
app.on('window-all-closed', function (){
app.quit();
});
// this method will be called when atom-shell has done everything
// initialization and ready for creating browser windows
app.on('ready', function (){
// create the tray window
mainTray = new Tray(ICON);
// this method will be called when atom-shell has done everything
// initialization and ready for creating browser windows
app.on('ready', function (){
// create the tray window
mainTray = new Tray(ICON);
mainTray.setToolTip(APPNAME);
mainTray.setContextMenu(Menu.buildFromTemplate([
{
label: '显示窗口',
click: function (){
mainWindow.show();
}
},
{
label: '退出程序',
click: function (){
app.quit();
}
mainTray.setToolTip(APPNAME);
mainTray.setContextMenu(Menu.buildFromTemplate([
{
label: '显示窗口',
click: function (){
mainWindow.show();
}
]));
},
{
label: '退出程序',
click: function (){
app.quit();
}
}
]));
// create the browser window
mainWindow = new BrowserWindow({
width: 1024,
height: 768,
icon: ICON,
'min-width': 1024,
'min-height': 768,
title: APPNAME,
frame: false,
center: true,
'use-content-size': true
});
// and load the index.html of the app
mainWindow.loadURL(INDEX);
// emitted when the window is closed
mainWindow.on('closed', function (){
// dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element
mainTray.destroy();
mainTray = null;
mainWindow = null;
});
// window control
windowControl(ICON, mainWindow, mainTray);
// open directory
openDirectory(mainWindow);
// app configure
new AppConfigure(mainWindow, mainTray);
// emulator start
thread.start();
// create the browser window
mainWindow = new BrowserWindow({
width: 1024,
height: 768,
icon: ICON,
'min-width': 1024,
'min-height': 768,
title: APPNAME,
frame: false,
center: true,
'use-content-size': true
});
} else {
var Emulator = require('./bin/emulator');
process.on('message', function (project){
var stream;
// and load the index.html of the app
mainWindow.loadURL(INDEX);
// emitted when the window is closed
mainWindow.on('closed', function (){
// dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element
mainTray.destroy();
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()
});
});
mainTray = null;
mainWindow = null;
});
}
// window control
windowControl(ICON, mainWindow, mainTray);
// open directory
openDirectory(mainWindow);
// app configure
new AppConfigure(mainWindow, mainTray);
// emulator start
thread.start();
});

View File

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