From e8deda9fd336c23780861d0718fad3741b28fdea Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 10 Jan 2025 21:50:34 +0100 Subject: [PATCH] graphics() raspberry ubuntu displays --- README.md | 6 +++--- lib/graphics.js | 56 ++++++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 0f8c115..7bc423b 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ add new features and support more platforms. Thank you in advance! ## Node.js ✅, Bun ✅ and Deno ✅ -I tested this library with Node.js, Bun and Deno (V2.x) with no issues. There is -currently only one problem on Denos side: os.freemem() pollyfill is currently -not correct (version 2.1.4) but there is already a fix (not yet published). +I tested this library with Node.js, Bun and Deno (V2.x) with no issues. There +was only one problem on Denos side in version <= 2.1.4: os.freemem() pollyfill +was not correct but this is now fixed with Deno >= 2.1.5. **Attention**: This library is supposed to be used as a backend/server-side library and **will definitely not work within a browser**. diff --git a/lib/graphics.js b/lib/graphics.js index 4c04df3..e93d3c5 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -768,51 +768,55 @@ function graphics(callback) { vramDynamic: true }); } - if (callback) { - callback(result); - } - resolve(result); + // if (callback) { + // callback(result); + // } + // resolve(result); }); - } else { - let cmd = 'lspci -vvv 2>/dev/null'; - exec(cmd, function (error, stdout) { - if (!error) { - let lines = stdout.toString().split('\n'); + } + // } else { + let cmd = 'lspci -vvv 2>/dev/null'; + exec(cmd, function (error, stdout) { + if (!error) { + let lines = stdout.toString().split('\n'); + if (result.controllers.length === 0) { result.controllers = parseLinesLinuxControllers(lines); + const nvidiaData = nvidiaDevices(); // needs to be rewritten ... using no spread operators result.controllers = result.controllers.map((controller) => { // match by busAddress return mergeControllerNvidia(controller, nvidiaData.find((contr) => contr.pciBus.toLowerCase().endsWith(controller.busAddress.toLowerCase())) || {}); }); } - let cmd = 'clinfo --raw'; + } + let cmd = 'clinfo --raw'; + exec(cmd, function (error, stdout) { + if (!error) { + let lines = stdout.toString().split('\n'); + result.controllers = parseLinesLinuxClinfo(result.controllers, lines); + } + let cmd = 'xdpyinfo 2>/dev/null | grep \'depth of root window\' | awk \'{ print $5 }\''; exec(cmd, function (error, stdout) { + let depth = 0; if (!error) { let lines = stdout.toString().split('\n'); - result.controllers = parseLinesLinuxClinfo(result.controllers, lines); + depth = parseInt(lines[0]) || 0; } - let cmd = 'xdpyinfo 2>/dev/null | grep \'depth of root window\' | awk \'{ print $5 }\''; + let cmd = 'xrandr --verbose 2>/dev/null'; exec(cmd, function (error, stdout) { - let depth = 0; if (!error) { let lines = stdout.toString().split('\n'); - depth = parseInt(lines[0]) || 0; + result.displays = parseLinesLinuxDisplays(lines, depth); } - let cmd = 'xrandr --verbose 2>/dev/null'; - exec(cmd, function (error, stdout) { - if (!error) { - let lines = stdout.toString().split('\n'); - result.displays = parseLinesLinuxDisplays(lines, depth); - } - if (callback) { - callback(result); - } - resolve(result); - }); + if (callback) { + callback(result); + } + resolve(result); }); }); }); - } + }); + // } } if (_freebsd || _openbsd || _netbsd) { if (callback) { callback(null); }