graphics() added positionX, positionY (max OS)

This commit is contained in:
Sebastian Hildebrandt
2023-01-06 08:00:50 +01:00
parent e145a803a9
commit 21b1d62b21
76 changed files with 251 additions and 176 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -7,7 +7,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+50 -16
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
@@ -225,12 +225,12 @@ function graphics(callback) {
} catch (e) {
util.noop();
}
for (let i = 0; i < lines.length; i++) {
if ('' !== lines[i].trim()) {
if (' ' !== lines[i][0] && '\t' !== lines[i][0]) { // first line of new entry
let isExternal = (pciIDs.indexOf(lines[i].split(' ')[0]) >= 0);
let vgapos = lines[i].toLowerCase().indexOf(' vga ');
let _3dcontrollerpos = lines[i].toLowerCase().indexOf('3d controller');
lines.forEach((line) => {
if ('' !== line.trim()) {
if (' ' !== line[0] && '\t' !== line[0]) { // first line of new entry
let isExternal = (pciIDs.indexOf(line.split(' ')[0]) >= 0);
let vgapos = line.toLowerCase().indexOf(' vga ');
let _3dcontrollerpos = line.toLowerCase().indexOf('3d controller');
if (vgapos !== -1 || _3dcontrollerpos !== -1) { // VGA
if (_3dcontrollerpos !== -1 && vgapos === -1) {
vgapos = _3dcontrollerpos;
@@ -247,14 +247,14 @@ function graphics(callback) {
};
}
const pciIDCandidate = lines[i].split(' ')[0];
const pciIDCandidate = line.split(' ')[0];
if (/[\da-fA-F]{2}:[\da-fA-F]{2}\.[\da-fA-F]/.test(pciIDCandidate)) {
currentController.busAddress = pciIDCandidate;
}
isGraphicsController = true;
let endpos = lines[i].search(/\[[0-9a-f]{4}:[0-9a-f]{4}]|$/);
let parts = lines[i].substr(vgapos, endpos - vgapos).split(':');
currentController.busAddress = lines[i].substr(0, vgapos).trim();
let endpos = line.search(/\[[0-9a-f]{4}:[0-9a-f]{4}]|$/);
let parts = line.substr(vgapos, endpos - vgapos).split(':');
currentController.busAddress = line.substr(0, vgapos).trim();
if (parts.length > 1) {
parts[1] = parts[1].trim();
if (parts[1].toLowerCase().indexOf('corporation') >= 0) {
@@ -264,7 +264,7 @@ function graphics(callback) {
currentController.vram = null;
currentController.vramDynamic = false;
} else if (parts[1].toLowerCase().indexOf(' inc.') >= 0) {
if ((parts[1].match(new RegExp(']', 'g')) || []).length > 1) {
if ((parts[1].match(/]/g) || []).length > 1) {
currentController.vendor = parts[1].substr(0, parts[1].toLowerCase().indexOf(']') + 1).trim();
currentController.model = parts[1].substr(parts[1].toLowerCase().indexOf(']') + 1, 200).trim().split('(')[0].trim();
} else {
@@ -275,7 +275,7 @@ function graphics(callback) {
currentController.vram = null;
currentController.vramDynamic = false;
} else if (parts[1].toLowerCase().indexOf(' ltd.') >= 0) {
if ((parts[1].match(new RegExp(']', 'g')) || []).length > 1) {
if ((parts[1].match(/]/g) || []).length > 1) {
currentController.vendor = parts[1].substr(0, parts[1].toLowerCase().indexOf(']') + 1).trim();
currentController.model = parts[1].substr(parts[1].toLowerCase().indexOf(']') + 1, 200).trim().split('(')[0].trim();
} else {
@@ -290,7 +290,7 @@ function graphics(callback) {
}
}
if (isGraphicsController) { // within VGA details
let parts = lines[i].split(':');
let parts = line.split(':');
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('devicename') !== -1 && parts[1].toLowerCase().indexOf('onboard') !== -1) { currentController.bus = 'Onboard'; }
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('region') !== -1 && parts[1].toLowerCase().indexOf('memory') !== -1) {
let memparts = parts[1].split('=');
@@ -300,7 +300,8 @@ function graphics(callback) {
}
}
}
}
});
if (currentController.vendor || currentController.model || currentController.bus || currentController.busAddress || currentController.vram !== null || currentController.vramDynamic) { // already a controller found
controllers.push(currentController);
}
@@ -663,11 +664,44 @@ function graphics(callback) {
exec(cmd, function (error, stdout) {
if (!error) {
try {
let output = stdout.toString();
const output = stdout.toString();
result = parseLinesDarwin(util.plistParser(output)[0]._items);
} 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 ""');
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'] && 'OriginX' in o['CurrentInfo'] && result.displays && result.displays[i]) {
result.displays[i].positionX = o['CurrentInfo']['OriginX'];
}
if (o['CurrentInfo'] && 'OriginY' in o['CurrentInfo'] && 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 ('LimitsOriginX' in o && result.displays && result.displays[i]) {
result.displays[i].positionX = o['LimitsOriginX'];
}
if ('LimitsOriginY' in o && result.displays && result.displays[i]) {
result.displays[i].positionY = o['LimitsOriginY'];
}
if (o['Mode'] && 'BitsPerPixel' in o['Mode'] && result.displays && result.displays[i]) {
result.displays[i].pixelDepth = o['Mode']['BitsPerPixel'];
}
i++;
});
}
}
if (callback) {
callback(result);
+8 -1
View File
@@ -975,7 +975,14 @@ export function diskLayout(cb?: (data: Systeminformation.DiskLayoutData[]) => an
export function networkInterfaceDefault(cb?: (data: string) => any): Promise<string>;
export function networkGatewayDefault(cb?: (data: string) => any): Promise<string>;
export function networkInterfaces(cb?: (data: Systeminformation.NetworkInterfacesData[]) => any): Promise<Systeminformation.NetworkInterfacesData[]>;
export function networkInterfaces(
cb?:
| ((data: Systeminformation.NetworkInterfacesData[] | Systeminformation.NetworkInterfacesData) => any)
| boolean
| string,
rescan?: boolean,
defaultString?: string
): Promise<Systeminformation.NetworkInterfacesData[] | Systeminformation.NetworkInterfacesData>;
export function networkStats(ifaces?: string, cb?: (data: Systeminformation.NetworkStatsData[]) => any): Promise<Systeminformation.NetworkStatsData[]>;
export function networkConnections(cb?: (data: Systeminformation.NetworkConnectionsData[]) => any): Promise<Systeminformation.NetworkConnectionsData[]>;
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// Contributors: Guillaume Legrain (https://github.com/glegrain)
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+56 -13
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
@@ -118,22 +118,21 @@ function getValue(lines, property, separator, trimmed, lineMatch) {
property = property.toLowerCase();
trimmed = trimmed || false;
lineMatch = lineMatch || false;
for (let i = 0; i < lines.length; i++) {
let line = lines[i].toLowerCase().replace(/\t/g, '');
let result = '';
lines.forEach((line) => {
let lineLower = line.toLowerCase().replace(/\t/g, '');
if (trimmed) {
line = line.trim();
lineLower = lineLower.trim();
}
if (line.startsWith(property) && (lineMatch ? (line.match(property + separator)) : true)) {
const parts = trimmed ? lines[i].trim().split(separator) : lines[i].split(separator);
if (lineLower.startsWith(property) && (lineMatch ? (lineLower.match(property + separator)) : true)) {
const parts = trimmed ? line.trim().split(separator) : line.split(separator);
if (parts.length >= 2) {
parts.shift();
return parts.join(separator).trim();
} else {
return '';
result = parts.join(separator).trim();
}
}
}
return '';
});
return result;
}
function decodeEscapeSequence(str, base) {
@@ -722,7 +721,7 @@ function isPrototypePolluted() {
st.__proto__.toString = stringToString;
st.__proto__.substr = stringSubstr;
notPolluted = notPolluted || !(s.length === 62);
notPolluted = notPolluted || (s.length !== 62);
const ms = Date.now();
if (typeof ms === 'number' && ms > 1600000000000) {
const l = ms % 100 + 15;
@@ -733,7 +732,7 @@ function isPrototypePolluted() {
const q = Math.random() * 61.99999999 + 1;
const qs = parseInt(Math.floor(q).toString(), 10);
const qs2 = parseInt(q.toString().split('.')[0], 10);
notPolluted = notPolluted && !(r === q);
notPolluted = notPolluted && (r !== q);
notPolluted = notPolluted && rs === rs2 && qs === qs2;
st += s[rs - 1];
}
@@ -1188,6 +1187,49 @@ function plistParser(xmlStr) {
return metaData[0].data;
}
function strIsNumeric(str) {
return typeof str === 'string' && !isNaN(str) && !isNaN(parseFloat(str));
}
function plistReader(output) {
const lines = output.split('\n');
for (let i = 0; i < lines.length; i++) {
if (lines[i].indexOf(' = ') >= 0) {
const lineParts = lines[i].split(' = ');
lineParts[0] = lineParts[0].trim();
if (!lineParts[0].startsWith('"')) {
lineParts[0] = '"' + lineParts[0] + '"';
}
lineParts[1] = lineParts[1].trim();
if (lineParts[1].indexOf('"') === -1 && lineParts[1].endsWith(';')) {
const valueString = lineParts[1].substring(0, lineParts[1].length - 1);
if (!strIsNumeric(valueString)) {
lineParts[1] = `"${valueString}";`;
}
}
if (lineParts[1].indexOf('"') >= 0 && lineParts[1].endsWith(';')) {
const valueString = lineParts[1].substring(0, lineParts[1].length - 1).replace(/"/g, '');
if (strIsNumeric(valueString)) {
lineParts[1] = `${valueString};`;
}
}
lines[i] = lineParts.join(' : ');
}
lines[i] = lines[i].replace(/\(/g, '[').replace(/\)/g, ']').replace(/;/g, ',').trim();
if (lines[i].startsWith('}') && lines[i - 1] && lines[i - 1].endsWith(',')) {
lines[i - 1] = lines[i - 1].substring(0, lines[i - 1].length - 1);
}
}
output = lines.join('');
let obj = {};
try {
obj = JSON.parse(output);
} catch (e) {
noop();
}
return obj;
}
function semverCompare(v1, v2) {
let res = 0;
const parts1 = v1.split('.');
@@ -1247,6 +1289,7 @@ exports.promisifySave = promisifySave;
exports.smartMonToolsInstalled = smartMonToolsInstalled;
exports.linuxVersion = linuxVersion;
exports.plistParser = plistParser;
exports.plistReader = plistReader;
exports.stringReplace = stringReplace;
exports.stringToLower = stringToLower;
exports.stringToString = stringToString;
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
+1 -1
View File
@@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Copyright: (c) 2014 - 2023
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT