关闭窗口自动杀进程

This commit is contained in:
fofolee
2022-04-22 22:28:24 +08:00
parent 76dd321ff6
commit 2b84ebdda3
5 changed files with 48 additions and 23 deletions

View File

@@ -8,6 +8,7 @@ const axios = require('axios');
const http = require('http');
const url = require('url')
const nodeFns = require("./lib/nodeFns")
const kill = require('tree-kill')
require('ses')
window._ = require("lodash")
@@ -97,8 +98,8 @@ window.quickcommand = {
},
// 关闭进程
kill: function(pid, signal = 'SIGTERM') {
process.kill(pid, signal)
kill: function(pid, signal = 'SIGTERM', cb) {
kill(pid, signal, cb)
},
// dom 解析
@@ -211,22 +212,22 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline,
}
let getCommandToLaunchTerminal = (cmdline, dir) => {
let cd = ''
if (utools.isWindows()) {
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
// 直接 existsSync wt.exe 无效
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
cmdline = cmdline.replace(/"/g, `\\"`)
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
} else {
cmdline = cmdline.replace(/"/g, `^"`)
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
command = `${cd} start "" cmd /k "${cmdline}"`
}
} else {
let cd = ''
if (utools.isWindows()) {
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
// 直接 existsSync wt.exe 无效
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
cmdline = cmdline.replace(/"/g, `\\"`)
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
} else {
cmdline = cmdline.replace(/"/g, `^"`)
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
command = `${cd} start "" cmd /k "${cmdline}"`
}
} else {
cmdline = cmdline.replace(/"/g, `\\"`)
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
if (fs.existsSync('/Applications/iTerm.app')) {
command = `osascript -e 'tell application "iTerm"
create window with default profile
@@ -606,6 +607,7 @@ window.runCodeFile = (cmd, option, terminal, callback) => {
// let stderr = err_chunks.join("");
// callback(stdout, stderr)
// })
return child
}
let httpServer
@@ -666,4 +668,4 @@ window.quickcommandHttpServer = () => {
run,
stop
}
}
}