feat: 增加设置页和托盘,登录后关闭窗口留在托盘

This commit is contained in:
2026-10-26 08:28:16 +08:00
parent e78b8897fc
commit 331e316fd9
16 changed files with 501 additions and 52 deletions
+24 -1
View File
@@ -10,7 +10,7 @@ import uuid
from fastapi import APIRouter, HTTPException
from app.platform.client import NqiError, needs_captcha
from app.platform.sessions import available_accounts, remember_account, resume
from app.platform.sessions import available_accounts, clear_accounts, forget_account, list_local_accounts, remember_account, resume
from app.shared.state import state
logger = logging.getLogger("nqi.auth")
@@ -166,6 +166,29 @@ async def saved() -> dict:
return {"accounts": await available_accounts()}
@router.get("/accounts")
async def accounts() -> dict:
state.require_client()
return {"accounts": list_local_accounts()}
@router.delete("/accounts/{login_id}")
async def remove_account(login_id: str) -> dict:
state.require_client()
await forget_account(login_id)
return {"accounts": list_local_accounts()}
@router.delete("/accounts")
async def remove_accounts() -> dict:
state.require_client()
try:
await clear_accounts()
except NqiError as exc:
raise _bad(str(exc)) from exc
return {"accounts": []}
@router.post("/resume")
async def resume_saved(body: dict) -> dict:
login_id = str(body.get("loginId") or "").strip()
+14
View File
@@ -83,6 +83,20 @@ async def forget_account(login_id: str) -> None:
logger.warning("登录记录暂时写不进去: %s", exc)
def list_local_accounts() -> list[dict]:
"""本机保存的账号,不访问平台。"""
return [public_view(item) for item in _read()]
async def clear_accounts() -> None:
async with _write_lock:
try:
_write([])
except OSError as exc:
logger.warning("登录记录暂时写不进去: %s", exc)
raise NqiError("登录记录暂时无法清除") from exc
def public_view(item: dict) -> dict:
return {
"loginId": item.get("loginId") or "",