[Astal] Add battery low notification
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { bind } from "astal";
|
import { bind } from "astal";
|
||||||
|
import { execAsync } from "astal";
|
||||||
import AstalBattery from "gi://AstalBattery";
|
import AstalBattery from "gi://AstalBattery";
|
||||||
import AstalBluetooth from "gi://AstalBluetooth";
|
import AstalBluetooth from "gi://AstalBluetooth";
|
||||||
import AstalNetwork from "gi://AstalNetwork";
|
import AstalNetwork from "gi://AstalNetwork";
|
||||||
@@ -120,6 +121,8 @@ const BluetoothWidget = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let hasSentNotification = false;
|
||||||
const BatteryWidget = () => {
|
const BatteryWidget = () => {
|
||||||
const battery = AstalBattery.get_default();
|
const battery = AstalBattery.get_default();
|
||||||
if (battery.get_is_present()) {
|
if (battery.get_is_present()) {
|
||||||
@@ -127,7 +130,14 @@ const BatteryWidget = () => {
|
|||||||
<image
|
<image
|
||||||
iconName={bind(battery, "batteryIconName").as(icon => icon)}
|
iconName={bind(battery, "batteryIconName").as(icon => icon)}
|
||||||
cssClasses={["quick-view-symbol"]}
|
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>
|
></image>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user