diff --git a/RELEASES.md b/RELEASES.md index 2b0eabe..fffd2cf 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -11,6 +11,12 @@ _Check the [documentation](https://github.com/AstraExt/astra-monitor/blob/main/README.md#nethogs) for more details._ +- **_Sensors Ignore Regex_**: Now you can use regular expressions to ignore specific sensors based on their name, category, or attribute. This feature allows for more granular control over which sensor data is displayed: + - Sensor Name: Exclude an entire sensor (the one you see in the sensors menu). + - Category: Exclude entire groups of sensors (e.g., "Package", "Core", "Edge"). + - Attribute: Exclude specific attributes (e.g., Min, Max, Crit, Alarm). + This powerful filtering mechanism enables users to customize their sensor display, focusing on the most relevant information while reducing clutter from unwanted sensor data. + ### Bug fixes - Addressed `amdgpu_top` v0.8.5 data structure change, now top processes are correctly displayed diff --git a/schemas/org.gnome.shell.extensions.astra-monitor.gschema.xml b/schemas/org.gnome.shell.extensions.astra-monitor.gschema.xml index e27f398..a33a8fa 100644 --- a/schemas/org.gnome.shell.extensions.astra-monitor.gschema.xml +++ b/schemas/org.gnome.shell.extensions.astra-monitor.gschema.xml @@ -1103,6 +1103,21 @@ Sensors Temperature Unit Temperature Unit of measurement for the sensors + + '' + Ignored Sensors Regex + A regex to match Sensors to ignore + + + '' + Ignored Sensors Category Regex + A regex to match Sensors Category to ignore + + + '' + Ignored Sensors Attribute Regex + A regex to match Sensors Attribute to ignore + 'auto' Sensors Source diff --git a/src/network/networkMonitor.ts b/src/network/networkMonitor.ts index bf3848a..8acc650 100644 --- a/src/network/networkMonitor.ts +++ b/src/network/networkMonitor.ts @@ -85,7 +85,7 @@ export default class NetworkMonitor extends Monitor { private detectedMaxSpeedsValues: MaxSpeeds; private interfaceChecks: Record; private ignored: string[]; - private ignoredRegex: RegExp | null; + private ignoredRegex!: RegExp | null; private updateNetworkIOTask: CancellableTaskManager; private updateRoutesTask: CancellableTaskManager; @@ -147,7 +147,7 @@ export default class NetworkMonitor extends Monitor { }); // Regex ignored interfaces - { + const updateIgnoredRegex = () => { const regex = Config.get_string('network-ignored-regex'); try { if(regex === null || regex === '') this.ignoredRegex = null; @@ -155,19 +155,13 @@ export default class NetworkMonitor extends Monitor { } catch(e) { this.ignoredRegex = null; } - } + }; Config.connect(this, 'changed::network-ignored-regex', () => { this.reset(); - - const regex = Config.get_string('network-ignored-regex'); - try { - if(regex === null || regex === '') this.ignoredRegex = null; - else this.ignoredRegex = new RegExp(`^${regex}$`, 'i'); - } catch(e) { - this.ignoredRegex = null; - } + updateIgnoredRegex(); }); + updateIgnoredRegex(); Config.connect( this, diff --git a/src/prefs/sensors.ts b/src/prefs/sensors.ts index cf3e141..43b9b7a 100644 --- a/src/prefs/sensors.ts +++ b/src/prefs/sensors.ts @@ -126,6 +126,45 @@ export default class Sensors { 'string' ); + const ignoredSection = PrefsUtils.addExpanderRow( + { title: _('Ignored Sensors') }, + group, + 'sensors' + ); + + PrefsUtils.addTextInputRow( + { + title: _('Ignored Sensors Regex'), + subtitle: _('Completely ignore sensors matching this regex'), + tabs: 1, + }, + 'sensors-ignored-regex', + ignoredSection, + '' + ); + + PrefsUtils.addTextInputRow( + { + title: _('Ignored Sensors Category Regex'), + subtitle: _('Categories are like "Package", "Core", "Edge", etc.'), + tabs: 1, + }, + 'sensors-ignored-category-regex', + ignoredSection, + '' + ); + + PrefsUtils.addTextInputRow( + { + title: _('Ignored Sensors Attribute Regex'), + subtitle: _('Attributes are like "Alarm", "Min", "Max", "Crit", etc.'), + tabs: 1, + }, + 'sensors-ignored-attribute-regex', + ignoredSection, + '' + ); + const sourcesSection = PrefsUtils.addExpanderRow( { title: _('Data Sources') }, group, diff --git a/src/sensors/sensorsMenu.ts b/src/sensors/sensorsMenu.ts index cb083be..812ffa5 100644 --- a/src/sensors/sensorsMenu.ts +++ b/src/sensors/sensorsMenu.ts @@ -63,6 +63,19 @@ export default class SensorsMenu extends MenuBase { this.createSensorsList(); this.addUtilityButtons('sensors'); + + Config.connect(this, 'changed::sensors-ignored-regex', () => { + this.resetSensorsList(); + Utils.sensorsMonitor.requestUpdate('sensorsData'); + }); + Config.connect(this, 'changed::sensors-ignored-category-regex', () => { + this.resetSensorsList(); + Utils.sensorsMonitor.requestUpdate('sensorsData'); + }); + Config.connect(this, 'changed::sensors-ignored-attribute-regex', () => { + this.resetSensorsList(); + Utils.sensorsMonitor.requestUpdate('sensorsData'); + }); } createSensorsList() { @@ -82,6 +95,14 @@ export default class SensorsMenu extends MenuBase { } } + resetSensorsList() { + for(const [id, sensor] of this.sensors.entries()) { + this.sensorsSection.remove_child(sensor.container); + this.sensors.delete(id); + } + this.noSensorsLabel.show(); + } + updateSensorsList(sensors: Map) { if(sensors.size > 0) this.noSensorsLabel.hide(); else this.noSensorsLabel.show(); diff --git a/src/sensors/sensorsMonitor.ts b/src/sensors/sensorsMonitor.ts index 8ce2111..128e7b2 100644 --- a/src/sensors/sensorsMonitor.ts +++ b/src/sensors/sensorsMonitor.ts @@ -59,6 +59,10 @@ export default class SensorsMonitor extends Monitor { private prefTooltipSensor4Source?: SensorSource; private prefTooltipSensor5Source?: SensorSource; + private ignoredSensorsRegex!: RegExp | null; + private ignoredSensorsCategoryRegex!: RegExp | null; + private ignoredSensorsAttributeRegex!: RegExp | null; + constructor() { super('Sensors Monitor'); @@ -170,6 +174,57 @@ export default class SensorsMonitor extends Monitor { 'changed::sensors-header-tooltip-sensor5', updateTooltipSensor5SourceBind ); + + // Regex ignored sensors + const updateIgnoredSensorsRegex = () => { + const regex = Config.get_string('sensors-ignored-regex'); + try { + if(regex === null || regex === '') this.ignoredSensorsRegex = null; + else this.ignoredSensorsRegex = new RegExp(`^${regex}$`, 'i'); + } catch(e) { + this.ignoredSensorsRegex = null; + } + }; + + Config.connect(this, 'changed::sensors-ignored-regex', () => { + this.reset(); + updateIgnoredSensorsRegex(); + }); + updateIgnoredSensorsRegex(); + + // Regex ignored sensors category + const updateIgnoredSensorsCategoryRegex = () => { + const regex = Config.get_string('sensors-ignored-category-regex'); + try { + if(regex === null || regex === '') this.ignoredSensorsCategoryRegex = null; + else this.ignoredSensorsCategoryRegex = new RegExp(`^${regex}$`, 'i'); + } catch(e) { + this.ignoredSensorsCategoryRegex = null; + } + }; + + Config.connect(this, 'changed::sensors-ignored-category-regex', () => { + this.reset(); + updateIgnoredSensorsCategoryRegex(); + }); + updateIgnoredSensorsCategoryRegex(); + + // Regex ignored sensors attribute + const updateIgnoredSensorsAttributeRegex = () => { + const regex = Config.get_string('sensors-ignored-attribute-regex'); + try { + if(regex === null || regex === '') this.ignoredSensorsAttributeRegex = null; + else this.ignoredSensorsAttributeRegex = new RegExp(`^${regex}$`, 'i'); + } catch(e) { + this.ignoredSensorsAttributeRegex = null; + } + }; + + Config.connect(this, 'changed::sensors-ignored-attribute-regex', () => { + this.reset(); + updateIgnoredSensorsAttributeRegex(); + }); + updateIgnoredSensorsAttributeRegex(); } get updateFrequency() { @@ -182,6 +237,10 @@ export default class SensorsMonitor extends Monitor { reset() { this.updateSensorsDataTask.cancel(); + + this.ignoredSensorsRegex = null; + this.ignoredSensorsCategoryRegex = null; + this.ignoredSensorsAttributeRegex = null; } start() { @@ -327,11 +386,25 @@ export default class SensorsMonitor extends Monitor { deviceLabel = Utils.capitalize(split[0]) + ' - ' + split[1].replace(/}$/, ''); + if( + this.ignoredSensorsRegex !== null && + this.ignoredSensorsRegex.test(deviceLabel) + ) { + continue; + } + device = { name: deviceLabel, children: new Map(), attrs: {} }; data.hwmon.children.set(deviceName, device); } for(const [categoryName, hwmonCategory] of hwmonDevice) { + if( + this.ignoredSensorsCategoryRegex !== null && + this.ignoredSensorsCategoryRegex.test(categoryName) + ) { + continue; + } + if(!this.shouldUpdate('hwmon', [deviceName, categoryName])) continue; let category = device.children.get(categoryName); @@ -341,6 +414,13 @@ export default class SensorsMonitor extends Monitor { } for(const [attributeName, hwmonAttribute] of hwmonCategory) { + if( + this.ignoredSensorsAttributeRegex !== null && + this.ignoredSensorsAttributeRegex.test(attributeName) + ) { + continue; + } + if( !this.shouldUpdate('hwmon', [ deviceName, @@ -406,6 +486,13 @@ export default class SensorsMonitor extends Monitor { const parsedData = JSON.parse(lmSensorsDataValue) as any; if(parsedData) { for(const [deviceName, deviceData] of Object.entries(parsedData)) { + if( + this.ignoredSensorsRegex !== null && + this.ignoredSensorsRegex.test(deviceName) + ) { + continue; + } + let device = data.lm_sensors.children.get(deviceName); if(!device) { device = { name: deviceName, children: new Map(), attrs: {} }; @@ -426,6 +513,13 @@ export default class SensorsMonitor extends Monitor { for(const [categoryName, categoryData] of Object.entries( deviceData as Record )) { + if( + this.ignoredSensorsCategoryRegex !== null && + this.ignoredSensorsCategoryRegex.test(categoryName) + ) { + continue; + } + if(categoryName === 'Adapter') continue; let category = device.children.get(categoryName); @@ -437,6 +531,13 @@ export default class SensorsMonitor extends Monitor { for(const [attributeName, attributeValue] of Object.entries( categoryData as Record )) { + if( + this.ignoredSensorsAttributeRegex !== null && + this.ignoredSensorsAttributeRegex.test(attributeName) + ) { + continue; + } + const value = parseFloat(attributeValue as any); let unit = ''; if(attributeName !== 'fan')