mirror of
https://github.com/fofolee/uTools-ProcessKiller.git
synced 2025-07-24 23:19:31 +08:00
支持 linux
This commit is contained in:
parent
f4282a80a7
commit
02b80e839e
@ -3,7 +3,7 @@ const WINDOW_DEFAULT_ICON = './imgs/window.png'
|
||||
|
||||
CacheIcons = async tasks => {
|
||||
var noCaches = [];
|
||||
if (window.isWin) {
|
||||
if (utools.isWindows()) {
|
||||
for (var t of tasks) {
|
||||
if (/^[A-z]:\\/.test(t.Path)) {
|
||||
if (localStorage[basename(t.Path, '.exe')] == undefined && !noCaches.includes(t.Path)) noCaches.push(t.Path)
|
||||
@ -15,7 +15,7 @@ CacheIcons = async tasks => {
|
||||
localStorage[basename(i.path, '.exe')] = i.b64Ico;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
} else if(utools.isMacOs()){
|
||||
for (var t of tasks) {
|
||||
if (t.app) {
|
||||
if (localStorage[basename(t.app, '.app')] == undefined && !noCaches.includes(t.app)) noCaches.push(t.app)
|
||||
@ -31,16 +31,17 @@ CacheIcons = async tasks => {
|
||||
}
|
||||
|
||||
kill = async (pid, restart) => {
|
||||
await window.taskkill(pid, restart)
|
||||
tasks = await tasklist();
|
||||
show(tasks, window.text);
|
||||
if (window.taskkill(pid, restart)) {
|
||||
var tasks = await tasklist();
|
||||
show(tasks, window.text);
|
||||
}
|
||||
}
|
||||
|
||||
search = (t, text) => {
|
||||
text = text.toUpperCase();
|
||||
var taskinfo = '';
|
||||
var icon;
|
||||
if (window.isWin) {
|
||||
if (utools.isWindows()) {
|
||||
icon = WINDOW_DEFAULT_ICON
|
||||
if (/^[A-z]:\\/.test(t.Path)) {
|
||||
var cache = localStorage[basename(t.Path, '.exe')];
|
||||
@ -97,7 +98,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
||||
}
|
||||
}
|
||||
// var initTime = new Date().getTime();
|
||||
tasks = await tasklist();
|
||||
var tasks = await tasklist();
|
||||
if (tasks) {
|
||||
window.text = '';
|
||||
// 读取进程耗时
|
||||
@ -110,7 +111,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
||||
// iconsCachedTime -= (tasksLoadedTime + initTime);
|
||||
// console.log(iconsCachedTime);
|
||||
show(tasks, window.text);
|
||||
var sign = isWin ? 'Alt' : '⌘';
|
||||
var sign = utools.isMacOs() ? '⌘' : 'Alt';
|
||||
$('.numbers').html(`
|
||||
<div>${sign}+1</div>
|
||||
<div>${sign}+2</div>
|
||||
@ -127,7 +128,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
||||
utools.setSubInput(({ text }) => {
|
||||
window.text = text;
|
||||
show(tasks, text);
|
||||
}, '左/右键 -> 关闭/重启进程; ctrl + c/e/r -> 复制路径/在文件管理器中显示/重启');
|
||||
}, '左/右键 -> 关闭/重启进程; ctrl + c/e/r -> 复制路径/文件管理器中显示/重启');
|
||||
utools.onPluginOut(() => {
|
||||
var update = { _id: "iconCache", data: localStorage };
|
||||
if (db) update._rev = db._rev;
|
||||
@ -164,8 +165,13 @@ Mousetrap.bind('ctrl+c', () => {
|
||||
});
|
||||
|
||||
Mousetrap.bind('ctrl+e', () => {
|
||||
var path = $(".select").children(".path").text();
|
||||
open(path);
|
||||
var path
|
||||
if (utools.isLinux()) {
|
||||
path = getLinuxProcPath($(".select").attr('id'))
|
||||
} else {
|
||||
path = $(".select").children(".path").text();
|
||||
}
|
||||
if(path) open(path);
|
||||
return false
|
||||
});
|
||||
|
||||
@ -211,7 +217,7 @@ Mousetrap.bind('up', () => {
|
||||
return false
|
||||
});
|
||||
|
||||
key = isWin ? 'alt' : 'command'
|
||||
key = utools.isMacOs() ? 'command' : 'alt'
|
||||
|
||||
Mousetrap.bind([`${key}+1`], function (e) {
|
||||
var index = ($(window).scrollTop()) / 50;
|
||||
|
@ -47,7 +47,6 @@ compileFile = script => {
|
||||
}
|
||||
}
|
||||
|
||||
isWin = os.platform() == 'win32' ? true : false;
|
||||
|
||||
totalMem = os.totalmem();
|
||||
|
||||
@ -55,7 +54,7 @@ tasklist = () =>
|
||||
new Promise((reslove, reject) => {
|
||||
{
|
||||
var tasklist = [];
|
||||
if (isWin) {
|
||||
if (utools.isWindows()) {
|
||||
var binPath = GetFilePath('ProcessKiller.exe');
|
||||
if(!fs.existsSync(binPath)) compileFile('ProcessKiller.cs')
|
||||
execFile(binPath, ['getProcess'], { encoding: 'buffer' },(err, stdout, stderr) => {
|
||||
@ -66,7 +65,7 @@ tasklist = () =>
|
||||
});
|
||||
reslove(data);
|
||||
})
|
||||
} else {
|
||||
} else if(utools.isMacOs()){
|
||||
exec('ps -A -o pid -o %cpu -o %mem -o user -o comm | sed 1d | sort -rnk 3', (err, stdout, stderr) => {
|
||||
if(err) reject(utools.showNotification(stderr))
|
||||
lines = stdout.split('\n');
|
||||
@ -81,23 +80,52 @@ tasklist = () =>
|
||||
});
|
||||
reslove(tasklist);
|
||||
});
|
||||
} else {
|
||||
exec('ps -A -o pid -o %cpu -o %mem -o user -o comm:20 -o cmd | sed 1d | sort -rnk 3', (err, stdout, stderr) => {
|
||||
if(err) reject(utools.showNotification(stderr))
|
||||
lines = stdout.split('\n');
|
||||
lines.forEach(line => {
|
||||
if (line) {
|
||||
l = /(\d+)\s+(\d+[\.|\,]\d+)\s+(\d+[\.|\,]\d+)\s+(.*?)\s+(.{20})\s+(.*)/.exec(line);
|
||||
dict = { pid: l[1], cpu: l[2], mem: l[3], usr: l[4], path: l[6], nam: l[5].trim() }
|
||||
tasklist.push(dict);
|
||||
}
|
||||
});
|
||||
reslove(tasklist);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
taskkill = (pid, restart) =>
|
||||
new Promise((reslove, reject) => {
|
||||
getLinuxProcPath = pid => {
|
||||
try {
|
||||
return fs.readlinkSync(`/proc/${pid}/exe`)
|
||||
} catch (error) {
|
||||
utools.showNotification(error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
taskkill = (pid, restart) => {
|
||||
try {
|
||||
process.kill(pid);
|
||||
} catch (error) {
|
||||
utools.showNotification('权限不足,请以管理员权限运行uTools');
|
||||
return false
|
||||
}
|
||||
if(restart){
|
||||
var cmd = restart
|
||||
if (!utools.isLinux()) cmd = '"' + cmd + '"'
|
||||
try {
|
||||
process.kill(pid);
|
||||
} catch (error) {
|
||||
reject(utools.showNotification('权限不足,请以管理员权限运行uTools'));
|
||||
}
|
||||
if(restart){
|
||||
exec(cmd);
|
||||
utools.showNotification('重启进程成功!')
|
||||
exec(`"${restart}"`);
|
||||
} catch (error) {
|
||||
utools.showNotification(error);
|
||||
return false
|
||||
}
|
||||
reslove(true);
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
findThirdIndex = (str, cha) => {
|
||||
var x = str.indexOf(cha);
|
||||
@ -121,14 +149,14 @@ icns2Base64 = icns => {
|
||||
|
||||
GetIcons = PathList =>
|
||||
new Promise((reslove, reject) => {
|
||||
if (isWin) {
|
||||
if (utools.isWindows()) {
|
||||
PathList = PathList.join("|").replace("\\", "/");
|
||||
execFile(GetFilePath('ProcessKiller.exe'), ["getIcons", PathList],{ encoding: 'buffer' },(error, stdout, stderr) => {
|
||||
if(error) reject(utools.showNotification(iconv.decode(stderr, 'gb18030')));
|
||||
data = JSON.parse(iconv.decode(stdout, 'gb18030'));
|
||||
reslove(data);
|
||||
});
|
||||
} else {
|
||||
} else if(utools.isMacOs()){
|
||||
data = []
|
||||
PathList.forEach(p => {
|
||||
var InfoFile = path.join(p, 'Contents', 'Info.plist');
|
||||
@ -145,4 +173,4 @@ GetIcons = PathList =>
|
||||
})
|
||||
reslove(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user