cpu() fix, code cleanup
This commit is contained in:
+11
-4
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user