diff --git a/assets/index.js b/assets/index.js index 19d312e..c5f7b9c 100644 --- a/assets/index.js +++ b/assets/index.js @@ -6,7 +6,7 @@ CacheIcons = async tasks => { var noCaches = []; if (window.isWin) { for (var t of tasks) { - if (t.Path) { + if (/^[A-z]:\\/.test(t.Path)) { if (localStorage[basename(t.Path, '.exe')] == undefined && !noCaches.includes(t.Path)) noCaches.push(t.Path) } } @@ -63,23 +63,20 @@ search = (t, text) => { var taskinfo = ''; var icon; if (window.isWin) { - if (t.Path) { + if (/^[A-z]:\\/.test(t.Path)) { icon = localStorage[basename(t.Path, '.exe')] } else { icon = WINDOW_DEFAULT_ICON; } var n = (t.ProcessName + t.Description).toUpperCase(); if (n.includes(text)) { - var usr = t.UserName ? t.UserName.split('\\').pop() : '', - title = t.Description ? t.Description : t.ProcessName, - mem = (parseInt(t.WorkingSet) * 100 / window.totalMem).toFixed(2), - path = t.Path ? t.Path : ''; - taskinfo = `
-
${usr}
+ var mem = (parseInt(t.WorkingSet) * 100 / window.totalMem).toFixed(2); + // path = t.Path ? t.Path : ''; + taskinfo = `
-
${title}
+
${t.ProcessName}
M: ${mem}%
-
${path}
`; +
${t.Path}
`; } } else { if (t.app) { @@ -114,20 +111,23 @@ show = text => { utools.onPluginEnter( async ({ code, type, payload }) => { utools.setExpendHeight(0); - // if (window.isWin) { - // utools.setExpendHeight(50); - // $("#tasklist").html(`
Loading...
`); - // $(".load").animate({ "opacity": "0.3" }, 500) - // .animate({ "opacity": "1" }, 500); - // } var db = utools.db.get('iconCache'); if (db) { for (var key in db.data) { localStorage[key] = db.data[key] } } + var initTime = new Date().getTime(); window.tasks = await tasklist(); + var tasksLoadedTime = new Date().getTime(); + tasksLoadedTime -= initTime; + // 读取进程耗时 + console.log(tasksLoadedTime); await CacheIcons(tasks); + var iconsCachedTime = new Date().getTime(); + iconsCachedTime -= (tasksLoadedTime + initTime); + // 缓存图标耗时 + console.log(iconsCachedTime); show(''); utools.setSubInput(({ text }) => { window.text = text; @@ -143,9 +143,9 @@ utools.onPluginEnter( async ({ code, type, payload }) => { $("#tasklist").on('mousedown', '.taskinfo', function (e) { if (1 == e.which) { - kill($(this).attr('name')); + kill($(this).attr('id')); } else if (3 == e.which) { - kill($(this).attr('name'), $(this).children(".path").html().replace(/\\/g, '/')) + kill($(this).attr('id'), $(this).children(".path").html().replace(/\\/g, '/')) } }); @@ -161,9 +161,9 @@ $(document).keydown(e => { switch (e.keyCode) { case 13: if (event.shiftKey) { - kill($(".select").attr('name'), $(".select").children(".path").html().replace(/\\/g, '/')) + kill($(".select").attr('id'), $(".select").children(".path").html().replace(/\\/g, '/')) } else { - kill($(".select").attr('name')); + kill($(".select").attr('id')); } break; case 38: diff --git a/bin/ProcessKiller.exe b/bin/ProcessKiller.exe index 929d2e1..a3900c8 100644 Binary files a/bin/ProcessKiller.exe and b/bin/ProcessKiller.exe differ diff --git a/index.html b/index.html index d7d9c35..f4be667 100644 --- a/index.html +++ b/index.html @@ -11,9 +11,7 @@ -
-
Loading...
-
+
diff --git a/preload.js b/preload.js index 39af03e..c36b0f5 100644 --- a/preload.js +++ b/preload.js @@ -47,16 +47,24 @@ tasklist = () => { var tasklist = []; if (isWin) { - exec('net session > NULL && echo 1 || echo 0', (err, stdout, stderr) => { - let isAdmin = parseInt(stdout), - IncludeUserName = isAdmin ? '-IncludeUserName' : '', - UserName = isAdmin ? ',UserName' : ''; - powershell(`Get-Process ${IncludeUserName} | sort-object ws -descending | Select-Object ProcessName,Path,Description,WorkingSet${UserName} | ConvertTo-Json`, (stdout, stderr) => { - stderr && console.log(stderr); - tasklist = JSON.parse(stdout); - reslove(tasklist); + execFile(GetBinPath('ProcessKiller.exe'), ['getProcess'], { encoding: 'buffer' },(err, stdout, stderr) => { + err && reject(iconv.decode(stderr, 'gb18030')); + data = JSON.parse(iconv.decode(stdout, 'gb18030')); + data = data.sort((x,y) => { + return y.WorkingSet - x.WorkingSet; }); + reslove(data); }) + // exec('net session > NULL && echo 1 || echo 0', (err, stdout, stderr) => { + // let isAdmin = parseInt(stdout), + // IncludeUserName = isAdmin ? '-IncludeUserName' : '', + // UserName = isAdmin ? ',UserName' : ''; + // powershell(`Get-Process ${IncludeUserName} | sort-object ws -descending | Select-Object ProcessName,Path,Description,WorkingSet${UserName} | ConvertTo-Json`, (stdout, stderr) => { + // stderr && console.log(stderr); + // tasklist = JSON.parse(stdout); + // reslove(tasklist); + // }); + // }) } else { exec('ps -A -o pid -o %cpu -o %mem -o user -o comm | sed 1d | sort -rnk 3', (err, stdout, stderr) => { lines = stdout.split('\n'); @@ -97,7 +105,7 @@ taskkill = (task, path, callback) => { } } -findSecondIndex = (str, cha) => { +findThirdIndex = (str, cha) => { var x = str.indexOf(cha); var y = str.indexOf(cha, x + 1); var z = str.indexOf(cha, y + 1); @@ -109,10 +117,10 @@ icns2Base64 = icns => { buffer = fs.readFileSync(icns, Buffer) ImgHead = Buffer.from([0x89, 0x50, 0x4E, 0x47]) ImgTail = Buffer.from([0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82]) - var start = findSecondIndex(buffer, ImgHead); + var start = findThirdIndex(buffer, ImgHead); // var WidthPos = start + 18; // var ImgWidth = buffer.readInt16BE(WidthPos); - var end = findSecondIndex(buffer, ImgTail) + 8; + var end = findThirdIndex(buffer, ImgTail) + 8; var b64 = buffer.slice(start, end).toString('base64') return b64 } @@ -144,4 +152,19 @@ GetIcons = PathList => }) reslove(data) } - }) \ No newline at end of file + }) + +// var initTime = new Date().getTime(); +// powershell(`Get-Process | sort-object ws -descending | Select-Object ProcessName,Path,Description,WorkingSet | ConvertTo-Json`, (stdout, stderr) => { +// stderr && console.log(stderr); +// tasklist = JSON.parse(stdout); +// console.log(tasklist); +// var EndTime = new Date().getTime(); +// console.log(EndTime - initTime); +// }) + +// execFile(path.join('bin', 'ProcessKiller.exe'), ['getProcess'], (err, stdout, stderr) => { +// console.log(JSON.parse(stdout)); +// var EndTime = new Date().getTime(); +// console.log(EndTime - initTime); +// }) \ No newline at end of file