Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion backend/core/acctbind.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,45 @@
"""
from __future__ import annotations

from . import accounts, acctname, maa
from . import accounts, acctname, maa, settings


def _maa_of(snap) -> dict:
m = (snap or {}).get('maa')
return m if isinstance(m, dict) else {}


def _snap(file, snap=None):
if snap is not None:
return snap
try:
return accounts.get_account(file) or {}
except Exception:
return {}


def dir_of(file='', snap=None) -> str:
"""这个账号用哪个 MAA 目录:账号自己绑的 → 全局默认

2026-11-22 用户口径:每个账号都可以绑自己的 MAA 路径(设置 → MAA 路径
按账号填),不同 MAA 往往连的是不同模拟器。所以「跑这个号」的时候
必须按账号取目录,不能一律用全局那个——否则多开时全挤到同一台模拟器上,
表现就是「说好挂五个号,结果只有一个号在动」。
"""
d = str(_maa_of(_snap(file, snap)).get('dir') or '').strip()
if d:
return d
try:
return str(settings.load().get('maaDir') or '').strip()
except Exception:
return ''


def profile_of(file='', snap=None) -> str:
"""这个账号绑的 MAA 配置档案名(没绑给空串)"""
return str(_maa_of(_snap(file, snap)).get('profile') or '').strip()


def channel_of(snap) -> str:
a = (snap or {}).get('account')
return str((a.get('channelName') if isinstance(a, dict) else '') or '')
Expand Down
312 changes: 287 additions & 25 deletions backend/core/agent.py

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion backend/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,17 @@ def api_task(q, _body):
return t


def api_tasks(q, _body):
"""某个账号的相关任务(新的在前,带完整日志)

助手右栏的日志按账号分栏:切到哪个号,就把这个号的任务日志整块摆出来
(2026-11-22 用户要求「日志随账号切换」)。任务本身挂在后台线程上跑,
切号不影响它。
"""
return {'list': tasks.for_owner(q.get('file') or '',
int(q.get('limit') or 8))}


# ---------------------------------------------------------------- 观测(M2/M3)
def api_watch_status(q, _body):
"""MAA 现在跑到哪了。没开监控也能给个实时读数(前端一打开就要显示)"""
Expand Down Expand Up @@ -724,7 +735,8 @@ def api_multi_apply(_q, body):
raise ValueError('方案是空的(没有可执行的作业)')
d = _maa_dir_any(body.get('file'))
plan_data['maaDir'] = d
tid = tasks.create('多账号挂机(%d 个账号)' % len(rows))
tid = tasks.create('多账号挂机(%d 个账号)' % len(rows),
owners=[a.get('file') for a in rows if a.get('file')])
start = body.get('start', True)
tl = plan_data.get('tasks') or (
['startup', 'copilot', 'mall', 'award'] if start else ['startup'])
Expand Down Expand Up @@ -925,6 +937,7 @@ def api_schedule_stop(_q, _body):
'/api/maa/clear': api_maa_clear,
'/api/maa/tasklist': api_maa_tasklist,
'/api/task': api_task,
'/api/tasks': api_tasks,
'/api/export': api_export,
'/api/paradox/plan': api_paradox_plan,
'/api/paradox/pick': api_paradox_pick,
Expand Down
27 changes: 21 additions & 6 deletions backend/core/envcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,24 @@ def _ld_instance_up(emu_dir, index):


# ---------------------------------------------------------------- 读配置
def read_config():
"""收集连接参数。读不到 MAA 配置时返回空壳,调用方据此跳过检查。"""
def read_config(maa_dir=None, profile=None):
"""收集连接参数。读不到 MAA 配置时返回空壳,调用方据此跳过检查。

多开时每个账号绑的是不同 MAA(也往往连不同模拟器),所以这里能指定
看哪一份 MAA 配置——不指定就看全局默认那份。
"""
out = {'adb': '', 'address': '', 'kind': '', 'emu_dir': '', 'index': 0,
'name': '', 'source': ''}

# 1) MAA 的 gui.new.json
try:
from . import maa
cfg = maa._load_cfg()
cfg = maa._load_cfg(maa_dir or None)
except Exception: # noqa: BLE001 配置缺失不算错
cfg = None
if cfg:
configs = cfg.get('Configurations') or {}
name = cfg.get('Current') or ''
name = profile or cfg.get('Current') or ''
conf = (configs.get(name)
or (next(iter(configs.values())) if configs else {}) or {})
cs = ((conf.get('Gui') or {}).get('ConnectSettings') or {})
Expand Down Expand Up @@ -301,15 +305,26 @@ def wait_ready(cfg, timeout=WAIT_DEFAULT, log=None, quiet_until=8.0):


# ---------------------------------------------------------------- 对外
def ensure(log=None, wait=None):
def ensure(log=None, wait=None, maa_dir=None, profile=None, address=None):
"""开跑前确认环境,返回 ``(ok, 说明)``

一切正常时**一行日志都不写**(用户要的是「别显示出来」,只在他没开
模拟器的时候提示并代劳)。返回 False 时调用方应当直接停任务——连不上
设备还往下跑,只会在几十秒后报一句更难懂的「找不到关卡」。

``maa_dir`` / ``profile`` 指定看哪份 MAA 配置(多开时每个账号一份)。
``address`` 是多开时点名的模拟器地址:只查这一台在不在线,不在就直说,
**不会**去启动档案里那台(启动错了等于让两组抢同一台设备)。
"""
log = log or (lambda *_: None)
cfg = read_config()
cfg = read_config(maa_dir, profile)
if address:
devs = _devices(cfg['adb']) or {}
if devs.get(address) == 'device':
return True, 'adb 正常(%s)' % address
live = [a for a, s in devs.items() if s == 'device']
return False, ('指定的模拟器「%s」没在线(现在在线:%s)。'
'先把它开起来再重跑' % (address, '、'.join(live) or '无'))
if not cfg['adb'] and not cfg['emu_dir']:
return True, '没读到 MAA 配置,跳过环境检查'
if not _KINDS.get(cfg['kind']) and not cfg['emu_dir']:
Expand Down
Loading