From 4c588794810a1ce851e671c201edbe4c163fc3db Mon Sep 17 00:00:00 2001 From: Mads Nedergaard Paulsen Date: Thu, 10 Jul 2025 19:04:40 +0200 Subject: [PATCH 1/2] add low power notfication --- bin/omarchy-battery-monitor | 32 +++++++++++++++++++ .../user/omarchy-battery-monitor.service | 8 +++++ .../user/omarchy-battery-monitor.timer | 11 +++++++ install/power.sh | 3 ++ 4 files changed, 54 insertions(+) create mode 100755 bin/omarchy-battery-monitor create mode 100644 config/systemd/user/omarchy-battery-monitor.service create mode 100644 config/systemd/user/omarchy-battery-monitor.timer diff --git a/bin/omarchy-battery-monitor b/bin/omarchy-battery-monitor new file mode 100755 index 0000000..eb26d0f --- /dev/null +++ b/bin/omarchy-battery-monitor @@ -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 diff --git a/config/systemd/user/omarchy-battery-monitor.service b/config/systemd/user/omarchy-battery-monitor.service new file mode 100644 index 0000000..3c47283 --- /dev/null +++ b/config/systemd/user/omarchy-battery-monitor.service @@ -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 \ No newline at end of file diff --git a/config/systemd/user/omarchy-battery-monitor.timer b/config/systemd/user/omarchy-battery-monitor.timer new file mode 100644 index 0000000..dc43763 --- /dev/null +++ b/config/systemd/user/omarchy-battery-monitor.timer @@ -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 \ No newline at end of file diff --git a/install/power.sh b/install/power.sh index c7f458f..0ae0c0c 100644 --- a/install/power.sh +++ b/install/power.sh @@ -5,6 +5,9 @@ yay -S --noconfirm power-profiles-daemon if ls /sys/class/power_supply/BAT* &>/dev/null; then # This computer runs on a battery powerprofilesctl set balanced || true + + # Enable battery monitoring timer for low battery notifications + systemctl --user enable --now omarchy-battery-monitor.timer || true else # This computer runs on power outlet powerprofilesctl set performance || true From 957b23966cda27cac808ffb696c79d4996def285 Mon Sep 17 00:00:00 2001 From: Mads Nedergaard Paulsen Date: Thu, 10 Jul 2025 19:32:52 +0200 Subject: [PATCH 2/2] add migration for low power notify --- migrations/1752168292.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 migrations/1752168292.sh diff --git a/migrations/1752168292.sh b/migrations/1752168292.sh new file mode 100755 index 0000000..a2ed0c2 --- /dev/null +++ b/migrations/1752168292.sh @@ -0,0 +1,15 @@ +echo "Enable battery low notifications for laptops" + +if ls /sys/class/power_supply/BAT* &>/dev/null; then + mkdir -p ~/.config/systemd/user + + cp ~/.local/share/omarchy/config/systemd/user/omarchy-battery-monitor.* ~/.config/systemd/user/ + + systemctl --user daemon-reload + systemctl --user enable --now omarchy-battery-monitor.timer || true + + echo "Battery monitoring enabled - you'll receive notifications at 10% battery" +else + echo "No battery detected - skipping battery monitor setup" +fi +