mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-14 00:14:14 +09:00
Merge pull request #68 from Farsx/display-label
Added option to display sensor label in the panel
This commit is contained in:
38
extension.js
38
extension.js
@@ -19,10 +19,19 @@ const SensorsItem = new Lang.Class({
|
||||
|
||||
_init: function(label, value) {
|
||||
this.parent({reactive: false});
|
||||
this._label = label;
|
||||
this._value = value;
|
||||
|
||||
this.addActor(new St.Label({text: label}));
|
||||
this.addActor(new St.Label({text: value}), {align: St.Align.END});
|
||||
}
|
||||
},
|
||||
|
||||
getPanelString: function() {
|
||||
if(settings.get_boolean('display-label'))
|
||||
return '%s: %s'.format(this._label, this._value);
|
||||
else
|
||||
return this._value;
|
||||
},
|
||||
});
|
||||
|
||||
const SensorsMenuButton = new Lang.Class({
|
||||
@@ -121,43 +130,48 @@ const SensorsMenuButton = new Lang.Class({
|
||||
sum += temp['temp'];
|
||||
if (temp['temp'] > max)
|
||||
max = temp['temp'];
|
||||
if (temp['label'] == settings.get_string('sensor'))
|
||||
sel = this._formatTemp(temp['temp']);
|
||||
item = new SensorsItem(temp['label'], this._formatTemp(temp['temp']));
|
||||
if (temp['label'] == settings.get_string('sensor'))
|
||||
sel = item;
|
||||
section.addMenuItem(item);
|
||||
}
|
||||
if (tempInfo.length > 0 && (fanInfo.length > 0 || voltageInfo.length > 0)){
|
||||
section.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||
}
|
||||
for each (let fan in fanInfo){
|
||||
if (settings.get_string('sensor') == fan['label'])
|
||||
sel = '%drpm'.format(fan['rpm']);
|
||||
item = new SensorsItem(fan['label'], '%drpm'.format(fan['rpm']));
|
||||
if (settings.get_string('sensor') == fan['label'])
|
||||
sel = item;
|
||||
section.addMenuItem(item);
|
||||
}
|
||||
if (fanInfo.length > 0 && voltageInfo.length > 0){
|
||||
section.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||
}
|
||||
for each (let voltage in voltageInfo){
|
||||
if (settings.get_string('sensor') == voltage['label'])
|
||||
sel = '%s%.2fV'.format(((voltage['volt'] >= 0) ? '+' : '-'), voltage['volt']);
|
||||
item = new SensorsItem(voltage['label'], '%s%.2fV'.format(((voltage['volt'] >= 0) ? '+' : '-'), voltage['volt']));
|
||||
if (settings.get_string('sensor') == voltage['label'])
|
||||
sel = item;
|
||||
section.addMenuItem(item);
|
||||
}
|
||||
|
||||
let mainSensor = '';
|
||||
|
||||
switch (settings.get_string('show-in-panel'))
|
||||
{
|
||||
switch (settings.get_string('show-in-panel')) {
|
||||
case 'maximum':
|
||||
mainSensor = this._formatTemp(max);//or the maximum temp
|
||||
if(settings.get_boolean('display-label'))
|
||||
mainSensor = "Maximum: %s".format(this._formatTemp(max));
|
||||
else
|
||||
mainSensor = this._formatTemp(max);//or the maximum temp
|
||||
break;
|
||||
case 'sensor':
|
||||
mainSensor = sel;//or temperature from a selected sensor
|
||||
mainSensor = sel.getPanelString();//or temperature from a selected sensor
|
||||
break;
|
||||
case 'average':
|
||||
default:
|
||||
mainSensor = this._formatTemp(sum/tempInfo.length);//average as default
|
||||
if(settings.get_boolean('display-label'))
|
||||
mainSensor = "Average: %s".format(this._formatTemp(sum/tempInfo.length));
|
||||
else
|
||||
mainSensor = this._formatTemp(sum/tempInfo.length);//average as default
|
||||
break;
|
||||
}
|
||||
this.statusLabel.set_text(mainSensor);
|
||||
|
||||
8
prefs.js
8
prefs.js
@@ -134,6 +134,14 @@ const SensorsPrefsWidget = new GObject.Class({
|
||||
|
||||
this.attach(new Gtk.Label({ label: "Show in panel" }), 0, ++counter, 1, 1);
|
||||
this.attach(this._sensorSelector, 1, counter , 1, 1);
|
||||
|
||||
let settings = this._settings;
|
||||
let checkButton = new Gtk.CheckButton({label: 'Display label'});
|
||||
checkButton.set_active(settings.get_boolean('display-label'));
|
||||
checkButton.connect('toggled', function () {
|
||||
settings.set_boolean('display-label', checkButton.get_active());
|
||||
});
|
||||
this.attach(checkButton, 2, counter , 1, 1);
|
||||
},
|
||||
|
||||
_comboBoxSeparator: function(model, iter, data) {
|
||||
|
||||
@@ -21,7 +21,13 @@
|
||||
<description>Select if "average", "maximum" or a specific sensor temperature has to be shown in the panel</description>
|
||||
</key>
|
||||
|
||||
<key type="s" name="sensor">
|
||||
<key type="b" name="display-label">
|
||||
<default>false</default>
|
||||
<summary>Display label</summary>
|
||||
<description>Display also the label of the sensor in the panel</description>
|
||||
</key>
|
||||
|
||||
<key type="s" name="sensor">
|
||||
<default>""</default>
|
||||
<summary>Sensor temperature to show in panel</summary>
|
||||
<description>Select the sensor whose temperature has to be shown in the panel</description>
|
||||
|
||||
Reference in New Issue
Block a user