Why use it? it's handy if you're in the habit of running your battery until it's totally dead, resulting in a hard, instant, dirty shutdown-- which can't be too healthy for your hardware or your puppy OS
Requirements:
this pet requires xfce4-battery-plugin.
Tested on xSlacko-b7 and Vlina-r2. Hopefully, other peeps here can report if it works on other puppies.
How to use it? nothing to configure, just install it. To see how it's set up, pop open your Battery Monitor config panel by right-clicking the Battery Monitor tray icon, and click "Properties". You'll see that "Critical Battery Action" has been set to "Run Command", and xfce4-shutdowncounter has been loaded into the "Command" field. The command will be executed when your battery discharges to critical level-- it's a script which displays the graphic shutdown alert shown above. You don't have to do anything else.
Optionally, the timeout seconds can be customized by entering your desired timeout seconds in the battery monitor config 'Command' box, after "xfce4-shutdowncounter":
How to test: Save and close all work. open a CLI terminal window, and enter xfce4-shutdowncounter. You should see the progress gauge. Allow the progress gauge 60 seconds to run out. Then your machine should shutdown.
Gotchas: This pet has one gotcha. The xfce panel has a watchdog, which checks for faulty panel applets which repeatedly restart within a small time-window. Therefor, if you install and uninstall this pet within 1 minute, then you will see this alert:
don't be alarmed, just click "Execute" to restore the battery monitor. If you click "Remove", no worries: just manually re-add the battery monitor to your panel using xfce panel preferences. No settings will be corrupted.
enjoy!
Technical Details
PQ - Puppiness Quotient: No known bugs, bloat-free, well commented, no extra depends. 4-line installer, 9-line bash script, 4-line Uninstaller. No other code. Executes only on low battery. Triggered by official xfce process, not a listener. No adware, malware, viruses, or bots, just does what it 'posed ta do. All code documented below.
How does it work? This xfce4-shutdowncounter script displays the dialog-box powerdown progress gauge above:
Code: Select all
#!/bin/sh
# get script path, so it can find icon
mypath="`dirname $0`"
# get optional user waittime. Default to 60 seconds.
waittime=${1:-60}
# get step size for gauge by converting waittime to 100%
stepsize=$((100 / $waittime))
# loop once per second, updating progress bar as you go.
(for (( percent=$stepsize; percent <= 100; percent+=$stepsize ))
do
# update progress bar
echo "$percent"
sleep 1
done) |
# display gauge
Xdialog --title "Battery Monitor" --icon "$mypath/xfce4-battery-critical.xpm" --gauge "Battery dangerously low!
This computer will power down in $waittime seconds.
To cancel the shutdown, close this window.
% remaining:" 13 60
# if gauge was not closed prematurely, then shutdown the computer.
[ "$?" = 0 ] && wmpoweroff
The installer enters settings into the Battery Monitor panel by writing values to the Battery Monitor config file:
/root/.config/xfce4/panel/battery-10.rc
Before installation, the config file includes the following:
Code: Select all
...
action_on_critical=1
command_on_critical=
Code: Select all
...
action_on_critical=2
command_on_critical=xfce4-shutdowncounter
Code: Select all
#!/bin/bash
# set battery monitor to run a command on critical level, and write new critical action command to battery config. then kill battery monitor to apply new settings. It will restart automatically.
# set battery config to run a command on critical
sed -i 's,^\(action_on_critical=\).*,\1'2',' /root/.config/xfce4/panel/battery-10.rc
# add command to battery config file.
sed -i 's,^\(command_on_critical=\).*,\1'xfce4-shutdowncounter',' /root/.config/xfce4/panel/battery-10.rc
# kill battery monitor. will restart automatically.
kill -9 $(ps -ef | grep libbattery.so | grep -v grep | awk '{ print $2 }')
Code: Select all
#!/bin/bash
# clear the critical action command from battery monitor, set run default standard alert. then kill battery monitor to apply the change. It will restart automatically.
# remove command from battery config.
sed -i 's,^\(command_on_critical=\).*,\1'',' /root/.config/xfce4/panel/battery-10.rc
# set battery config to display standar alert on critical
sed -i 's,^\(action_on_critical=\).*,\1'1',' /root/.config/xfce4/panel/battery-10.rc
# kill battery monitor. will restart automatically.
kill -9 $(ps -ef | grep libbattery.so | grep -v grep | awk '{ print $2 }')
- xfce4-battery-plugin does not use xfce's xfconf system. Therefor, the installer for this pet must kill the battery monitor temporarily for the new settings to take effect. The battery monitor terminates and restarts so quickly you may not even see it happen. If by chance the battery monitor dev (or someone) makes an xfconf patch for the battery monitor, then the kill should not be necessary, and the panel alert mentioned above will never happen.
- currently using xdialog, because simple. Drawback: only displays a percentage gauge, so wait-time has to be scaled to 100%.
- i might have used the pre-existing /etc/acpi/actions/acpi_poweroff.sh as my shutdown counter. acpi_poweroff has more features, but that script is about 175 lines of code, and my shutdown counter is only 9 lines of code. I prefer simple/small
Changes:
- 3.2 is path fix for icon.
- 3.3 works with different xfce install-id's of xfce4-battery-plugin config file., and handles spaces in directory names.