Skip to content

Commit 8be724c

Browse files
committed
optimize: fast enable proxy when runtime is already running
1 parent 42833b3 commit 8be724c

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

scripts/core/alias.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ _clash_alias_auto_restore_proxy() {
258258
_clash_alias_persist_enabled || return 0
259259
_clash_alias_export_proxy || return 0
260260

261-
echo "♻️ 已恢复当前 shell 代理环境(来自持久化状态)"
262261
return 0
263262
}
264263

scripts/core/clashctl.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ cmd_on() {
200200

201201
prepare
202202

203-
# fast path:已经完全开启时,直接返回
203+
# fast path 1:代理已经完整开启
204204
if status_is_running 2>/dev/null \
205205
&& proxy_controller_reachable 2>/dev/null \
206206
&& [ "$(system_proxy_status 2>/dev/null || echo off)" = "on" ] \
@@ -210,14 +210,17 @@ cmd_on() {
210210
return 0
211211
fi
212212

213-
ensure_on_path_ready
214-
215-
if [ "$already_on" = "true" ]; then
213+
# fast path 2:runtime 已运行,只是系统代理被关了
214+
if status_is_running 2>/dev/null \
215+
&& proxy_controller_reachable 2>/dev/null; then
216+
system_proxy_enable || true
216217
print_on_feedback
217218
trap - ERR
218219
return 0
219220
fi
220221

222+
ensure_on_path_ready
223+
221224
if status_is_running 2>/dev/null && ! proxy_controller_reachable 2>/dev/null; then
222225
ui_warn "检测到内核已运行但控制器不可访问,正在重启以加载当前配置"
223226
service_restart || die_state "控制器启动失败:内核重启未完成" "clashctl logs mihomo"
@@ -294,7 +297,6 @@ cmd_off() {
294297
local system_proxy_rc
295298

296299
prepare
297-
service_stop
298300

299301
if system_proxy_disable; then
300302
:

0 commit comments

Comments
 (0)