Skip to content

Commit f1589ee

Browse files
committed
optimize: add fast path for already-enabled clashon
1 parent b08c89d commit f1589ee

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

scripts/core/clashctl.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,27 @@ cmd_on() {
195195
local relay_switch
196196
local relay_switch_file relay_err_file relay_rc
197197
local system_proxy_rc system_proxy_degraded="false"
198-
local already_on="false"
199198

200199
trap 'rc=$?; ui_error "开启代理失败:cmd_on 在第 ${LINENO} 行执行失败:${BASH_COMMAND}(返回码:${rc})"; ui_next "clashctl logs service"; exit "$rc"' ERR
201200

202201
prepare
203-
ensure_on_path_ready
204202

203+
# fast path:已经完全开启时,直接返回
205204
if status_is_running 2>/dev/null \
206205
&& proxy_controller_reachable 2>/dev/null \
207206
&& [ "$(system_proxy_status 2>/dev/null || echo off)" = "on" ] \
208207
&& system_proxy_matches_runtime 2>/dev/null; then
209-
already_on="true"
208+
print_on_feedback
209+
trap - ERR
210+
return 0
211+
fi
212+
213+
ensure_on_path_ready
214+
215+
if [ "$already_on" = "true" ]; then
216+
print_on_feedback
217+
trap - ERR
218+
return 0
210219
fi
211220

212221
if status_is_running 2>/dev/null && ! proxy_controller_reachable 2>/dev/null; then

0 commit comments

Comments
 (0)