Refactor Polling Mechanism: Implement Class-Based Poller with Start/Stop Control (#528)
* custom module updates to class based. * Finish poller logic. * Use composition for pollers * Rename poller * Handle recorder polling. * Fix quotes in bash command * Remove logs
This commit is contained in:
@@ -2,14 +2,14 @@ import GLib from 'gi://GLib?version=2.0';
|
||||
import { convertCelsiusToFahrenheit } from 'globals/weather';
|
||||
import { UnitType } from 'lib/types/weather';
|
||||
import options from 'options';
|
||||
import { Variable } from 'types/variable';
|
||||
import { Variable as VariableType } from 'types/variable';
|
||||
const { sensor } = options.bar.customModules.cpuTemp;
|
||||
|
||||
/**
|
||||
* Retrieves the current CPU temperature.
|
||||
* @returns CPU temperature in degrees Celsius
|
||||
*/
|
||||
export const getCPUTemperature = (round: Variable<boolean>, unit: Variable<UnitType>): number => {
|
||||
export const getCPUTemperature = (round: VariableType<boolean>, unit: VariableType<UnitType>): number => {
|
||||
try {
|
||||
if (sensor.value.length === 0) {
|
||||
return 0;
|
||||
@@ -23,13 +23,13 @@ export const getCPUTemperature = (round: Variable<boolean>, unit: Variable<UnitT
|
||||
return 0;
|
||||
}
|
||||
|
||||
let decimalTemp = parseInt(tempInfo) / 1000;
|
||||
let decimalTemp = parseInt(tempInfo, 10) / 1000;
|
||||
|
||||
if (unit.value === 'imperial') {
|
||||
decimalTemp = convertCelsiusToFahrenheit(decimalTemp);
|
||||
}
|
||||
|
||||
return round ? Math.round(decimalTemp) : parseFloat(decimalTemp.toFixed(2));
|
||||
return round.value ? Math.round(decimalTemp) : parseFloat(decimalTemp.toFixed(2));
|
||||
} catch (error) {
|
||||
console.error('Error calculating CPU Temp:', error);
|
||||
return 0;
|
||||
|
||||
@@ -8,9 +8,11 @@ import Button from 'types/widgets/button';
|
||||
// Utility Methods
|
||||
import { inputHandler } from 'customModules/utils';
|
||||
import { getCPUTemperature } from './helpers';
|
||||
import { pollVariable } from 'customModules/PollVar';
|
||||
import { BarBoxChild } from 'lib/types/bar';
|
||||
import { Attribute, Child } from 'lib/types/widget';
|
||||
import { FunctionPoller } from 'lib/poller/FunctionPoller';
|
||||
import { Variable as VariableType } from 'types/variable';
|
||||
import { UnitType } from 'lib/types/weather';
|
||||
|
||||
// All the user configurable options for the cpu module that are needed
|
||||
const {
|
||||
@@ -30,7 +32,7 @@ const {
|
||||
|
||||
export const cpuTemp = Variable(0);
|
||||
|
||||
pollVariable(
|
||||
const cpuTempPoller = new FunctionPoller<number, [VariableType<boolean>, VariableType<UnitType>]>(
|
||||
// Variable to poll and update with the result of the function passed in
|
||||
cpuTemp,
|
||||
// Variables that should trigger the polling function to update when they change
|
||||
@@ -43,6 +45,8 @@ pollVariable(
|
||||
unit,
|
||||
);
|
||||
|
||||
cpuTempPoller.initialize('cputemp');
|
||||
|
||||
export const CpuTemp = (): BarBoxChild => {
|
||||
const cpuTempModule = module({
|
||||
textIcon: icon.bind('value'),
|
||||
|
||||
Reference in New Issue
Block a user