diff --git a/systemTemperature@KopfDesDaemons/README.md b/systemTemperature@KopfDesDaemons/README.md new file mode 100644 index 000000000..59169fd6e --- /dev/null +++ b/systemTemperature@KopfDesDaemons/README.md @@ -0,0 +1,23 @@ +# System Temperature Desklet + +This desklet displays the temperature of a specific thermal zone on your system. To configure it correctly, you need to specify the path to the thermal zone's temperature file in the desklet settings. + +## Finding the Correct Temperature File + +1. **Locate Thermal Zones:** + + Thermal zone files are usually located under `/sys/class/thermal/`. You can list them with the command: + + ```bash + ls /sys/class/thermal/ + ``` + +2. **Identify the Relevant Thermal Zone:** + + Each thermal_zoneX directory represents a thermal zone. Inside, you'll find a file that contains the temperature data (in millidegrees Celsius). + +3. **Set the Path in Desklet Settings:** + + In the desklet settings, specify the full path to the temperature file you want to monitor, such as: + + `/sys/class/thermal/thermal_zone2/temp` diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/desklet.js b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/desklet.js new file mode 100644 index 000000000..811dadeac --- /dev/null +++ b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/desklet.js @@ -0,0 +1,163 @@ +const Desklet = imports.ui.desklet; +const Lang = imports.lang; +const St = imports.gi.St; +const Mainloop = imports.mainloop; +const GLib = imports.gi.GLib; +const Settings = imports.ui.settings; +const Gettext = imports.gettext; + +const UUID = "systemTemperature@KopfDesDaemons"; + +Gettext.bindtextdomain(UUID, GLib.get_home_dir() + "/.local/share/locale"); + +function _(str) { + return Gettext.dgettext(UUID, str); +} + +function TemperatureDesklet(metadata, deskletId) { + this._init(metadata, deskletId); +} + +TemperatureDesklet.prototype = { + __proto__: Desklet.Desklet.prototype, + + _init: function (metadata, deskletId) { + Desklet.Desklet.prototype._init.call(this, metadata, deskletId); + + this.setHeader(_("System Temperature")); + + // Initialize settings + this.settings = new Settings.DeskletSettings(this, this.metadata["uuid"], deskletId); + + // Get settings + this.initialLabelText = this.settings.getValue("labelText") || "CPU temperature:"; + this.tempFilePath = this.settings.getValue("tempFilePath") || "/sys/class/thermal/thermal_zone2/temp"; + this.fontSizeLabel = this.settings.getValue("fontSizeLabel") || 12; + this.fontSizeTemperature = this.settings.getValue("fontSizeTemperature") || 20; + this.dynamicColorEnabled = this.settings.getValue("dynamicColorEnabled") || true; + this.temperatureUnit = this.settings.getValue("temperatureUnit") || "C"; + this.updateInterval = this.settings.getValue("updateInterval") || 1; + + // Bind settings properties + const boundSettings = [ + "tempFilePath", + "labelText", + "temperatureUnit", + "updateInterval", + "fontSizeLabel", + "fontSizeTemperature", + "dynamicColorEnabled" + ]; + boundSettings.forEach(setting => { + this.settings.bindProperty(Settings.BindingDirection.IN, setting, setting, this.on_settings_changed, null); + }); + + // Create label for the static text + this.label = new St.Label({ text: this.initialLabelText, y_align: St.Align.START, style_class: "label-text" }); + this.label.set_style(`font-size: ${this.fontSizeLabel}px;`); + + // Create label for the temperature value + this.temperatureLabel = new St.Label({ text: "Loading...", style_class: "temperature-label" }); + this.temperatureLabel.set_style(`font-size: ${this.fontSizeTemperature}px;`); + + // Set up the layout + this.box = new St.BoxLayout({ vertical: true }); + this.box.add_child(this.label); + this.box.add_child(this.temperatureLabel); + this.setContent(this.box); + + this._timeout = null; + + // Start the temperature update loop + this.updateTemperature(); + }, + + updateTemperature: function () { + try { + // Get CPU temperature + const [result, out] = GLib.spawn_command_line_sync(`cat ${this.tempFilePath}`); + + if (!result || out === null) { + throw new Error("Could not retrieve CPU temperature."); + } + + // Convert temperature from millidegree Celsius to degree Celsius + let temperature = parseFloat(out.toString().trim()) / 1000.0; + if (this.temperatureUnit === "F") { + temperature = (temperature * 9 / 5) + 32; + } + + // Update temperature text with the chosen unit + const temperatureText = `${temperature.toFixed(1)}°${this.temperatureUnit}`; + this.temperatureLabel.set_text(temperatureText); + + // Set color based on temperature if dynamic color is enabled, else set default color + if (this.dynamicColorEnabled) { + this.updateLabelColor(temperature); + } else { + this.temperatureLabel.set_style(`color: #ffffff; font-size: ${this.fontSizeTemperature}px;`); + } + + } catch (e) { + this.temperatureLabel.set_text("Error"); + global.logError(`Error in updateTemperature: ${e.message}`); + } + + // Reset and set up the interval timeout + if (this._timeout) Mainloop.source_remove(this._timeout); + this._timeout = Mainloop.timeout_add_seconds(this.updateInterval, () => this.updateTemperature()); + }, + + updateLabelColor: function (temperature) { + // Define min and max temperature thresholds based on the unit + let minTemp = 20, maxTemp = 90; + + // Convert min and max temperature from degree Celsius to degree Fahrenheit + if (this.temperatureUnit === "F") { + minTemp = (minTemp * 9 / 5) + 32; + maxTemp = (maxTemp * 9 / 5) + 32; + } + + // Calculate color based on temperature + temperature = Math.min(maxTemp, Math.max(minTemp, temperature)); + const ratio = (temperature - minTemp) / (maxTemp - minTemp); + let color = `rgb(${Math.floor(ratio * 255)}, ${Math.floor((1 - ratio) * 255)}, 0)`; + + // Set the color + this.temperatureLabel.set_style(`color: ${color}; font-size: ${this.fontSizeTemperature}px;`); + }, + + on_settings_changed: function () { + // Update the label text and styles when the settings change + if (this.label && this.labelText) { + this.label.set_text(this.labelText); + this.label.set_style(`font-size: ${this.fontSizeLabel}px;`); + } + + if (this.temperatureLabel) { + this.temperatureLabel.set_style(`font-size: ${this.fontSizeTemperature}px;`); + } + }, + + on_desklet_removed: function () { + // Clean up the timeout when the desklet is removed + if (this._timeout) { + Mainloop.source_remove(this._timeout); + this._timeout = null; + } + + if (this.label) { + this.box.remove_child(this.label); + this.label = null; + } + + if (this.temperatureLabel) { + this.box.remove_child(this.temperatureLabel); + this.temperatureLabel = null; + } + } +}; + +function main(metadata, deskletId) { + return new TemperatureDesklet(metadata, deskletId); +} diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/icon.png b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/icon.png new file mode 100644 index 000000000..d6795f39a Binary files /dev/null and b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/icon.png differ diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/icon.xcf b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/icon.xcf new file mode 100644 index 000000000..8e8110407 Binary files /dev/null and b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/icon.xcf differ diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/metadata.json b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/metadata.json new file mode 100644 index 000000000..685d104fb --- /dev/null +++ b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/metadata.json @@ -0,0 +1,7 @@ +{ + "uuid": "systemTemperature@KopfDesDaemons", + "name": "System Temperature", + "description": "Displays the temperature of a thermal zone in the system.", + "version": "1.0", + "max-instances": "10" +} \ No newline at end of file diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/po/de.po b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/po/de.po new file mode 100644 index 000000000..149b24b42 --- /dev/null +++ b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/po/de.po @@ -0,0 +1,72 @@ +# SYSTEM TEMPERATURE +# This file is put in the public domain. +# KopfDesDaemons, 2024 +# +msgid "" +msgstr "" +"Project-Id-Version: systemTemperature@KopfDesDaemons 1.0\n" +"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-desklets/" +"issues\n" +"POT-Creation-Date: 2024-11-08 19:56+0100\n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.0.1\n" + +#. metadata.json->name +#. desklet.js:27 +msgid "System Temperature" +msgstr "Systemtemperatur" + +#. metadata.json->description +msgid "Displays the temperature of a thermal zone in the system." +msgstr "Zeigt die Temperatur einer Thermal-Zone im System an." + +#. settings-schema.json->head0->description +msgid "General" +msgstr "Allgemein" + +#. settings-schema.json->tempFilePath->description +msgid "Path to file with temperature value (thermal zone)" +msgstr "Pfad zu der Datei mit dem Temperaturwert (Thermal-Zone)" + +#. settings-schema.json->labelText->description +msgid "Text for the label" +msgstr "Text für das Label" + +#. settings-schema.json->temperatureUnit->options +msgid "°C" +msgstr "°C" + +#. settings-schema.json->temperatureUnit->options +msgid "°F" +msgstr "°F" + +#. settings-schema.json->temperatureUnit->description +msgid "Temperature unit (Celsius or Fahrenheit)" +msgstr "Temperatureinheit (Celsius oder Fahrenheit)" + +#. settings-schema.json->updateInterval->description +msgid "Update interval in seconds" +msgstr "Aktualisierungsintervall in Sekunden" + +#. settings-schema.json->head1->description +msgid "Style" +msgstr "Stil" + +#. settings-schema.json->fontSizeLabel->description +msgid "Font size for the label text" +msgstr "Schriftgöße für das Label" + +#. settings-schema.json->fontSizeTemperature->description +msgid "Font size for the temperature display" +msgstr "Schriftgröße für die Temperaturanzeige" + +#. settings-schema.json->dynamicColorEnabled->description +msgid "Dynamic color based on temperature" +msgstr "Dynamische Farbe basierend auf der Temperatur" diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/po/systemTemperature@KopfDesDaemons.pot b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/po/systemTemperature@KopfDesDaemons.pot new file mode 100644 index 000000000..0c49374e9 --- /dev/null +++ b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/po/systemTemperature@KopfDesDaemons.pot @@ -0,0 +1,71 @@ +# SYSTEM TEMPERATURE +# This file is put in the public domain. +# KopfDesDaemons, 2024 +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: systemTemperature@KopfDesDaemons 1.0\n" +"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-desklets/" +"issues\n" +"POT-Creation-Date: 2024-11-08 19:56+0100\n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. metadata.json->name +#. desklet.js:27 +msgid "System Temperature" +msgstr "" + +#. metadata.json->description +msgid "Displays the temperature of a thermal zone in the system." +msgstr "" + +#. settings-schema.json->head0->description +msgid "General" +msgstr "" + +#. settings-schema.json->tempFilePath->description +msgid "Path to file with temperature value (thermal zone)" +msgstr "" + +#. settings-schema.json->labelText->description +msgid "Text for the label" +msgstr "" + +#. settings-schema.json->temperatureUnit->options +msgid "°C" +msgstr "" + +#. settings-schema.json->temperatureUnit->options +msgid "°F" +msgstr "" + +#. settings-schema.json->temperatureUnit->description +msgid "Temperature unit (Celsius or Fahrenheit)" +msgstr "" + +#. settings-schema.json->updateInterval->description +msgid "Update interval in seconds" +msgstr "" + +#. settings-schema.json->head1->description +msgid "Style" +msgstr "" + +#. settings-schema.json->fontSizeLabel->description +msgid "Font size for the label text" +msgstr "" + +#. settings-schema.json->fontSizeTemperature->description +msgid "Font size for the temperature display" +msgstr "" + +#. settings-schema.json->dynamicColorEnabled->description +msgid "Dynamic color based on temperature" +msgstr "" diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/settings-schema.json b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/settings-schema.json new file mode 100644 index 000000000..bb575d498 --- /dev/null +++ b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/settings-schema.json @@ -0,0 +1,58 @@ +{ + "head0": { + "type": "header", + "description": "General" + }, + "tempFilePath": { + "type": "entry", + "default": "/sys/class/thermal/thermal_zone2/temp", + "description": "Path to file with temperature value (thermal zone)" + }, + "labelText": { + "type": "entry", + "default": "CPU Temperature", + "description": "Text for the label" + }, + "temperatureUnit": { + "type": "combobox", + "default": "C", + "options": { + "\u00b0C": "C", + "\u00b0F": "F" + }, + "description": "Temperature unit (Celsius or Fahrenheit)" + }, + "updateInterval": { + "type": "scale", + "default": 1, + "min": 1, + "max": 60, + "step": 1, + "description": "Update interval in seconds" + }, + "head1": { + "type": "header", + "description": "Style" + }, + "fontSizeLabel": { + "type": "scale", + "default": 12, + "min": 8, + "max": 100, + "step": 1, + "description": "Font size for the label text" + }, + "fontSizeTemperature": { + "type": "scale", + "default": 35, + "min": 12, + "max": 100, + "step": 1, + "description": "Font size for the temperature display" + }, + "dynamicColorEnabled": { + "type": "switch", + "default": true, + "description": "Dynamic color based on temperature" + } +} \ No newline at end of file diff --git a/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/stylesheet.css b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/stylesheet.css new file mode 100644 index 000000000..3b4d7bb1d --- /dev/null +++ b/systemTemperature@KopfDesDaemons/files/systemTemperature@KopfDesDaemons/stylesheet.css @@ -0,0 +1,3 @@ +.temperature-label { + font-weight: bold; +} \ No newline at end of file diff --git a/systemTemperature@KopfDesDaemons/info.json b/systemTemperature@KopfDesDaemons/info.json new file mode 100644 index 000000000..abdd76797 --- /dev/null +++ b/systemTemperature@KopfDesDaemons/info.json @@ -0,0 +1,3 @@ +{ + "author": "KopfDesDaemons" +} \ No newline at end of file diff --git a/systemTemperature@KopfDesDaemons/screenshot.png b/systemTemperature@KopfDesDaemons/screenshot.png new file mode 100644 index 000000000..5e27deaaa Binary files /dev/null and b/systemTemperature@KopfDesDaemons/screenshot.png differ