cpu() fix, code cleanup

This commit is contained in:
Sebastian Hildebrandt
2019-02-08 18:05:56 +01:00
parent 459eb99a7f
commit 6790fb531e
4 changed files with 20 additions and 7 deletions
+11 -4
View File
@@ -293,7 +293,7 @@ function getCpu() {
}
if (result.speed === '0.00') {
let current = getCpuCurrentSpeedSync();
if (current !== '0.00') result.speed = current.avg.toFixed(2);
if (current.avg !== 0) result.speed = current.avg.toFixed(2);
}
_cpu_speed = result.speed;
result.speedmin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
@@ -374,7 +374,7 @@ function getCpu() {
}
if (result.speed === '0.00') {
let current = getCpuCurrentSpeedSync();
if (current !== '0.00') result.speed = current.avg.toFixed(2);
if (current.avg !== 0) result.speed = current.avg.toFixed(2);
}
_cpu_speed = result.speed;
result.speedmin = '';
@@ -575,8 +575,15 @@ function cpuCurrentspeed(callback) {
return new Promise((resolve) => {
process.nextTick(() => {
let result = getCpuCurrentSpeedSync();
if (result === 0 && _cpu_speed !== '0.00') result = parseFloat(_cpu_speed);
if (result.avg === 0 && _cpu_speed !== '0.00') {
const currCpuSpeed = parseFloat(_cpu_speed);
result = {
min: currCpuSpeed,
max: currCpuSpeed,
avg: currCpuSpeed,
cores: []
}
}
if (callback) { callback(result); }
resolve(result);
});