Integrate graceful shutdown into power menu

inky
Elnu 2 years ago
parent a427c8d48a
commit 806d8c41df

@ -3,7 +3,6 @@
### TODO
- Make rofi power menu work by removing password requirement from shutdown, reboot, etc., which is normally done with `visudo` (see [this Stack Overflow thread](https://askubuntu.com/a/168885) and [Nix `sudo` option](https://search.nixos.org/options?channel=22.05&from=0&size=50&sort=relevance&type=packages&query=sudo).
- Package safe poweroff bash script required by rofi power menu
- Theme GRUB
- Find out how handling multiple hosts works so both desktop and ThinkPad configurations are buildable from flake
- Load in vim configuration

@ -3,7 +3,7 @@
substituteAll {
name = "rofi-power";
src = ./power.sh;
inherit = wmctrl;
dir = "bin";
isExecutable = true;
}

@ -21,13 +21,47 @@ if [[ $sure != $confirm ]]; then
fi
if [[ $chosen != $SUSPEND ]]; then
sh /home/elnu/scripts/graceful-shutdown/graceful_shutdown.sh
# based on https://github.com/ardadem/graceful-shutdown
TIMEOUT=10
APPLIST_TO_TERMINATE=(Discord firefox)
close_windows () {
wmctrl -l | awk '{print $1}' | while read -r wId
do
wmctrl -i -c $wId
done
}
window_timeout_countdown () {
for i in $(seq 1 $TIMEOUT);
do
if [[ -z $(wmctrl -l) ]]; then
return 0
fi
sleep 1
done
exit 1
}
terminate_processes () {
pidof ${APPLIST_TO_TERMINATE[@]} | tr ' ' '\n' | while read -r pId
do
kill -15 $pId
tail --pid=$pId -f /dev/null # wait until terminate it
done
}
close_windows
window_timeout_countdown
terminate_processes
fi
case "$chosen" in
$POWER_OFF) sudo poweroff ;;
$REBOOT) sudo reboot ;;
$SUSPEND) sudo systemctl suspend ;;
$POWER_OFF) poweroff ;;
$REBOOT) reboot ;;
$SUSPEND) systemctl suspend ;;
$LOG_OUT) i3-msg exit ;;
*) exit 1 ;;
esac

Loading…
Cancel
Save