去掉更新检测

This commit is contained in:
fofolee 2020-04-19 18:03:46 +08:00
parent afbc1a73c5
commit ef878d37c0

View File

@ -1,50 +1,50 @@
const os = require('os') const os = require('os')
const iconv = require('iconv-lite') const iconv = require('iconv-lite')
const { spawn, exec } = require("child_process") const { spawn, exec } = require("child_process")
const jschardet = require("jschardet") // const { dialog, BrowserWindow, nativeImage } = require('electron').remote
// const { shell } = require('electron');
//-------checkUpdate------
const fs = require('fs')
const path = require("path") 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'))); isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true
logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
messageBox = (options, callback) => { GetBinPath = ExeFile => {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => { if (isDev) {
callback(index); 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; isWin = os.platform() == 'win32' ? true : false;
getIco = isWin ? require('icon-extractor') : require('file-icon'); 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) => { powershell = (cmd, callback) => {
const ps = spawn('powershell', ['-NoProfile', '-Command', cmd], { encoding: 'buffer' }) const ps = spawn('powershell', ['-Command', cmd], { encoding: 'buffer' })
let chunks = [], err_chunks = [], size = 0, err_size = 0; let chunks = [];
let err_chunks = [];
ps.stdout.on('data', chunk => { ps.stdout.on('data', chunk => {
chunks.push(chunk); chunks.push(iconv.decode(chunk, 'cp936'))
size += chunk.length;
}) })
ps.stderr.on('data', err_chunk => { ps.stderr.on('data', err_chunk => {
err_chunks.push(err_chunk); err_chunks.push(iconv.decode(err_chunk, 'cp936'))
err_size += err_chunk.length;
}) })
ps.on('close', code => { ps.on('close', code => {
let stdout = Buffer.concat(chunks, size); let stdout = chunks.join("");
stdout = stdout.length ? iconv.decode(stdout, jschardet.detect(stdout).encoding) : ''; let stderr = err_chunks.join("");
let stderr = Buffer.concat(err_chunks, err_size);
stderr = stderr.length ? iconv.decode(stderr, jschardet.detect(stderr).encoding) : '';
callback(stdout, stderr) callback(stdout, stderr)
}) })
} }
@ -52,16 +52,23 @@ powershell = (cmd, callback) => {
tasklist = (callback) => { tasklist = (callback) => {
var tasklist = []; var tasklist = [];
if (isWin) { if (isWin) {
exec('net session > NULL && echo 1 || echo 0', (err, stdout, stderr) => { powershell("Get-Process | Format-List ProcessName,Path,Description", (stdout, stderr) => {
let isAdmin = parseInt(stdout), let tasks = stdout.trim().split('\r\n\r\n');
IncludeUserName = isAdmin ? '-IncludeUserName' : '', for (var task of tasks) {
UserName = isAdmin ? ',UserName' : ''; dict = {}
powershell(`Get-Process ${IncludeUserName} | sort-object ws -descending | Select-Object ProcessName,Path,Description,WorkingSet${UserName} | ConvertTo-Json`, (stdout, stderr) => { let lines = task.split('\r\n')
stderr && dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'error', title: '啊嘞?!', message: stderr }) lines.forEach(line => {
tasklist = JSON.parse(stdout); 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); callback(tasklist);
}); });
})
} else { } else {
exec('ps -A -o pid -o %cpu -o %mem -o user -o comm | sed 1d | sort -rnk 3', (err, stdout, stderr) => { 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'); lines = stdout.split('\n');