1- """Clash -based network access restriction for student agents."""
1+ """Mihomo -based network access restriction for student agents."""
22
33from __future__ import annotations
44
@@ -39,20 +39,15 @@ def _get_clash_binary_path() -> Tuple[bool, str]:
3939 project_root = os .path .dirname (script_dir )
4040 exe_dir = os .path .dirname (os .path .abspath (sys .executable )) if getattr (sys , "frozen" , False ) else script_dir
4141
42- clash_path = os .path .join (project_root , "mihomo.exe" )
43- if os .path .isfile (clash_path ):
44- return True , clash_path
45- clash_path = os .path .join (exe_dir , "mihomo.exe" )
46- if os .path .isfile (clash_path ):
47- return True , clash_path
48- clash_path = os .path .join (exe_dir , "clash.exe" )
49- if os .path .isfile (clash_path ):
50- return True , clash_path
42+ mihomo_path = os .path .join (project_root , "mihomo.exe" )
43+ if os .path .isfile (mihomo_path ):
44+ return True , mihomo_path
45+ mihomo_path = os .path .join (exe_dir , "mihomo.exe" )
46+ if os .path .isfile (mihomo_path ):
47+ return True , mihomo_path
5148 if shutil .which ("mihomo" ):
5249 return True , "mihomo"
53- if shutil .which ("clash" ):
54- return True , "clash"
55- return False , "Clash binary not found"
50+ return False , "mihomo 可执行文件未找到"
5651
5752
5853def _ensure_config_dir () -> None :
@@ -248,10 +243,10 @@ def _start_clash_process(clash_path: str) -> Tuple[bool, str]:
248243 )
249244 time .sleep (1.5 )
250245 if _clash_process .poll () is not None :
251- return False , "Clash process exited immediately "
252- return True , "Clash started "
246+ return False , "mihomo 进程立即退出 "
247+ return True , "mihomo 已启动 "
253248 except Exception as e :
254- return False , f"Failed to start Clash : { e } "
249+ return False , f"启动 mihomo 失败 : { e } "
255250
256251
257252def _is_clash_running () -> bool :
@@ -278,7 +273,7 @@ def apply_blacklist(rules: List[Dict[str, str]]) -> Tuple[bool, str]:
278273
279274 ok , msg = _start_clash_process (clash_path )
280275 if not ok :
281- return False , f"启动 Clash 失败: { msg } "
276+ return False , f"启动 mihomo 失败: { msg } "
282277
283278 return True , f"已添加 { len (rules )} 条黑名单规则"
284279
@@ -298,7 +293,7 @@ def apply_whitelist(rules: List[Dict[str, str]]) -> Tuple[bool, str]:
298293
299294 ok , msg = _start_clash_process (clash_path )
300295 if not ok :
301- return False , f"启动 Clash 失败: { msg } "
296+ return False , f"启动 mihomo 失败: { msg } "
302297
303298 return True , f"已启用白名单模式,允许 { len (rules )} 个目标"
304299
@@ -318,7 +313,7 @@ def block_all_network() -> Tuple[bool, str]:
318313
319314 ok , msg = _start_clash_process (clash_path )
320315 if not ok :
321- return False , f"启动 Clash 失败: { msg } "
316+ return False , f"启动 mihomo 失败: { msg } "
322317
323318 return True , "已启用完全断网模式"
324319
@@ -346,13 +341,13 @@ def start_clash_if_config_exists() -> Tuple[bool, str]:
346341 return False , clash_path
347342
348343 if _is_clash_running ():
349- return True , "Clash 已在运行"
344+ return True , "mihomo 已在运行"
350345
351346 ok , msg = _start_clash_process (clash_path )
352347 if not ok :
353- return False , f"启动 Clash 失败: { msg } "
348+ return False , f"启动 mihomo 失败: { msg } "
354349
355- return True , "Clash 已启动"
350+ return True , "mihomo 已启动"
356351
357352
358353def get_current_restriction_status () -> Dict [str , Any ]:
0 commit comments