Skip to content

Commit 54f3d3a

Browse files
authored
Merge pull request #239 from wnlen/dev
Dev
2 parents b08c89d + 8be724c commit 54f3d3a

3 files changed

Lines changed: 18 additions & 12 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: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,32 @@ 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 1:代理已经完整开启
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+
# 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
217+
print_on_feedback
218+
trap - ERR
219+
return 0
210220
fi
211221

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

287299
prepare
288-
service_stop
289300

290301
if system_proxy_disable; then
291302
:

uninstall.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,25 @@ for arg in "$@"; do
2121
esac
2222
done
2323

24-
# shellcheck source=scripts/core/common.sh
2524
source "$PROJECT_DIR/scripts/core/common.sh"
26-
# shellcheck source=scripts/core/runtime.sh
2725
source "$PROJECT_DIR/scripts/core/runtime.sh"
28-
# shellcheck source=scripts/core/config.sh
2926
source "$PROJECT_DIR/scripts/core/config.sh"
30-
# shellcheck source=scripts/init/systemd.sh
27+
source "$PROJECT_DIR/scripts/core/proxy.sh"
3128
source "$PROJECT_DIR/scripts/init/systemd.sh"
32-
# shellcheck source=scripts/init/systemd-user.sh
3329
source "$PROJECT_DIR/scripts/init/systemd-user.sh"
34-
# shellcheck source=scripts/init/script.sh
3530
source "$PROJECT_DIR/scripts/init/script.sh"
3631

3732
init_project_context "$PROJECT_DIR"
3833
load_env_if_exists
3934
detect_install_scope auto
4035

36+
system_proxy_disable || true
37+
clear_shell_proxy_persist_state || true
4138
service_stop || true
4239
remove_runtime_entry || true
4340
remove_clashctl_entry || true
4441
remove_clashctl_completion || true
4542
remove_shell_alias_entry || true
46-
clear_shell_proxy_persist_state || true
4743

4844
if [ "$PURGE_RUNTIME" = "true" ]; then
4945
rm -rf "$RUNTIME_DIR"

0 commit comments

Comments
 (0)