mirror of
https://github.com/tw93/Mole.git
synced 2026-02-14 22:50:13 +00:00
🎨 Support system application uninstallation
This commit is contained in:
@@ -69,8 +69,17 @@ batch_uninstall_applications() {
|
|||||||
(while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null) &
|
(while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null) &
|
||||||
local sudo_keepalive_pid=$!
|
local sudo_keepalive_pid=$!
|
||||||
|
|
||||||
# Set up cleanup trap for sudo keepalive
|
# Append keepalive cleanup to existing traps without overriding them
|
||||||
trap "kill $sudo_keepalive_pid 2>/dev/null || true; wait $sudo_keepalive_pid 2>/dev/null || true" EXIT INT TERM
|
local _trap_cleanup_cmd="kill $sudo_keepalive_pid 2>/dev/null || true; wait $sudo_keepalive_pid 2>/dev/null || true"
|
||||||
|
for signal in EXIT INT TERM; do
|
||||||
|
local existing_trap
|
||||||
|
existing_trap=$(trap -p "$signal" | awk -F"'" '{print $2}')
|
||||||
|
if [[ -n "$existing_trap" ]]; then
|
||||||
|
trap "$existing_trap; $_trap_cleanup_cmd" "$signal"
|
||||||
|
else
|
||||||
|
trap "$_trap_cleanup_cmd" "$signal"
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show summary and get batch confirmation
|
# Show summary and get batch confirmation
|
||||||
@@ -80,10 +89,24 @@ batch_uninstall_applications() {
|
|||||||
echo -e "${YELLOW}⚠️ Running apps will be force-quit: ${RED}${running_apps[*]}${NC}"
|
echo -e "${YELLOW}⚠️ Running apps will be force-quit: ${RED}${running_apps[*]}${NC}"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
echo -e -n "${BLUE}Press ENTER to confirm, or any other key to cancel:${NC} "
|
printf "%b" "${BLUE}Press ENTER to confirm, or ESC/q to cancel:${NC} "
|
||||||
read -r
|
local confirm_key=""
|
||||||
|
IFS= read -r -s -n1 confirm_key || confirm_key=""
|
||||||
|
if [[ "$confirm_key" == $'\e' ]]; then
|
||||||
|
while IFS= read -r -s -n1 -t 0 rest; do
|
||||||
|
[[ -z "$rest" || "$rest" == $'\n' ]] && break
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
if [[ -n "$REPLY" ]]; then
|
local cancel=false
|
||||||
|
case "$confirm_key" in
|
||||||
|
""|$'\n'|$'\r') ;;
|
||||||
|
$'\e'|"q"|"Q") cancel=true ;;
|
||||||
|
*) cancel=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ "$cancel" == true ]]; then
|
||||||
log_info "Uninstallation cancelled by user"
|
log_info "Uninstallation cancelled by user"
|
||||||
# Clean up sudo keepalive if it was started
|
# Clean up sudo keepalive if it was started
|
||||||
if [[ -n "${sudo_keepalive_pid:-}" ]]; then
|
if [[ -n "${sudo_keepalive_pid:-}" ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user