mirror of
https://github.com/nuintun/command-manager.git
synced 2025-06-07 19:44:35 +08:00
update files
This commit is contained in:
parent
53891db655
commit
b82707608e
@ -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()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
199
main.js
199
main.js
@ -4,134 +4,91 @@
|
|||||||
|
|
||||||
'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;
|
app.quit();
|
||||||
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
|
// this method will be called when atom-shell has done everything
|
||||||
app.on('window-all-closed', function (){
|
// initialization and ready for creating browser windows
|
||||||
app.quit();
|
app.on('ready', function (){
|
||||||
});
|
// create the tray window
|
||||||
|
mainTray = new Tray(ICON);
|
||||||
|
|
||||||
// this method will be called when atom-shell has done everything
|
mainTray.setToolTip(APPNAME);
|
||||||
// initialization and ready for creating browser windows
|
mainTray.setContextMenu(Menu.buildFromTemplate([
|
||||||
app.on('ready', function (){
|
{
|
||||||
// create the tray window
|
label: '显示窗口',
|
||||||
mainTray = new Tray(ICON);
|
click: function (){
|
||||||
|
mainWindow.show();
|
||||||
mainTray.setToolTip(APPNAME);
|
|
||||||
mainTray.setContextMenu(Menu.buildFromTemplate([
|
|
||||||
{
|
|
||||||
label: '显示窗口',
|
|
||||||
click: function (){
|
|
||||||
mainWindow.show();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '退出程序',
|
|
||||||
click: function (){
|
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]));
|
},
|
||||||
|
{
|
||||||
|
label: '退出程序',
|
||||||
|
click: function (){
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]));
|
||||||
|
|
||||||
// create the browser window
|
// create the browser window
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1024,
|
width: 1024,
|
||||||
height: 768,
|
height: 768,
|
||||||
icon: ICON,
|
icon: ICON,
|
||||||
'min-width': 1024,
|
'min-width': 1024,
|
||||||
'min-height': 768,
|
'min-height': 768,
|
||||||
title: APPNAME,
|
title: APPNAME,
|
||||||
frame: false,
|
frame: false,
|
||||||
center: true,
|
center: true,
|
||||||
'use-content-size': 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();
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
var Emulator = require('./bin/emulator');
|
|
||||||
|
|
||||||
process.on('message', function (project){
|
// and load the index.html of the app
|
||||||
var stream;
|
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({
|
mainTray = null;
|
||||||
cwd: project.path,
|
mainWindow = null;
|
||||||
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()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
// window control
|
||||||
|
windowControl(ICON, mainWindow, mainTray);
|
||||||
|
|
||||||
|
// open directory
|
||||||
|
openDirectory(mainWindow);
|
||||||
|
|
||||||
|
// app configure
|
||||||
|
new AppConfigure(mainWindow, mainTray);
|
||||||
|
|
||||||
|
// emulator start
|
||||||
|
thread.start();
|
||||||
|
});
|
@ -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;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user