win下增加内存占比和进程用户并按内存排序

This commit is contained in:
fofolee
2019-05-03 20:35:19 +08:00
parent bd511c7a13
commit e9956c33d3
2 changed files with 16 additions and 23 deletions

View File

@@ -10,6 +10,8 @@ isWin = os.platform() == 'win32' ? true : false;
getIco = isWin ? require('icon-extractor') : require('file-icon');
totalMem = os.totalmem();
getLogo = () => nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
messageBox = (options, callback) => {
@@ -42,21 +44,8 @@ powershell = (cmd, callback) => {
tasklist = (callback) => {
var tasklist = [];
if (isWin) {
powershell("Get-Process | Format-List ProcessName,Path,Description", (stdout, stderr) => {
let tasks = stdout.trim().split('\r\n\r\n');
for (var task of tasks) {
dict = {}
let lines = task.split('\r\n')
lines.forEach(line => {
if (line) {
let key = line.split(/\s+:\s*/)[0];
let value = line.split(/\s+:\s*/)[1];
dict[key] = value;
}
})
tasklist.push(dict);
}
tasklist.shift();
powershell("Get-Process -IncludeUserName | sort-object ws -descending | Select-Object ProcessName,Path,Description,WorkingSet,UserName | ConvertTo-Json", (stdout, stderr) => {
tasklist = JSON.parse(stdout);
callback(tasklist);
});
} else {