fix: 打开时等后台就绪再显示已保存登录
This commit is contained in:
@@ -143,7 +143,7 @@ async def _merge(changes: list[tuple[str, str, dict | None]]) -> None:
|
||||
|
||||
|
||||
async def available_accounts() -> list[dict]:
|
||||
"""并发向平台确认每条凭证。失效的删掉,暂时连不上的留着但不显示。"""
|
||||
"""并发向平台确认每条凭证。确认失效的删掉,暂时连不上的仍显示本机保存的信息。"""
|
||||
items = _read()
|
||||
probed = await asyncio.gather(*(_probe(item) for item in items))
|
||||
changes: list[tuple[str, str, dict | None]] = []
|
||||
@@ -151,8 +151,9 @@ async def available_accounts() -> list[dict]:
|
||||
for item, (status, record) in zip(items, probed):
|
||||
login_id = str(item.get("loginId") or "")
|
||||
changes.append((login_id, status, record))
|
||||
if status == "ok" and record is not None:
|
||||
visible.append(public_view(record))
|
||||
if status == "drop":
|
||||
continue
|
||||
visible.append(public_view(record if status == "ok" and record is not None else item))
|
||||
await _merge(changes)
|
||||
return visible
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ async def _saved_accounts_keep_temporary_failures(tmp_path: Path, monkeypatch):
|
||||
monkeypatch.setattr(NqiClient, "export_cookies", exported)
|
||||
visible = await sessions.available_accounts()
|
||||
stored = {item["loginId"]: item for item in sessions._read()}
|
||||
assert [item["loginId"] for item in visible] == ["a"]
|
||||
assert [item["loginId"] for item in visible] == ["a", "down"]
|
||||
assert "dead" not in stored
|
||||
assert stored["down"]["cookies"][0]["value"] == "down"
|
||||
assert stored["a"]["cookies"][0]["value"] == "a-new"
|
||||
@@ -445,7 +445,7 @@ async def _saved_accounts_probe_together_and_timeout_keeps_cookie(tmp_path: Path
|
||||
visible = await sessions.available_accounts()
|
||||
assert time.monotonic() - started < 0.5
|
||||
assert max(starts) - min(starts) < 0.2
|
||||
assert [item["loginId"] for item in visible] == ["b"]
|
||||
assert [item["loginId"] for item in visible] == ["b", "slow"]
|
||||
stored = {item["loginId"]: item for item in sessions._read()}
|
||||
assert stored["slow"]["cookies"][0]["value"] == "slow"
|
||||
assert stored["b"]["cookies"][0]["value"] == "b-new"
|
||||
|
||||
Reference in New Issue
Block a user