53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""MaaEnd 只补齐当前官方终端包的路径和 ADB 界面适配。"""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from ArknightsMaaConfig.maa import ADDRESS, REDROID, DIRECT, command, wait_android
|
|
|
|
|
|
def prepare(configure=False):
|
|
source = Path("/app/maaend")
|
|
version = json.loads((source / "interface.json").read_text())["version"]
|
|
target = Path("/state") / f"maaend-{version}"
|
|
if not target.exists():
|
|
shutil.copytree(source, target, symlinks=True)
|
|
# 保留原文件;CLI 不支持 hotkey 设置,ADB 使用原始 pipeline 的默认值。
|
|
original = target / "interface.upstream.json"
|
|
if not original.exists():
|
|
shutil.copyfile(target / "interface.json", original)
|
|
interface = json.loads(original.read_text())
|
|
interface["controller"] = [c for c in interface["controller"] if c["name"] == "ADB"]
|
|
interface["import"] = [p for p in interface["import"] if p != "tasks/setting/Keymap.json"]
|
|
(target / "interface.json").write_text(json.dumps(interface, ensure_ascii=False, indent=2))
|
|
work = target / "maafw"
|
|
config = json.loads(Path(__file__).with_name("maa_pi_config.json").read_text())
|
|
if not configure and not config.get("task"):
|
|
raise RuntimeError("请先配置 MaaEnd 任务并提交到 MAAsConfig,再启用 maaend。")
|
|
config["adb"].update(address=ADDRESS, adb_path="/usr/bin/adb")
|
|
(work / "config").mkdir(exist_ok=True)
|
|
(work / "config/maa_pi_config.json").write_text(json.dumps(config, ensure_ascii=False, indent=2))
|
|
return work
|
|
|
|
|
|
def main():
|
|
configure = sys.argv[1:] == ["configure"]
|
|
work = prepare(configure)
|
|
if command(["docker", "restart", REDROID]):
|
|
return 1
|
|
try:
|
|
if not wait_android():
|
|
return 1
|
|
return subprocess.run([str(work / "MaaPiCli")] + ([] if configure else ["-d"]), cwd=work, env=DIRECT).returncode
|
|
finally:
|
|
command(["docker", "stop", REDROID])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|