diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f693a7..fa64db7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.42.4 | 2018-07-09 | `cpuTemperature()` bugfix parsing negative values | | 3.42.3 | 2018-07-05 | `services()` bugfix not finding services with capital letters | | 3.42.2 | 2018-07-03 | `users()` optimized results if lack of permissions | | 3.42.1 | 2018-07-03 | `versions()` bugfix git version macOS | diff --git a/lib/cpu.js b/lib/cpu.js index a11d1fc..3616509 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -184,8 +184,8 @@ function getCpu() { result.speed = parseFloat(result.speed.replace(/GHz+/g, '')).toFixed(2); _cpu_speed = result.speed; result = cpuBrandManufacturer(result); - result.speedmin = (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0 ).toFixed(2); - result.speedmax = (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0 ).toFixed(2); + result.speedmin = (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0).toFixed(2); + result.speedmax = (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0).toFixed(2); result.vendor = util.getValue(lines, 'machdep.cpu.vendor'); result.family = util.getValue(lines, 'machdep.cpu.family'); result.model = util.getValue(lines, 'machdep.cpu.model'); @@ -284,9 +284,9 @@ function getCpu() { result.voltage = isNaN(voltage) ? '' : voltage.toFixed(2); for (let i = 0; i < cache.length; i++) { lines = cache[i].split('\n'); - let cacheType = util.getValue(lines,'Socket Designation').toLowerCase().replace(' ', '-').split('-'); + let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-'); cacheType = cacheType.length ? cacheType[0] : ''; - const sizeParts = util.getValue(lines,'Installed Size').split(' '); + const sizeParts = util.getValue(lines, 'Installed Size').split(' '); let size = parseInt(sizeParts[0], 10); const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb'; size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1))); @@ -337,17 +337,17 @@ function getCpu() { if (!result.speed) { result.speed = result.speedmax; } - + let description = util.getValue(lines, 'description', '=').split(' '); for (let i = 0; i < description.length; i++) { - if (description[i].toLowerCase().startsWith('family') && (i+1) < description.length && description[i+1]) { - result.family = description[i+1]; + if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) { + result.family = description[i + 1]; } - if (description[i].toLowerCase().startsWith('model') && (i+1) < description.length && description[i+1]) { - result.model = description[i+1]; + if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) { + result.model = description[i + 1]; } - if (description[i].toLowerCase().startsWith('stepping') && (i+1) < description.length && description[i+1]) { - result.stepping = description[i+1]; + if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) { + result.stepping = description[i + 1]; } } } @@ -372,7 +372,7 @@ function getCpu() { }); }); } catch (e) { - resolve(result); + resolve(result); } } }); @@ -417,8 +417,8 @@ function getCpuCurrentSpeedSync() { avgFreq = avgFreq / cpus.length; return { min: parseFloat(((minFreq + 1) / 1000).toFixed(2)), - max: parseFloat(((maxFreq + 1) / 1000).toFixed(2)), - avg: parseFloat(((avgFreq + 1) / 1000).toFixed(2)) + max: parseFloat(((maxFreq + 1) / 1000).toFixed(2)), + avg: parseFloat(((avgFreq + 1) / 1000).toFixed(2)) }; } else { return { @@ -462,7 +462,7 @@ function cpuTemperature(callback) { if (!error) { let lines = stdout.toString().split('\n'); lines.forEach(function (line) { - let regex = /\+([^°]*)/g; + let regex = /[+-]([^°]*)/g; let temps = line.match(regex); if (line.split(':')[0].toUpperCase().indexOf('PHYSICAL') !== -1) { result.main = parseFloat(temps); @@ -478,8 +478,8 @@ function cpuTemperature(callback) { if (callback) { callback(result); } resolve(result); } else { - fs.stat('/sys/class/thermal/thermal_zone0/temp', function(err) { - if(err === null) { + fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) { + if (err === null) { exec('cat /sys/class/thermal/thermal_zone0/temp', function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); @@ -570,7 +570,7 @@ function cpuTemperature(callback) { }); } catch (e) { if (callback) { callback(result); } - resolve(result); + resolve(result); } } }); @@ -614,7 +614,7 @@ function cpuFlags(callback) { }); } catch (e) { if (callback) { callback(result); } - resolve(result); + resolve(result); } } if (_linux) { @@ -634,11 +634,11 @@ function cpuFlags(callback) { result = util.getValue(lines, 'features', ':', true).toLowerCase(); } if (callback) { callback(result); } - resolve(result); + resolve(result); }); } else { if (callback) { callback(result); } - resolve(result); + resolve(result); } }); } @@ -649,7 +649,7 @@ function cpuFlags(callback) { let parts = stdout.toString().split('\tFlags:'); const lines = parts.length > 1 ? parts[1].split('\tVersion:')[0].split['\n'] : []; lines.forEach(function (line) { - let flag = (line.indexOf('(') ? line .split('(')[0].toLowerCase() : '').trim().replace(/\t/g, ''); + let flag = (line.indexOf('(') ? line.split('(')[0].toLowerCase() : '').trim().replace(/\t/g, ''); if (flag) { flags.push(flag); } @@ -730,9 +730,9 @@ function cpuCache(callback) { } for (let i = 0; i < cache.length; i++) { const lines = cache[i].split('\n'); - let cacheType = util.getValue(lines,'Socket Designation').toLowerCase().replace(' ', '-').split('-'); + let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-'); cacheType = cacheType.length ? cacheType[0] : ''; - const sizeParts = util.getValue(lines,'Installed Size').split(' '); + const sizeParts = util.getValue(lines, 'Installed Size').split(' '); let size = parseInt(sizeParts[0], 10); const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb'; size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1))); @@ -812,7 +812,7 @@ function cpuCache(callback) { }); } catch (e) { if (callback) { callback(result); } - resolve(result); + resolve(result); } } });