1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-07 21:29:20 +00:00

Simpler and faster

This commit is contained in:
Tw93
2025-12-05 14:21:18 +08:00
parent 90cb4f84f2
commit 5761fd87c8
10 changed files with 166 additions and 159 deletions

View File

@@ -1201,48 +1201,36 @@ force_kill_app() {
# Use executable name for precise matching, fallback to app name
local match_pattern="${exec_name:-$app_name}"
# Check if main process is running using exact match
local has_main_process=false
if pgrep -x "$match_pattern" > /dev/null 2>&1; then
has_main_process=true
fi
# Also check for related processes using fuzzy match
local has_related_processes=false
if pgrep -i "$match_pattern" > /dev/null 2>&1; then
has_related_processes=true
fi
# If nothing is running, return success
if [[ "$has_main_process" == false && "$has_related_processes" == false ]]; then
# Check if process is running using exact match only
if ! pgrep -x "$match_pattern" > /dev/null 2>&1; then
return 0
fi
# Try graceful termination first for exact match
if [[ "$has_main_process" == true ]]; then
pkill -x "$match_pattern" 2> /dev/null || true
fi
# Also try graceful termination for related processes
if [[ "$has_related_processes" == true ]]; then
pkill -i "$match_pattern" 2> /dev/null || true
fi
# Try graceful termination first
pkill -x "$match_pattern" 2> /dev/null || true
sleep 2
# Check again after graceful kill
if ! pgrep -i "$match_pattern" > /dev/null 2>&1; then
if ! pgrep -x "$match_pattern" > /dev/null 2>&1; then
return 0
fi
# Force kill if still running
pkill -9 -i "$match_pattern" 2> /dev/null || true
pkill -9 -x "$match_pattern" 2> /dev/null || true
sleep 2
# If still running and sudo is available, try with sudo
if pgrep -x "$match_pattern" > /dev/null 2>&1; then
if sudo -n true 2> /dev/null; then
sudo pkill -9 -x "$match_pattern" 2> /dev/null || true
sleep 2
fi
fi
# Final check with longer timeout for stubborn processes
local retries=3
while [[ $retries -gt 0 ]]; do
if ! pgrep -i "$match_pattern" > /dev/null 2>&1; then
if ! pgrep -x "$match_pattern" > /dev/null 2>&1; then
return 0
fi
sleep 1
@@ -1250,7 +1238,7 @@ force_kill_app() {
done
# Still running after all attempts
pgrep -i "$match_pattern" > /dev/null 2>&1 && return 1 || return 0
pgrep -x "$match_pattern" > /dev/null 2>&1 && return 1 || return 0
}
# Remove application icons from the Dock (best effort)