Files
gnome-shell-extension-freon/freon@UshakovVasilii_Github.yahoo.com/nvidiaUtil.js
polter dab42ffc5c nvidiaUtil: code cleanup, fix recognizing the card (#242)
Since the card list is populated only in constructor, to update it we
had to toggle "Nvidia" switch `on`->`off`->`on`.

The fix is to get the temperature along with the card name in one
`nvidia-smi` call.

Also some code cleanup was made, removed old unused code.

Fixes #241

Signed-off-by: Pavel Artsishevsky <polter.rnd@gmail.com>
2022-07-09 08:21:51 +03:00

39 lines
992 B
JavaScript

const ByteArray = imports.byteArray;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const CommandLineUtil = Me.imports.commandLineUtil;
var NvidiaUtil = class extends CommandLineUtil.CommandLineUtil {
constructor() {
super();
let path = GLib.find_program_in_path('nvidia-smi');
this._argv = path ? [path, '--query-gpu=name,temperature.gpu', '--format=csv,noheader'] : null;
}
get temp() {
let gpus = [];
if (this._output) {
for (let line of this._output) {
let values = line.split(',');
if (values.length < 2)
continue;
let label = values[0].trim();
let temp = parseFloat(values[1]);
if(!label || !temp)
continue;
gpus.push({ label: label, temp: temp });
}
}
return gpus;
}
};