From 25a78f126e86779b9325b100fd3523f31e5f3b52 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Mon, 15 Sep 2025 14:42:05 +0200 Subject: [PATCH] [Astal] Add battery low notification --- config/astal/components/bar/modules/QuickView.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/config/astal/components/bar/modules/QuickView.tsx b/config/astal/components/bar/modules/QuickView.tsx index 9aacd28..f3f7243 100644 --- a/config/astal/components/bar/modules/QuickView.tsx +++ b/config/astal/components/bar/modules/QuickView.tsx @@ -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 = () => { 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}%` + })} > ); } else {