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