From d2608358a289343cba5d7a43b3b636cffd8cbd99 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Thu, 21 Nov 2024 13:02:36 +0200 Subject: [PATCH] Made battery notifications work --- .zshrc | 4 ++++ scripts/battery_notifier.sh | 16 ++++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.zshrc b/.zshrc index f8699e6..af12135 100644 --- a/.zshrc +++ b/.zshrc @@ -94,6 +94,10 @@ eval $(keychain --quiet --eval --timeout 300 ~/.ssh/id_ed25519) # Open tmux if it's not open if [ -z "$TMUX" ]; then tmux a || tmux + # HACK: Send a notification so systemd notification will work + # Using tmux to only run this at startup + # I guess this works because it initializes some stuff? + notify-send --urgency=normal --expire-time=1 " " fi END_TIME=$(date +%s.%4N) diff --git a/scripts/battery_notifier.sh b/scripts/battery_notifier.sh index 17e77f8..96043c8 100755 --- a/scripts/battery_notifier.sh +++ b/scripts/battery_notifier.sh @@ -1,22 +1,14 @@ set -eu export DISPLAY=:0.0 -export XAUTHORIRTY=/home/kyren/.Xauthority - - -echo "$DISPLAY, $XAUTHORIRTY" >> "$HOME/Desktop/debug.log" +export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus battery_level=$(cat /sys/class/power_supply/BAT0/capacity) battery_status=$(cat /sys/class/power_supply/BAT0/status) -echo "$battery_level% $battery_status" >> "$HOME/Desktop/debug.log" - -/etc/profiles/per-user/kyren/bin/notify-send --urgency=normal \ - --app-name="Battery Notifier" \ - --expire-time=5000 \ - "Battery at $battery_level%, unplug!" >> "$HOME/Desktop/debug.log" 2>&1 +echo "Battery: $battery_level% $battery_status" >> "$HOME/Desktop/debug.log" if [ "$battery_status" = "Charging" ] && [ "$battery_level" -ge 80 ]; then - touch "$HOME/Desktop/WHY" - /etc/profiles/per-user/kyren/bin/notify-send --urgency=normal \ + echo "Notification sent" >> "$HOME/Desktop/debug.log" + /etc/profiles/per-user/kyren/bin/notify-send --urgency=normal \ --app-name="Battery Notifier" \ --expire-time=5000 \ "Battery at $battery_level%, unplug!" >> "$HOME/Desktop/debug.log" 2>&1