mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-14 00:14:14 +09:00
* replace global.log() with logError()
* remove run_dispose calls
This function should only be called from object system implementations.
https://gjs-docs.gnome.org/gobject20~2.0/gobject.object#method-run_dispose
* use pkexec instead of sudo for ipmi-sensors
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
import GLib from 'gi://GLib';
|
|
|
|
function getSmartData (argv){
|
|
const smartctl = GLib.find_program_in_path('smartctl')
|
|
return JSON.parse(new TextDecoder().decode( GLib.spawn_command_line_sync(`'${smartctl}' ${argv} -j`)[1] ))
|
|
}
|
|
|
|
export default class SmartctlUtil {
|
|
|
|
constructor(callback) {
|
|
this._smartDevices = [];
|
|
try {
|
|
this._smartDevices = getSmartData("--scan")["devices"]
|
|
} catch (e) {
|
|
logError(e, '[FREON] Unable to find smart devices');
|
|
}
|
|
this._updated = true;
|
|
}
|
|
|
|
get available(){
|
|
return this._smartDevices.length > 0;
|
|
}
|
|
|
|
get updated (){
|
|
return this._updated;
|
|
}
|
|
|
|
set updated (updated){
|
|
this._updated = updated;
|
|
}
|
|
|
|
get temp() {
|
|
return this._smartDevices.map(device => {
|
|
const info = getSmartData(`--info ${device["name"]}`);
|
|
if (info["smartctl"]["exit_status"] != 0)
|
|
return null;
|
|
|
|
const attributes = getSmartData(`--attributes ${device["name"]}`);
|
|
if (attributes["smartctl"]["exit_status"] != 0)
|
|
return null;
|
|
|
|
return {
|
|
label: info["model_name"],
|
|
temp: parseFloat(attributes.temperature.current)
|
|
}
|
|
}).filter(entry => entry != null);
|
|
}
|
|
|
|
destroy(callback) {
|
|
this._smartDevices = [];
|
|
}
|
|
|
|
execute(callback) {
|
|
this._updated = true;
|
|
}
|
|
|
|
};
|