mirror of
https://github.com/fofolee/uTools-ProcessKiller.git
synced 2025-06-08 06:16:21 +08:00
去掉更新检测
This commit is contained in:
parent
afbc1a73c5
commit
ef878d37c0
81
preload.js
81
preload.js
@ -1,50 +1,50 @@
|
||||
const os = require('os')
|
||||
const iconv = require('iconv-lite')
|
||||
const { spawn, exec } = require("child_process")
|
||||
const jschardet = require("jschardet")
|
||||
|
||||
//-------checkUpdate------
|
||||
const fs = require('fs')
|
||||
// const { dialog, BrowserWindow, nativeImage } = require('electron').remote
|
||||
// const { shell } = require('electron');
|
||||
const path = require("path")
|
||||
const { dialog, BrowserWindow, nativeImage } = require('electron').remote
|
||||
const { shell } = require('electron');
|
||||
|
||||
pluginInfo = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')));
|
||||
logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
|
||||
isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true
|
||||
|
||||
messageBox = (options, callback) => {
|
||||
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => {
|
||||
callback(index);
|
||||
})
|
||||
GetBinPath = ExeFile => {
|
||||
if (isDev) {
|
||||
return path.join(__dirname, 'bin', ExeFile)
|
||||
} else {
|
||||
return path.join(__dirname.replace(/(unsafe-\w+\.asar)/,'$1.unpacked'), 'bin', ExeFile)
|
||||
}
|
||||
}
|
||||
|
||||
open = url => {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
// ------------------------
|
||||
|
||||
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) => {
|
||||
// dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => {
|
||||
// callback(index);
|
||||
// })
|
||||
// }
|
||||
|
||||
// open = url => {
|
||||
// shell.openExternal(url);
|
||||
// }
|
||||
|
||||
powershell = (cmd, callback) => {
|
||||
const ps = spawn('powershell', ['-NoProfile', '-Command', cmd], { encoding: 'buffer' })
|
||||
let chunks = [], err_chunks = [], size = 0, err_size = 0;
|
||||
const ps = spawn('powershell', ['-Command', cmd], { encoding: 'buffer' })
|
||||
let chunks = [];
|
||||
let err_chunks = [];
|
||||
ps.stdout.on('data', chunk => {
|
||||
chunks.push(chunk);
|
||||
size += chunk.length;
|
||||
chunks.push(iconv.decode(chunk, 'cp936'))
|
||||
})
|
||||
ps.stderr.on('data', err_chunk => {
|
||||
err_chunks.push(err_chunk);
|
||||
err_size += err_chunk.length;
|
||||
err_chunks.push(iconv.decode(err_chunk, 'cp936'))
|
||||
})
|
||||
ps.on('close', code => {
|
||||
let stdout = Buffer.concat(chunks, size);
|
||||
stdout = stdout.length ? iconv.decode(stdout, jschardet.detect(stdout).encoding) : '';
|
||||
let stderr = Buffer.concat(err_chunks, err_size);
|
||||
stderr = stderr.length ? iconv.decode(stderr, jschardet.detect(stderr).encoding) : '';
|
||||
let stdout = chunks.join("");
|
||||
let stderr = err_chunks.join("");
|
||||
callback(stdout, stderr)
|
||||
})
|
||||
}
|
||||
@ -52,16 +52,23 @@ powershell = (cmd, callback) => {
|
||||
tasklist = (callback) => {
|
||||
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 && dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'error', title: '啊嘞?!', message: stderr })
|
||||
tasklist = JSON.parse(stdout);
|
||||
callback(tasklist);
|
||||
});
|
||||
})
|
||||
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();
|
||||
callback(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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user