Skip to content

Commit

Permalink
添加任务管理类.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvkens committed Mar 21, 2018
1 parent 379bf94 commit fd0dac2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"license": "MIT",
"dependencies": {
"npm":"^5.7.1",
"uba":"^2.3.5"
"uba":"^2.3.7"
}
}
7 changes: 3 additions & 4 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import { app, BrowserWindow, Menu, shell, ipcMain, globalShortcut } from 'electron';
import * as t from './term';
import createWindow from './createWindow';
import configureMenu from './menu';
import ipc from './ipc';
Expand All @@ -27,16 +26,16 @@ const onReady = () => {
app.on('ready', onReady);

app.on('will-quit', (event) => {
t.killAllTerm();
tasks.killAllTasks();
});
app.on('quit', (event) => {
t.killAllTerm();
tasks.killAllTasks();
});
app.on('window-all-closed', () => {
// if (process.platform !== 'darwin') {
// app.quit();
// }
t.killAllTerm();
tasks.killAllTasks();
app.quit();
});

Expand Down
3 changes: 2 additions & 1 deletion src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const IPC = () => {
ipcMain.on('uba::run::stop', (event, item) => {
console.log('接收停止杀进程');
// t.killAllTerm();
tasks.killAllTasks();
// tasks.killAllTasks();
tasks.killTasksPath(item.path);
});
/**
* 启动调试服务
Expand Down
25 changes: 20 additions & 5 deletions src/main/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Tasks {
* @param {*} path 执行路径
* @returns null 没有找到 否则返回终端
*/
getTasks(path){
getTasks(path) {
if (Tasks.tasks.has(path)) {
return Tasks.tasks.get(path);
}
Expand All @@ -54,30 +54,45 @@ class Tasks {
* @param {*} path 删除的路径
* @returns true 删除成功 false 删除失败
*/
removeTasks(path){
removeTasks(path) {
return Tasks.tasks.delete(path);
}
/**
* @description 获得当前运行任务数
* @returns number 任务数量
*/
getTasksCounts(){
getTasksCounts() {
return Tasks.tasks.size;
}
/**
* @description 获得所有任务终端
* @returns Map
*/
getAllTasks(){
getAllTasks() {
return Tasks.tasks;
}
/**
* @description 杀死所有任务进程
*/
killAllTasks(){
killAllTasks() {
for (let term of Tasks.tasks.values()) {
term.kill();
}
Tasks.tasks.clear();
}
/**
* @description 杀死进程指定path
* @param {*} path 结束任务的路径
* @returns true 成功结束 false 失败没有找到
*/
killTasksPath(path) {
if (Tasks.tasks.has(path)) {
Tasks.tasks.get(path).kill();
this.removeTasks(path);
return true;
}else{
return false
}
}
}

Expand Down
54 changes: 0 additions & 54 deletions src/main/term.js

This file was deleted.

0 comments on commit fd0dac2

Please sign in to comment.