hyprland - battery notification, qutebrowser

This commit is contained in:
foglar 2025-01-26 17:13:48 +01:00
parent f4ed83dc98
commit 94f93e01bb
3 changed files with 134 additions and 2 deletions

View File

@ -87,6 +87,134 @@
'') '')
(writeShellScriptBin "battery-notify" ''
# Configuration variables (with default values)
dock="''${BATTERY_NOTIFY_DOCK:-true}"
batterynotify_conf="$HYDE_STATE_HOME/staterc"
battery_full_threshold="''${BATTERY_NOTIFY_THRESHOLD_FULL:-100}"
battery_critical_threshold="''${BATTERY_NOTIFY_THRESHOLD_CRITICAL:-5}"
unplug_charger_threshold="''${BATTERY_NOTIFY_THRESHOLD_UNPLUG:-80}"
battery_low_threshold="''${BATTERY_NOTIFY_THRESHOLD_LOW:-20}"
timer="''${BATTERY_NOTIFY_TIMER:-120}"
notify="''${BATTERY_NOTIFY_NOTIFY:-1140}"
interval="''${BATTERY_NOTIFY_INTERVAL:-5}"
execute_critical="''${BATTERY_NOTIFY_EXECUTE_CRITICAL:-systemctl suspend}"
execute_low="''${BATTERY_NOTIFY_EXECUTE_LOW:-}"
execute_unplug="''${BATTERY_NOTIFY_EXECUTE_UNPLUG:-}"
execute_charging="''${BATTERY_NOTIFY_EXECUTE_CHARGING:-}"
execute_discharging="''${BATTERY_NOTIFY_EXECUTE_DISCHARGING:-}"
verbose=false
# Display configuration info
config_info() {
cat <<EOF
Modify $batterynotify_conf to set options.
STATUS THRESHOLD INTERVAL
Full $battery_full_threshold $notify Minutes
Critical $battery_critical_threshold $timer Seconds then '$execute_critical'
Low $battery_low_threshold $interval Percent then '$execute_low'
Unplug $unplug_charger_threshold $interval Percent then '$execute_unplug'
Charging: $execute_charging
Discharging: $execute_discharging
EOF
}
# Check if system is a laptop
is_laptop() {
if ! grep -q "Battery" /sys/class/power_supply/BAT*/type 2>/dev/null; then
echo "No battery detected. Exiting."
exit 0
fi
}
# Display verbose information
fn_verbose() {
if $verbose; then
echo "============================================="
echo "Battery Status: $battery_status"
echo "Battery Percentage: $battery_percentage"
echo "============================================="
fi
}
# Handle battery notifications
notify_user() {
local urgency=$1
local title=$2
local message=$3
notify-send -a "HyDE Power" -t 5000 -u "$urgency" "$title" "$message"
}
# Get battery status and percentage
get_battery_info() {
local total_percentage=0 battery_count=0
for battery in /sys/class/power_supply/BAT*; do
battery_status=$(<"$battery/status")
battery_percentage=$(<"$battery/capacity")
total_percentage=$((total_percentage + battery_percentage))
battery_count=$((battery_count + 1))
done
battery_percentage=$((total_percentage / battery_count))
}
# Check battery thresholds
check_thresholds() {
if [[ "$battery_percentage" -ge "$unplug_charger_threshold" && "$battery_status" != "Discharging" ]]; then
notify_user "NORMAL" "Battery Charged" "Battery is at $battery_percentage%. You can unplug the charger!"
elif [[ "$battery_percentage" -le "$battery_critical_threshold" ]]; then
notify_user "CRITICAL" "Battery Critically Low" "$battery_percentage% remaining. Executing critical action."
$execute_critical
elif [[ "$battery_percentage" -le "$battery_low_threshold" && "$battery_status" == "Discharging" ]]; then
notify_user "NORMAL" "Battery Low" "$battery_percentage% remaining. Connect the charger."
$execute_low
fi
}
# Monitor battery status changes
monitor_battery() {
while :; do
get_battery_info
check_thresholds
sleep $interval
done
}
# Main function
main() {
is_laptop
config_info
if $verbose; then
echo "Verbose Mode is ON."
fi
monitor_battery
}
# Parse script arguments
case "$1" in
-i|--info)
config_info
exit 0
;;
-v|--verbose)
verbose=true
;;
-h|--help|*)
cat <<HELP
Usage: $0 [options]
[-i|--info] Display configuration information
[-v|--verbose] Enable verbose mode
[-h|--help] Show this help message
HELP
exit 0
;;
esac
main
'')
#(writeShellScriptBin "windowpin") #(writeShellScriptBin "windowpin")
]) ])
++ (with pkgs-stable; [ ++ (with pkgs-stable; [

View File

@ -130,7 +130,8 @@
"${pkgs.wl-clipboard}/bin/wl-paste --type image --watch cliphist store # clipboard store image data" "${pkgs.wl-clipboard}/bin/wl-paste --type image --watch cliphist store # clipboard store image data"
"${pkgs.swayosd}/bin/swayosd-server" "${pkgs.swayosd}/bin/swayosd-server"
"${pkgs.bitwarden}/bin/bitwarden" "${pkgs.bitwarden}/bin/bitwarden"
"battery-notify --verbose"
"systemctl --user start hyprpolkitagent" "systemctl --user start hyprpolkitagent"
#"swww-daemon --format xrgb" #"swww-daemon --format xrgb"

View File

@ -236,7 +236,10 @@ in
'mn' : 'https://mynixos.com/search?q={}', 'mn' : 'https://mynixos.com/search?q={}',
'yt' : 'https://www.youtube.com/results?search_query={}', 'yt' : 'https://www.youtube.com/results?search_query={}',
'gh' : 'https://github.com/search?q={}&type=repositories', 'gh' : 'https://github.com/search?q={}&type=repositories',
} 'ph' : 'https://www.phind.com/search?q={}&searchMode=always&allowMultiSearch=false',
'g' : 'https://www.google.com/search?q={}',
'gi' : 'https://www.google.com/search?tbm=isch&q={}',
}
config.set('completion.open_categories',["searchengines","quickmarks","bookmarks"]) config.set('completion.open_categories',["searchengines","quickmarks","bookmarks"])