Skip to content

Commit

Permalink
Sensors v4.0.3: Improved code. Greater stability. (#6807)
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiux authored Jan 26, 2025
1 parent e33d4f4 commit 1178d2e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
4 changes: 4 additions & 0 deletions Sensors@claudiux/files/Sensors@claudiux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v4.0.3~20250126
* Improved code. Greater stability.
* Change of Fan symbol.

### v4.0.2~20250116
* mainloopTools library: improvements.

Expand Down
20 changes: 9 additions & 11 deletions Sensors@claudiux/files/Sensors@claudiux/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {AppletSettings} = imports.ui.settings;
//const Gettext = imports.gettext;
const Extension = imports.ui.extension; // Needed to reload this applet
const ModalDialog = imports.ui.modalDialog;
const Lang = imports.lang;
//util
const {spawnCommandLineAsyncIO, spawnCommandLineAsync, spawnCommandLine, unref} = require("./lib/util");
//to-string
Expand Down Expand Up @@ -51,7 +50,7 @@ const {SensorsReaper} = require("./lib/sensorsReaper");
const ENABLED_APPLETS_KEY = "enabled-applets";

const C_TEMP = '⦿'; //'🌡'
const C_FAN = '🤂';
const C_FAN = '𖣘'; //'🤂'
const C_VOLT = '🗲'; //'🔌'
const C_INTRU = '⮿';
const DEFAULT_APPLET_LABEL = [C_TEMP, C_FAN, C_VOLT, C_INTRU];
Expand Down Expand Up @@ -213,14 +212,14 @@ class SensorsApplet extends Applet.TextApplet {
spawnCommandLineAsync("/bin/bash -c 'cd %s && chmod 755 *.py *.sh'".format(SCRIPTS_DIR), null, null);

this.sudo_or_wheel = "none";
let subProcess = spawnCommandLineAsyncIO("/bin/bash -c 'groups'", Lang.bind(this, (out, err, exitCode) => {
let subProcess = spawnCommandLineAsyncIO("/bin/bash -c 'groups'", (out, err, exitCode) => {
if (exitCode == 0) {
let groups = out.trim().split(' ');
if (groups.indexOf("wheel") > -1) this.sudo_or_wheel = "wheel";
if (groups.indexOf("sudo") > -1) this.sudo_or_wheel = "sudo";
}
subProcess.send_signal(9);
}));
});

// Detect language for numeric format:
this.num_lang = this._get_lang();
Expand Down Expand Up @@ -531,7 +530,7 @@ class SensorsApplet extends Applet.TextApplet {
let _temp;
//~ if (disk["value"])
//~ _temp = disk["value"];
let subProcess = spawnCommandLineAsyncIO(command, Lang.bind (this, function(stdout, stderr, exitCode) {
let subProcess = spawnCommandLineAsyncIO(command, (stdout, stderr, exitCode) => {
if (exitCode === 0) {
//~ this._temp[_disk_name] = stdout;

Expand All @@ -556,15 +555,15 @@ class SensorsApplet extends Applet.TextApplet {
}
}
subProcess.send_signal(9);
}));
});
}
}
}

populate_temp_disks_in_settings() {
let command = SCRIPTS_DIR+"/get_disk_list.sh";
var temp_disks = this.temp_disks;
let subProcess = spawnCommandLineAsyncIO(command, Lang.bind(this, function(stdout, stderr, exitCode) {
let subProcess = spawnCommandLineAsyncIO(command, (stdout, stderr, exitCode) => {
if (exitCode === 0) {
let out = stdout.trim();
let disks = out.split(" ");
Expand All @@ -579,7 +578,7 @@ class SensorsApplet extends Applet.TextApplet {
this.temp_disks = temp_disks
};
subProcess.send_signal(9);
}))
});
}

populate_fan_sensors_in_settings(force = true) {
Expand Down Expand Up @@ -1311,7 +1310,6 @@ class SensorsApplet extends Applet.TextApplet {

// Button suspend
let suspend_switch = new PopupMenu.PopupSwitchMenuItem(_("Suspend Sensors"), this.suspended);
//~ suspend_switch.connect("toggled", Lang.bind(this, function() {
suspend_switch.connect("toggled", () => {
this.menu.toggle();
this.suspended = !this.suspended;
Expand Down Expand Up @@ -1675,10 +1673,10 @@ class SensorsApplet extends Applet.TextApplet {
_on_disktemp_button_pressed() {
let subProcess = spawnCommandLineAsyncIO(
"/bin/bash -c '%s/pkexec_make_smartctl_usable_by_sudoers.sh %s'".format(SCRIPTS_DIR, this.sudo_or_wheel),
Lang.bind(this, (out, err, exitCode) => {
(out, err, exitCode) => {
this.s.setValue("disktemp_is_user_readable", this.is_disktemp_user_readable());
subProcess.send_signal(9);
}));
});
}

//~ check_disktemp_user_readable(force=false) {
Expand Down
23 changes: 10 additions & 13 deletions Sensors@claudiux/files/Sensors@claudiux/lib/sensorsReaper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio; // Needed for file infos
//const Util = imports.misc.util;
const Lang = imports.lang;
const Signals = imports.signals;
const Cinnamon = imports.gi.Cinnamon;
const Util = require("./lib/util");
Expand Down Expand Up @@ -80,15 +79,15 @@ class SensorsReaper {
this.sensors_command = this.sensors_program + " -u";
this.sensors_is_json_compatible = false;
let command = "%s -v".format(this.sensors_program);
let subProcess = Util.spawnCommandLineAsyncIO(command, Lang.bind(this, function(stdout, stderr, exitCode) {
let subProcess = Util.spawnCommandLineAsyncIO(command, (stdout, stderr, exitCode) => {
if (exitCode === 0) {
let output = stdout;
if (typeof stdout === "object") output = to_string(stdout);
sensors_version = output.split(" ")[2];
this.applet.sensors_version = sensors_version;
}
subProcess.send_signal(9);
}));
});
}
return this.sensors_command;
} else {
Expand All @@ -113,7 +112,7 @@ class SensorsReaper {
if (this.nvidia_smi_program) {
let command = `${this.nvidia_smi_program} --version`;
let subProcess = Util.spawnCommandLineAsyncIO(command,
Lang.bind(this, function (stdout, stderr, exitCode) {
(stdout, stderr, exitCode) => {
if (exitCode === 0) {
let output = stdout;
if (typeof stdout === "object")
Expand All @@ -131,7 +130,7 @@ class SensorsReaper {
}
// Test the command because Nvidia doesn't guarantee backwards compatability
let testProcess = Util.spawnCommandLineAsyncIO(this.nvidia_smi_command,
Lang.bind(this, function (stdout, stderr, exitCode) {
(stdout, stderr, exitCode) => {
if (exitCode != 0) {
global.logError(`Nvidia SMI call failed with code ${exitCode}: ${stdout}, ${stderr}`)
global.log(`Incompatible Nvidia SMI: ${this.nvidia_smi_program} v${this.nvidia_smi_version} `);
Expand All @@ -142,12 +141,10 @@ class SensorsReaper {
global.log(`Nvidia SMI v${this.nvidia_smi_version} command: ${this.nvidia_smi_command}`);
}
testProcess.send_signal(9);
})
);
});
subProcess.send_signal(9);
}
})
);
});

return this.nvidia_smi_command;
} else {
Expand All @@ -164,7 +161,7 @@ class SensorsReaper {
//if (this.in_fahrenheit)
//command += "f"; // The -f option of sensors is full of bugs !!!
if (this.sensors_command != undefined) {
let subProcess = Util.spawnCommandLineAsyncIO(this.sensors_command, Lang.bind (this, function(stdout, stderr, exitCode) {
let subProcess = Util.spawnCommandLineAsyncIO(this.sensors_command, (stdout, stderr, exitCode) => {
if (exitCode === 0) {
if (this.sensors_is_json_compatible)
this._sensors_reaped(stdout);
Expand All @@ -173,14 +170,14 @@ class SensorsReaper {
}
//Util.unref(subProcess);
subProcess.send_signal(9);
}));
});
}

}

reap_nvidia_smi() {
if (this.nvidia_smi_command != undefined) {
let subProcess = Util.spawnCommandLineAsyncIO(this.nvidia_smi_command, Lang.bind(this, function (stdout, stderr, exitCode) {
let subProcess = Util.spawnCommandLineAsyncIO(this.nvidia_smi_command, (stdout, stderr, exitCode) => {
if (exitCode === 0) {
let results = {};

Expand All @@ -203,7 +200,7 @@ class SensorsReaper {
global.logError(`Nvidia SMI call failed with code ${exitCode}: ${stdout}, ${stderr}`);
}
subProcess.send_signal(9);
}));
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sensors@claudiux/files/Sensors@claudiux/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"uuid": "Sensors@claudiux",
"name": "Sensors Monitor",
"description": "Displays the values of many computer sensors concerning Temperatures (CPU - GPU - Power Supply), Fan Speed, Voltages, Intrusions. Notifies you with color changes when a value reaches or exceeds its limit.",
"version": "4.0.2",
"version": "4.0.3",
"max-instances": 1,
"cinnamon-version": [
"3.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"page_Fans": {
"type": "page",
"title": "🤂 Fan",
"title": "𖣘 Fan",
"sections": [
"section_fanDisplay",
"section_fanOptions",
Expand Down

0 comments on commit 1178d2e

Please sign in to comment.