mirror of
https://github.com/SupertigerDev/waybar-online.git
synced 2026-03-24 08:06:37 +00:00
Add temperature module with dynamic temperature updates and critical state handling
This commit is contained in:
@@ -10,4 +10,8 @@ export const modules = {
|
|||||||
import("./modules/battery").then(
|
import("./modules/battery").then(
|
||||||
({ createBatteryModule }) => createBatteryModule
|
({ createBatteryModule }) => createBatteryModule
|
||||||
),
|
),
|
||||||
|
temperature: () =>
|
||||||
|
import("./modules/temperature").then(
|
||||||
|
({ createTemperatureModule }) => createTemperatureModule
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
40
src/routes/waybar/modules/temperature.ts
Normal file
40
src/routes/waybar/modules/temperature.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import type { WaybarConfig } from "../configParser";
|
||||||
|
import type { Module } from "../createModule";
|
||||||
|
import { createLabel } from "../Label";
|
||||||
|
|
||||||
|
export const createTemperatureModule = (
|
||||||
|
module: Module,
|
||||||
|
config: WaybarConfig["temperature"]
|
||||||
|
) => {
|
||||||
|
const label = createLabel({
|
||||||
|
interval: 1000,
|
||||||
|
update: () => update(),
|
||||||
|
config: config!,
|
||||||
|
module,
|
||||||
|
});
|
||||||
|
|
||||||
|
module.element.appendChild(label.element);
|
||||||
|
|
||||||
|
const update = async () => {
|
||||||
|
const temperatureC = Math.round(Math.random() * 90);
|
||||||
|
const temperatureF = Math.round(temperatureC * (9 / 5) + 32);
|
||||||
|
|
||||||
|
const criticalThreshold = config["critical-threshold"];
|
||||||
|
|
||||||
|
if (temperatureC >= criticalThreshold) {
|
||||||
|
module.element.classList.add("critical");
|
||||||
|
} else {
|
||||||
|
module.element.classList.remove("critical");
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxTemp = criticalThreshold !== undefined ? criticalThreshold : 0;
|
||||||
|
|
||||||
|
label.set({
|
||||||
|
temperatureC,
|
||||||
|
temperatureF,
|
||||||
|
icon: label.getIcon(temperatureC, "", maxTemp),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
update();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user