mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-08-11 18:18:37 +02:00
reworked the battery notification scripts
This commit is contained in:
Binary file not shown.
@@ -183,6 +183,7 @@ pavucontrol # PulseAudio Volume Control
|
||||
hyprshot
|
||||
hyprcursor
|
||||
vial # Open-source GUI and QMK fork for configuring your keyboard in real time
|
||||
mplayer # Movie player that supports many video formats
|
||||
];
|
||||
|
||||
# fonts
|
||||
|
||||
@@ -55,6 +55,7 @@ home.packages = [
|
||||
#scritps
|
||||
(pkgs.callPackage ../../modules/scripts/dontkillsteam.nix {}) # kill app (if it is steam put it in some background
|
||||
(pkgs.callPackage ../../modules/scripts/batterynotify.nix {})
|
||||
(pkgs.callPackage ../../modules/scripts/batterywarning.nix {})
|
||||
(pkgs.callPackage ../../modules/scripts/weather.nix {})
|
||||
(pkgs.callPackage ../../modules/scripts/cowsay.nix {})
|
||||
(pkgs.callPackage ../../modules/scripts/wallpaper.nix {})
|
||||
@@ -65,6 +66,7 @@ home.packages = [
|
||||
(pkgs.callPackage ../../modules/scripts/launch.nix {}) # necessary for the apps i launch with hyprland at every start
|
||||
(pkgs.callPackage ../../modules/scripts/gitnotify.nix {})
|
||||
(pkgs.callPackage ../../modules/scripts/tomato.nix {})
|
||||
|
||||
#pkgs
|
||||
pkgs.gruvbox-gtk-theme
|
||||
# # Adds the 'hello' command to your environment. It prints a friendly
|
||||
|
||||
@@ -190,7 +190,8 @@ in
|
||||
"nm-applet --indicator" # systray app for Network/wifi
|
||||
"wl-paste --type text --watch cliphist store" # clipboard store text data
|
||||
"wl-paste --type image --watch cliphist store" # clipboard store image data
|
||||
"custom-batterynotify"
|
||||
"custom-batterynotify"
|
||||
"custom-batterywarning"
|
||||
#wallpapers/b
|
||||
"swww img ${wallpaper}"
|
||||
"swww-daemon"
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
{ writeShellApplication
|
||||
, libnotify
|
||||
, systemd
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "custom-olddeprecatedbatterynotify";
|
||||
|
||||
runtimeInputs = [
|
||||
libnotify # provides notify-send
|
||||
systemd # provides systemctl
|
||||
];
|
||||
|
||||
text = ''
|
||||
set -euo pipefail
|
||||
|
||||
LOW="''${BATTERY_LOW_THRESHOLD:-20}"
|
||||
CRITICAL="''${BATTERY_CRITICAL_THRESHOLD:-5}"
|
||||
FULL="''${BATTERY_FULL_THRESHOLD:-95}"
|
||||
INTERVAL="''${BATTERY_INTERVAL:-30}"
|
||||
ACTION="''${BATTERY_CRITICAL_ACTION:-systemctl suspend}"
|
||||
|
||||
notify() {
|
||||
notify-send -a "Battery" -u "$1" "$2" "$3"
|
||||
}
|
||||
|
||||
get_info() {
|
||||
total=0
|
||||
count=0
|
||||
|
||||
for bat in /sys/class/power_supply/BAT*; do
|
||||
[ -f "$bat/capacity" ] || continue
|
||||
capacity=$(<"$bat/capacity")
|
||||
status=$(<"$bat/status")
|
||||
total=$((total + capacity))
|
||||
count=$((count + 1))
|
||||
done
|
||||
|
||||
[ "$count" -gt 0 ] || exit 0
|
||||
percentage=$((total / count))
|
||||
}
|
||||
|
||||
last_state=""
|
||||
|
||||
while true; do
|
||||
get_info
|
||||
|
||||
if [[ "$status" == "Discharging" && "$percentage" -le "$CRITICAL" ]]; then
|
||||
notify critical "Battery Critically Low" "$percentage% — suspending."
|
||||
$ACTION
|
||||
|
||||
elif [[ "$status" == "Discharging" && "$percentage" -le "$LOW" ]]; then
|
||||
if [[ "$last_state" != "low" ]]; then
|
||||
notify normal "Battery Low" "$percentage% remaining."
|
||||
last_state="low"
|
||||
fi
|
||||
|
||||
elif [[ "$status" != "Discharging" && "$percentage" -ge "$FULL" ]]; then
|
||||
if [[ "$last_state" != "full" ]]; then
|
||||
notify normal "Battery Full" "$percentage% — unplug charger."
|
||||
last_state="full"
|
||||
fi
|
||||
|
||||
else
|
||||
last_state=""
|
||||
fi
|
||||
|
||||
sleep "$INTERVAL"
|
||||
done
|
||||
'';
|
||||
}
|
||||
@@ -1,71 +1,69 @@
|
||||
{ writeShellApplication
|
||||
, libnotify
|
||||
, systemd
|
||||
}:
|
||||
|
||||
# taken and adapted https://github.com/miniMinn24/Battery_Notify with MIT License
|
||||
{ writeShellApplication, mplayer, brightnessctl, ... }:
|
||||
let
|
||||
NotifySound = ../../assets/battery_notify.mp3;
|
||||
in
|
||||
writeShellApplication {
|
||||
name = "custom-batterynotify";
|
||||
name = "custom-batterynotify";
|
||||
runtimeInputs = [
|
||||
mplayer
|
||||
brightnessctl
|
||||
];
|
||||
text = ''
|
||||
|
||||
runtimeInputs = [
|
||||
libnotify # provides notify-send
|
||||
systemd # provides systemctl
|
||||
];
|
||||
# Delay for startup
|
||||
sleep 5
|
||||
|
||||
text = ''
|
||||
set -euo pipefail
|
||||
# Change your sound path here
|
||||
|
||||
LOW="''${BATTERY_LOW_THRESHOLD:-20}"
|
||||
CRITICAL="''${BATTERY_CRITICAL_THRESHOLD:-5}"
|
||||
FULL="''${BATTERY_FULL_THRESHOLD:-95}"
|
||||
INTERVAL="''${BATTERY_INTERVAL:-30}"
|
||||
ACTION="''${BATTERY_CRITICAL_ACTION:-systemctl suspend}"
|
||||
|
||||
notify() {
|
||||
notify-send -a "Battery" -u "$1" "$2" "$3"
|
||||
}
|
||||
|
||||
get_info() {
|
||||
total=0
|
||||
count=0
|
||||
|
||||
for bat in /sys/class/power_supply/BAT*; do
|
||||
[ -f "$bat/capacity" ] || continue
|
||||
capacity=$(<"$bat/capacity")
|
||||
status=$(<"$bat/status")
|
||||
total=$((total + capacity))
|
||||
count=$((count + 1))
|
||||
done
|
||||
|
||||
[ "$count" -gt 0 ] || exit 0
|
||||
percentage=$((total / count))
|
||||
}
|
||||
|
||||
last_state=""
|
||||
|
||||
while true; do
|
||||
get_info
|
||||
|
||||
if [[ "$status" == "Discharging" && "$percentage" -le "$CRITICAL" ]]; then
|
||||
notify critical "Battery Critically Low" "$percentage% — suspending."
|
||||
$ACTION
|
||||
|
||||
elif [[ "$status" == "Discharging" && "$percentage" -le "$LOW" ]]; then
|
||||
if [[ "$last_state" != "low" ]]; then
|
||||
notify normal "Battery Low" "$percentage% remaining."
|
||||
last_state="low"
|
||||
fi
|
||||
|
||||
elif [[ "$status" != "Discharging" && "$percentage" -ge "$FULL" ]]; then
|
||||
if [[ "$last_state" != "full" ]]; then
|
||||
notify normal "Battery Full" "$percentage% — unplug charger."
|
||||
last_state="full"
|
||||
fi
|
||||
|
||||
else
|
||||
last_state=""
|
||||
fi
|
||||
|
||||
sleep "$INTERVAL"
|
||||
done
|
||||
'';
|
||||
playsound() {
|
||||
mplayer ${NotifySound}
|
||||
}
|
||||
|
||||
adjustBrightness() {
|
||||
local adjustment="$1"
|
||||
brightnessctl set "$adjustment"
|
||||
}
|
||||
|
||||
sendNotification() {
|
||||
local title="$1"
|
||||
local message="$2"
|
||||
notify-send -h string:x-canonical-private-synchronous:sys-notify -e -u low "$title" "$message"
|
||||
}
|
||||
|
||||
# Runs full time in background
|
||||
x=0
|
||||
while true; do
|
||||
Battery_Status="$(cat /sys/class/power_supply/BAT*/status)"
|
||||
Battery_Capacity=$(cat /sys/class/power_supply/BAT*/capacity)
|
||||
|
||||
case "$Battery_Status" in
|
||||
"Discharging")
|
||||
if [ $x -eq 1 ]; then
|
||||
sendNotification "Discharging" "Remains: <b>''${Battery_Capacity}%</b>"
|
||||
adjustBrightness "15%-"
|
||||
playsound
|
||||
x=0
|
||||
fi
|
||||
;;
|
||||
"Charging")
|
||||
if [ $x -eq 0 ]; then
|
||||
sendNotification "Charging" "Current: <b>''${Battery_Capacity}%</b>"
|
||||
adjustBrightness "15%+"
|
||||
playsound
|
||||
x=1
|
||||
fi
|
||||
;;
|
||||
"Full")
|
||||
if [ $x -eq 0 ]; then
|
||||
sendNotification "Fully Charged" "Noice: <b>''${Battery_Capacity}%</b>"
|
||||
playsound
|
||||
x=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
sleep 1
|
||||
done
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# taken and adapted https://github.com/miniMinn24/Battery_Notify with MIT License
|
||||
{ writeShellApplication, mplayer, brightnessctl, ... }:
|
||||
let
|
||||
NotifySound = ../../assets/battery_notify.mp3;
|
||||
in
|
||||
writeShellApplication {
|
||||
name = "custom-batterywarning";
|
||||
runtimeInputs = [
|
||||
mplayer
|
||||
brightnessctl
|
||||
];
|
||||
text = ''
|
||||
|
||||
# Delay for startup
|
||||
sleep 5
|
||||
|
||||
# Change your sound path here
|
||||
|
||||
playsound() {
|
||||
mplayer ${NotifySound}
|
||||
}
|
||||
|
||||
sendNotification() {
|
||||
local message="$1"
|
||||
notify-send -h string:x-canonical-private-synchronous:sys-notify -e -u critical "Battery Low!" "$message"
|
||||
}
|
||||
|
||||
notify_count=0
|
||||
|
||||
while true; do
|
||||
Battery_Status="$(cat /sys/class/power_supply/BAT*/status)"
|
||||
Battery_Capacity=$(cat /sys/class/power_supply/BAT*/capacity)
|
||||
|
||||
if [ "$Battery_Status" == "Discharging" ] && [ "$Battery_Capacity" -le 14 ]; then
|
||||
if [ "$notify_count" -eq 0 ]; then
|
||||
sendNotification "Power running out: <b>''${Battery_Capacity}%</b>"
|
||||
playsound
|
||||
notify_count=$((notify_count + 1))
|
||||
sleep 180
|
||||
|
||||
elif [ "$notify_count" -eq 1 ]; then
|
||||
sendNotification "<b>Save your works</b> before immediate shutdown."
|
||||
playsound
|
||||
notify_count=$((notify_count - 1))
|
||||
sleep 180
|
||||
fi
|
||||
else
|
||||
notify_count=0
|
||||
sleep 120
|
||||
fi
|
||||
done
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user