graphics() raspberry ubuntu displays

This commit is contained in:
Sebastian Hildebrandt 2025-01-10 21:50:34 +01:00
parent 36379825c3
commit e8deda9fd3
2 changed files with 33 additions and 29 deletions

View File

@ -48,9 +48,9 @@ add new features and support more platforms. Thank you in advance!
## Node.js ✅, Bun ✅ and Deno ✅ ## Node.js ✅, Bun ✅ and Deno ✅
I tested this library with Node.js, Bun and Deno (V2.x) with no issues. There is I tested this library with Node.js, Bun and Deno (V2.x) with no issues. There
currently only one problem on Denos side: os.freemem() pollyfill is currently was only one problem on Denos side in version <= 2.1.4: os.freemem() pollyfill
not correct (version 2.1.4) but there is already a fix (not yet published). 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 **Attention**: This library is supposed to be used as a backend/server-side
library and **will definitely not work within a browser**. library and **will definitely not work within a browser**.

View File

@ -768,51 +768,55 @@ function graphics(callback) {
vramDynamic: true vramDynamic: true
}); });
} }
if (callback) { // if (callback) {
callback(result); // callback(result);
} // }
resolve(result); // resolve(result);
}); });
} else { }
let cmd = 'lspci -vvv 2>/dev/null'; // } else {
exec(cmd, function (error, stdout) { let cmd = 'lspci -vvv 2>/dev/null';
if (!error) { exec(cmd, function (error, stdout) {
let lines = stdout.toString().split('\n'); if (!error) {
let lines = stdout.toString().split('\n');
if (result.controllers.length === 0) {
result.controllers = parseLinesLinuxControllers(lines); result.controllers = parseLinesLinuxControllers(lines);
const nvidiaData = nvidiaDevices(); const nvidiaData = nvidiaDevices();
// needs to be rewritten ... using no spread operators // needs to be rewritten ... using no spread operators
result.controllers = result.controllers.map((controller) => { // match by busAddress result.controllers = result.controllers.map((controller) => { // match by busAddress
return mergeControllerNvidia(controller, nvidiaData.find((contr) => contr.pciBus.toLowerCase().endsWith(controller.busAddress.toLowerCase())) || {}); 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) { exec(cmd, function (error, stdout) {
let depth = 0;
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); 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) { exec(cmd, function (error, stdout) {
let depth = 0;
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
depth = parseInt(lines[0]) || 0; result.displays = parseLinesLinuxDisplays(lines, depth);
} }
let cmd = 'xrandr --verbose 2>/dev/null'; if (callback) {
exec(cmd, function (error, stdout) { callback(result);
if (!error) { }
let lines = stdout.toString().split('\n'); resolve(result);
result.displays = parseLinesLinuxDisplays(lines, depth);
}
if (callback) {
callback(result);
}
resolve(result);
});
}); });
}); });
}); });
} });
// }
} }
if (_freebsd || _openbsd || _netbsd) { if (_freebsd || _openbsd || _netbsd) {
if (callback) { callback(null); } if (callback) { callback(null); }