bug fixes

This commit is contained in:
2024-09-17 17:21:59 -04:00
parent f393da8121
commit 9897ac7842
2 changed files with 11 additions and 11 deletions
-1
View File
@@ -1,4 +1,3 @@
chmod +x $PWD/run.sh chmod +x $PWD/run.sh
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl restart shownotif.service sudo systemctl restart shownotif.service
+11 -10
View File
@@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
PER=$(( $(cat /sys/class/power_supply/BAT1/charge_now) * 100 / $(cat /sys/class/power_supply/BAT1/charge_full) )) PER=$(( $(cat /sys/class/power_supply/BAT1/charge_now) * 100 / $(cat /sys/class/power_supply/BAT1/charge_full) ))
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )")
# Check if the PC is charging # Check if the PC is charging
@@ -11,7 +12,7 @@ declare -A props
# Load properties from file # Load properties from file
load_props() { load_props() {
local file="$PWD/props.txt" local file="$SCRIPT_DIR/props.txt"
if [[ -f "$file" ]]; then if [[ -f "$file" ]]; then
while IFS='=' read -r key value; do while IFS='=' read -r key value; do
props["$key"]="$value" props["$key"]="$value"
@@ -26,7 +27,7 @@ load_props() {
# Save properties to file # Save properties to file
save_props() { save_props() {
local file="$PWD/props.txt" local file="$SCRIPT_DIR/props.txt"
> "$file" > "$file"
for key in "${!props[@]}"; do for key in "${!props[@]}"; do
echo "$key=${props[$key]}" >> "$file" echo "$key=${props[$key]}" >> "$file"
@@ -39,31 +40,31 @@ load_props
# Battery percentage-based logic # Battery percentage-based logic
if [[ "$PER" -le 10 ]]; then if [[ "$PER" -le 10 ]]; then
# Always show notification if battery is 10% or less # Always show notification if battery is 10% or less
bash $PWD/shownotif.sh lowbat bash $SCRIPT_DIR/shownotif.sh lowbat
elif [[ "$PER" -le 20 && "${props["lowchargenotifsent"]}" == "false" ]]; then elif [[ "$PER" -le 20 && "${props["lowchargenotifsent"]}" == "false" ]]; then
# Show notification if battery is 20% or less, but only if it hasn't been sent already # Show notification if battery is 20% or less, but only if it hasn't been sent already
bash $PWD/shownotif.sh lowbat bash $SCRIPT_DIR/shownotif.sh lowbat
props["lowchargenotifsent"]=true props["lowchargenotifsent"]=true
fi fi
# Check if props["ischarge"] does not match IS_CHARGING and update accordingly # Check if props["ischarge"] does not match IS_CHARGING and update accordingly
if [[ "${props["ischarge"]}" != "$IS_CHARGING" ]]; then if [[ "${props["ischarge"]}" != "$IS_CHARGING" ]]; then
if [[ "$IS_CHARGING" == true ]]; then if [[ "$IS_CHARGING" == true ]]; then
bash $PWD/shownotif.sh charging-status-mismatch "Now Charging" bash $SCRIPT_DIR/shownotif.sh charging-status-mismatch "Now Charging"
else else
bash $PWD/shownotif.sh charging-status-mismatch "Now Unplugged" bash $SCRIPT_DIR/shownotif.sh charging-status-mismatch "Now Unplugged"
fi fi
props["ischarge"]=$IS_CHARGING props["ischarge"]=$IS_CHARGING
fi fi
# Check if the PC is charging and show a notification if needed # Check if the PC is charging and show a notification if needed
if [[ "$IS_CHARGING" == true && "${props["ischargingnotifshown"]}" == "false" ]]; then if [[ "$IS_CHARGING" == true && "${props["ischargingnotifshown"]}" == "false" ]]; then
bash $PWD/shownotif.sh charging bash $SCRIPT_DIR/shownotif.sh charging
props["ischargingnotifshown"]=true props["ischargingnotifshown"]=true
props["isunpluggednotifshown"]=false # Reset unplugged notification flag when charging props["isunpluggednotifshown"]=false # Reset unplugged notification flag when charging
elif [[ "$IS_CHARGING" == false && "${props["isunpluggednotifshown"]}" == "false" ]]; then elif [[ "$IS_CHARGING" == false && "${props["isunpluggednotifshown"]}" == "false" ]]; then
# Show unplugged notification when the PC is no longer charging # Show unplugged notification when the PC is no longer charging
bash $PWD/shownotif.sh unplugged bash $SCRIPT_DIR/shownotif.sh unplugged
props["isunpluggednotifshown"]=true props["isunpluggednotifshown"]=true
props["ischargingnotifshown"]=false # Reset charging notification flag when unplugged props["ischargingnotifshown"]=false # Reset charging notification flag when unplugged
fi fi
@@ -78,6 +79,6 @@ TEMP=$(sensors | grep -i 'temp1' | head -n 1 | awk '{print $2}' | sed 's/+//g;s/
# force to int # force to int
TEMP=${TEMP%.*} TEMP=${TEMP%.*}
if [ "$TEMP" -gt 20 ]; then if [ "$TEMP" -gt 75 ]; then
bash $PWD/shownotif.sh temperature bash $SCRIPT_DIR/shownotif.sh temperature
fi fi