[Astal] Add battery low notification

This commit is contained in:
2025-09-15 14:42:05 +02:00
parent e0c339785d
commit 25a78f126e

View File

@@ -1,4 +1,5 @@
import { bind } from "astal";
import { execAsync } from "astal";
import AstalBattery from "gi://AstalBattery";
import AstalBluetooth from "gi://AstalBluetooth";
import AstalNetwork from "gi://AstalNetwork";
@@ -120,6 +121,8 @@ const BluetoothWidget = () => {
);
};
let hasSentNotification = false;
const BatteryWidget = () => {
const battery = AstalBattery.get_default();
if (battery.get_is_present()) {
@@ -127,7 +130,14 @@ const BatteryWidget = () => {
<image
iconName={bind(battery, "batteryIconName").as(icon => icon)}
cssClasses={["quick-view-symbol"]}
tooltipText={bind(battery, 'percentage').as(p => `Battery Level: ${Math.round(p * 100)}%`)}
tooltipText={bind(battery, 'percentage').as(p => {
const level = Math.round(p * 100)
if ( level < 20 && !hasSentNotification ) {
hasSentNotification = true;
execAsync( 'bash -c "notify-send \'Battery level below 20%\'"' );
}
return `Battery Level: ${level}%`
})}
></image>
);
} else {