diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f751d5..b9a192c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | +| 5.18.6 | 2023-06-28 | `graphics()` fixed catched errors (mac OS) | | 5.18.5 | 2023-06-26 | `cpu()` fixed parsing (mac OS) | | 5.18.4 | 2023-06-22 | `graphics()` fixed parsing (mac OS) | | 5.18.3 | 2023-06-09 | `tests` improved key handling, updated docs | diff --git a/docs/history.html b/docs/history.html index 6dfdfc9..41e55bf 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.18.6 + 2023-06-28 + graphics() fixed catch errors (mac OS) + 5.18.5 2023-06-26 diff --git a/docs/index.html b/docs/index.html index cf5d943..cebd754 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.18.5
+
New Version: 5.18.6
diff --git a/lib/filesystem.js b/lib/filesystem.js index 7aaaf1d..7be68ac 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -137,18 +137,26 @@ function fsSize(drive, callback) { } } if (_linux) { - cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL'; - execSync('cat /proc/mounts 2>/dev/null').toString().split('\n').filter(line => { - return line.startsWith('/'); - }).forEach((line) => { - osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('rw') >= 0; - }); + try { + cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL'; + execSync('cat /proc/mounts 2>/dev/null').toString().split('\n').filter(line => { + return line.startsWith('/'); + }).forEach((line) => { + osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('rw') >= 0; + }); + } catch (e) { + util.noop(); + } } if (_freebsd || _openbsd || _netbsd) { - cmd = 'df -lkPT'; - execSync('mount').toString().split('\n').forEach((line) => { - osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('read-only') === -1; - }); + try { + cmd = 'df -lkPT'; + execSync('mount').toString().split('\n').forEach((line) => { + osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('read-only') === -1; + }); + } catch (e) { + util.noop(); + } } exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) { let lines = filterLines(stdout); @@ -1075,10 +1083,14 @@ function diskLayout(callback) { } } catch (e) { // fallback to older version of lsblk - const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL').toString(); - let lines = blkStdoutToObject(out2).split('\n'); - const data = parseBlk(lines); - devices = data.filter(item => { return (item.type === 'disk') && item.size > 0 && ((item.model !== null && item.model !== '') || (item.mount === '' && item.label === '' && item.fsType === '')); }); + try { + const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL').toString(); + let lines = blkStdoutToObject(out2).split('\n'); + const data = parseBlk(lines); + devices = data.filter(item => { return (item.type === 'disk') && item.size > 0 && ((item.model !== null && item.model !== '') || (item.mount === '' && item.label === '' && item.fsType === '')); }); + } catch (e) { + util.noop(); + } } devices.forEach((device) => { let mediumType = ''; diff --git a/lib/graphics.js b/lib/graphics.js index 356d09e..0fbb9f9 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -669,39 +669,42 @@ function graphics(callback) { } catch (e) { util.noop(); } - stdout = execSync('defaults read /Library/Preferences/com.apple.windowserver.plist 2>/dev/null;defaults read /Library/Preferences/com.apple.windowserver.displays.plist 2>/dev/null; echo ""', { maxBuffer: 1024 * 20000 }); - const output = (stdout || '').toString(); - const obj = util.plistReader(output); - if (obj['DisplayAnyUserSets'] && obj['DisplayAnyUserSets']['Configs'] && obj['DisplayAnyUserSets']['Configs'][0] && obj['DisplayAnyUserSets']['Configs'][0]['DisplayConfig']) { - const current = obj['DisplayAnyUserSets']['Configs'][0]['DisplayConfig']; - let i = 0; - current.forEach((o) => { - if (o['CurrentInfo'] && o['CurrentInfo']['OriginX'] !== undefined && result.displays && result.displays[i]) { - result.displays[i].positionX = o['CurrentInfo']['OriginX']; - } - if (o['CurrentInfo'] && o['CurrentInfo']['OriginY'] !== undefined && result.displays && result.displays[i]) { - result.displays[i].positionY = o['CurrentInfo']['OriginY']; - } - i++; - }); + try { + stdout = execSync('defaults read /Library/Preferences/com.apple.windowserver.plist 2>/dev/null;defaults read /Library/Preferences/com.apple.windowserver.displays.plist 2>/dev/null; echo ""', { maxBuffer: 1024 * 20000 }); + const output = (stdout || '').toString(); + const obj = util.plistReader(output); + if (obj['DisplayAnyUserSets'] && obj['DisplayAnyUserSets']['Configs'] && obj['DisplayAnyUserSets']['Configs'][0] && obj['DisplayAnyUserSets']['Configs'][0]['DisplayConfig']) { + const current = obj['DisplayAnyUserSets']['Configs'][0]['DisplayConfig']; + let i = 0; + current.forEach((o) => { + if (o['CurrentInfo'] && o['CurrentInfo']['OriginX'] !== undefined && result.displays && result.displays[i]) { + result.displays[i].positionX = o['CurrentInfo']['OriginX']; + } + if (o['CurrentInfo'] && o['CurrentInfo']['OriginY'] !== undefined && result.displays && result.displays[i]) { + result.displays[i].positionY = o['CurrentInfo']['OriginY']; + } + i++; + }); + } + if (obj['DisplayAnyUserSets'] && obj['DisplayAnyUserSets'].length > 0 && obj['DisplayAnyUserSets'][0].length > 0 && obj['DisplayAnyUserSets'][0][0]['DisplayID']) { + const current = obj['DisplayAnyUserSets'][0]; + let i = 0; + current.forEach((o) => { + if ('OriginX' in o && result.displays && result.displays[i]) { + result.displays[i].positionX = o['OriginX']; + } + if ('OriginY' in o && result.displays && result.displays[i]) { + result.displays[i].positionY = o['OriginY']; + } + if (o['Mode'] && o['Mode']['BitsPerPixel'] !== undefined && result.displays && result.displays[i]) { + result.displays[i].pixelDepth = o['Mode']['BitsPerPixel']; + } + i++; + }); + } + } catch (e) { + util.noop(); } - if (obj['DisplayAnyUserSets'] && obj['DisplayAnyUserSets'].length > 0 && obj['DisplayAnyUserSets'][0].length > 0 && obj['DisplayAnyUserSets'][0][0]['DisplayID']) { - const current = obj['DisplayAnyUserSets'][0]; - let i = 0; - current.forEach((o) => { - if ('OriginX' in o && result.displays && result.displays[i]) { - result.displays[i].positionX = o['OriginX']; - } - if ('OriginY' in o && result.displays && result.displays[i]) { - result.displays[i].positionY = o['OriginY']; - } - if (o['Mode'] && o['Mode']['BitsPerPixel'] !== undefined && result.displays && result.displays[i]) { - result.displays[i].pixelDepth = o['Mode']['BitsPerPixel']; - } - i++; - }); - } - } if (callback) { callback(result); diff --git a/lib/osinfo.js b/lib/osinfo.js index 39573ed..11f2a00 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -788,23 +788,28 @@ function versions(apps, callback) { } if ({}.hasOwnProperty.call(appsObj.versions, 'python')) { if (_darwin) { - const stdout = execSync('sw_vers'); - const lines = stdout.toString().split('\n'); - const osVersion = util.getValue(lines, 'ProductVersion', ':'); - const gitHomebrewExists1 = fs.existsSync('/usr/local/Cellar/python'); - const gitHomebrewExists2 = fs.existsSync('/opt/homebrew/bin/python'); - if ((util.darwinXcodeExists() && util.semverCompare('12.0.1', osVersion) < 0) || gitHomebrewExists1 || gitHomebrewExists2) { - const cmd = gitHomebrewExists1 ? '/usr/local/Cellar/python -V 2>&1' : (gitHomebrewExists2 ? '/opt/homebrew/bin/python -V 2>&1' : 'python -V 2>&1'); - exec(cmd, function (error, stdout) { - if (!error) { - const python = stdout.toString().split('\n')[0] || ''; - appsObj.versions.python = python.toLowerCase().replace('python', '').trim(); - } + try { + const stdout = execSync('sw_vers'); + const lines = stdout.toString().split('\n'); + const osVersion = util.getValue(lines, 'ProductVersion', ':'); + const gitHomebrewExists1 = fs.existsSync('/usr/local/Cellar/python'); + const gitHomebrewExists2 = fs.existsSync('/opt/homebrew/bin/python'); + if ((util.darwinXcodeExists() && util.semverCompare('12.0.1', osVersion) < 0) || gitHomebrewExists1 || gitHomebrewExists2) { + const cmd = gitHomebrewExists1 ? '/usr/local/Cellar/python -V 2>&1' : (gitHomebrewExists2 ? '/opt/homebrew/bin/python -V 2>&1' : 'python -V 2>&1'); + exec(cmd, function (error, stdout) { + if (!error) { + const python = stdout.toString().split('\n')[0] || ''; + appsObj.versions.python = python.toLowerCase().replace('python', '').trim(); + } + functionProcessed(); + }); + } else { functionProcessed(); - }); - } else { + } + } catch (e) { functionProcessed(); } + } else { exec('python -V 2>&1', function (error, stdout) { if (!error) { diff --git a/lib/util.js b/lib/util.js index df27342..6db68ff 100644 --- a/lib/util.js +++ b/lib/util.js @@ -586,8 +586,12 @@ function smartMonToolsInstalled() { } } if (_linux || _darwin || _freebsd || _openbsd || _netbsd) { - const pathArray = execSync('which smartctl 2>/dev/null', execOptsWin).toString().split('\r\n'); - _smartMonToolsInstalled = pathArray.length > 0; + try { + const pathArray = execSync('which smartctl 2>/dev/null', execOptsWin).toString().split('\r\n'); + _smartMonToolsInstalled = pathArray.length > 0; + } catch (e) { + util.noop(); + } } return _smartMonToolsInstalled; }