From 8acd0ece146e5256e5deef932e0a3dac3be5575b Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 18 Oct 2019 17:02:28 +0200 Subject: [PATCH] graphics() improving display detection (windows) --- lib/graphics.js | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/graphics.js b/lib/graphics.js index 9807fbc..70c8ae6 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -561,6 +561,7 @@ function graphics(callback) { workload.push(util.powerShell('Get-CimInstance -Namespace root\\wmi -ClassName WmiMonitorBasicDisplayParams | fl')); workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Screen]::AllScreens')); workload.push(util.powerShell('Get-CimInstance -Namespace root\\wmi -ClassName WmiMonitorConnectionParams | fl')); + workload.push(util.powerShell('gwmi WmiMonitorID -Namespace root\\wmi | ForEach-Object {(($_.ManufacturerName -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.ProductCodeID -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.UserFriendlyName -notmatch 0 | foreach {[char]$_}) -join "") + "|" + (($_.SerialNumberID -notmatch 0 | foreach {[char]$_}) -join "") + "|" + $_.InstanceName}')); Promise.all( workload @@ -587,19 +588,34 @@ function graphics(callback) { let tsections = data[4].split(/\n\s*\n/); tsections.shift(); - result.displays = parseLinesWindowsDisplaysPowershell(ssections, msections, dsections, tsections); + // monitor ID (powershell) - model / vendor + const res = data[5].split(/\r/); + let isections = []; + res.forEach(element => { + const parts = element.split('|'); + if (parts.length === 5) { + isections.push({ + vendor: parts[0], + code: parts[1], + model: parts[2], + serial: parts[3], + instanceId: parts[4] + }); + } + }); + result.displays = parseLinesWindowsDisplaysPowershell(ssections, msections, dsections, tsections, isections); if (result.controllers.length === 1 && result.displays.length === 1) { if (_resolutionx) { - result.displays[0].currentResX = _resolutionx; - if (!result.displays[0].resolutionx) { - result.displays[0].resolutionx = _resolutionx; + result.displays[0].resolutionx = _resolutionx; + if (!result.displays[0].currentResX) { + result.displays[0].currentResX = _resolutionx; } } if (_resolutiony) { - result.displays[0].currentResY = _resolutiony; - if (result.displays[0].resolutiony === 0) { - result.displays[0].resolutiony = _resolutiony; + result.displays[0].resolutiony = _resolutiony; + if (result.displays[0].currentResY === 0) { + result.displays[0].currentResY = _resolutiony; } } if (_pixeldepth) { @@ -677,7 +693,7 @@ function graphics(callback) { // return displays; // } - function parseLinesWindowsDisplaysPowershell(ssections, msections, dsections, tsections) { + function parseLinesWindowsDisplaysPowershell(ssections, msections, dsections, tsections, isections) { let displays = []; let vendor = ''; let model = ''; @@ -706,9 +722,17 @@ function graphics(callback) { const sizey = util.getValue(linesMonitor, 'MaxVerticalImageSize'); const instanceName = util.getValue(linesMonitor, 'InstanceName').toLowerCase(); const videoOutputTechnology = util.getValue(linesConnection, 'VideoOutputTechnology'); + let displayVendor = ''; + let displayModel = ''; + isections.forEach(element => { + if (element.instanceId.toLowerCase() === instanceName) { + displayVendor = element.vendor; + displayModel = element.model; + } + }); displays.push({ - vendor: instanceName.startsWith(deviceID) ? vendor : '', - model: instanceName.startsWith(deviceID) ? model : '', + vendor: instanceName.startsWith(deviceID) && displayVendor === '' ? vendor : displayVendor, + model: instanceName.startsWith(deviceID) && displayModel === '' ? model : displayModel, main: primary.toLowerCase() === 'true', builtin: videoOutputTechnology === '2147483648', connection: videoOutputTechnology && videoTypes[videoOutputTechnology] ? videoTypes[videoOutputTechnology] : '',