mirror of
https://github.com/basecamp/omarchy.git
synced 2025-07-27 12:19:24 +00:00
add low power notfication
This commit is contained in:
32
bin/omarchy-battery-monitor
Executable file
32
bin/omarchy-battery-monitor
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Omarchy Battery Monitor
|
||||||
|
# One-shot script that checks battery and sends notification if needed
|
||||||
|
# Designed to be run by systemd timer every 30 seconds
|
||||||
|
|
||||||
|
BATTERY_THRESHOLD=10
|
||||||
|
NOTIFICATION_FLAG="/run/user/$UID/omarchy_battery_notified"
|
||||||
|
|
||||||
|
get_battery_percentage() {
|
||||||
|
upower -i $(upower -e | grep 'BAT') | grep -E "percentage" | grep -o '[0-9]\+%' | sed 's/%//'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_battery_state() {
|
||||||
|
upower -i $(upower -e | grep 'BAT') | grep -E "state" | awk '{print $2}'
|
||||||
|
}
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
notify-send -u critical "Battery Low" "Battery level is at ${1}%! Please plug in your charger." -i battery-caution
|
||||||
|
}
|
||||||
|
|
||||||
|
BATTERY_LEVEL=$(get_battery_percentage)
|
||||||
|
BATTERY_STATE=$(get_battery_state)
|
||||||
|
|
||||||
|
if [[ "$BATTERY_STATE" == "discharging" && "$BATTERY_LEVEL" -le "$BATTERY_THRESHOLD" ]]; then
|
||||||
|
if [[ ! -f "$NOTIFICATION_FLAG" ]]; then
|
||||||
|
send_notification "$BATTERY_LEVEL"
|
||||||
|
touch "$NOTIFICATION_FLAG"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
rm -f "$NOTIFICATION_FLAG"
|
||||||
|
fi
|
8
config/systemd/user/omarchy-battery-monitor.service
Normal file
8
config/systemd/user/omarchy-battery-monitor.service
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Omarchy Battery Monitor Check
|
||||||
|
After=graphical-session.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=%h/.local/share/omarchy/bin/omarchy-battery-monitor
|
||||||
|
Environment=DISPLAY=:0
|
11
config/systemd/user/omarchy-battery-monitor.timer
Normal file
11
config/systemd/user/omarchy-battery-monitor.timer
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Omarchy Battery Monitor Timer
|
||||||
|
Requires=omarchy-battery-monitor.service
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=1min
|
||||||
|
OnUnitActiveSec=30sec
|
||||||
|
AccuracySec=10sec
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
@ -5,6 +5,9 @@ yay -S --noconfirm power-profiles-daemon
|
|||||||
if ls /sys/class/power_supply/BAT* &>/dev/null; then
|
if ls /sys/class/power_supply/BAT* &>/dev/null; then
|
||||||
# This computer runs on a battery
|
# This computer runs on a battery
|
||||||
powerprofilesctl set balanced || true
|
powerprofilesctl set balanced || true
|
||||||
|
|
||||||
|
# Enable battery monitoring timer for low battery notifications
|
||||||
|
systemctl --user enable --now omarchy-battery-monitor.timer || true
|
||||||
else
|
else
|
||||||
# This computer runs on power outlet
|
# This computer runs on power outlet
|
||||||
powerprofilesctl set performance || true
|
powerprofilesctl set performance || true
|
||||||
|
Reference in New Issue
Block a user