feat: support Clash Verge global script on Windows
This commit is contained in:
@@ -4,14 +4,39 @@
|
||||
用法:
|
||||
python3 scripts/gen_clash_verge_script.py [--out 目标路径]
|
||||
|
||||
默认输出到 Clash Verge 数据目录 profiles/Script.js(全局直连规则的唯一正确机制,
|
||||
见 clash-verge-config 记忆)。生成后需在 Clash Verge 界面点「重启内核」生效。
|
||||
默认按 Windows/macOS 平台输出到 Clash Verge 数据目录 profiles/Script.js(全局直连
|
||||
规则的唯一正确机制)。生成后需在 Clash Verge 界面点「重启内核」生效。
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
DEFAULT_OUT = Path.home() / "Library/Application Support/io.github.clash-verge-rev.clash-verge-rev/profiles/Script.js"
|
||||
APP_ID = "io.github.clash-verge-rev.clash-verge-rev"
|
||||
|
||||
|
||||
def default_output_path(
|
||||
platform_name: str = sys.platform,
|
||||
*,
|
||||
home: Path | None = None,
|
||||
appdata: Path | None = None,
|
||||
) -> Path:
|
||||
"""返回当前平台的 Clash Verge 全局 Script.js 路径。"""
|
||||
home = home or Path.home()
|
||||
if platform_name == "win32":
|
||||
if appdata is None:
|
||||
roaming = os.environ.get("APPDATA")
|
||||
if not roaming:
|
||||
raise SystemExit("[error] Windows 环境缺少 APPDATA,无法定位 Clash Verge 数据目录")
|
||||
appdata = Path(roaming)
|
||||
return appdata / APP_ID / "profiles" / "Script.js"
|
||||
if platform_name == "darwin":
|
||||
return home / "Library/Application Support" / APP_ID / "profiles" / "Script.js"
|
||||
return home / ".local/share" / APP_ID / "profiles" / "Script.js"
|
||||
|
||||
|
||||
DEFAULT_OUT = default_output_path()
|
||||
|
||||
|
||||
def load_payload(path: Path) -> list[str]:
|
||||
@@ -22,7 +47,7 @@ def load_payload(path: Path) -> list[str]:
|
||||
if line.startswith("- "):
|
||||
payload.append(line[2:].strip())
|
||||
if not payload:
|
||||
raise SystemExit(f"❌ direct.yaml 里没有 payload 条目: {path}")
|
||||
raise SystemExit(f"[error] direct.yaml 里没有 payload 条目: {path}")
|
||||
return payload
|
||||
|
||||
|
||||
@@ -66,7 +91,7 @@ def main() -> None:
|
||||
out = Path(args.out)
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
out.write_text(script, encoding="utf-8")
|
||||
print(f"✅ 已生成 {out}({len(payload)} 条规则)")
|
||||
print(f"[ok] 已生成 {out}({len(payload)} 条规则)")
|
||||
print(" 请在 Clash Verge 界面点「重启内核」生效。")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user