feat(api,userbot,frontend): rename session device from the web ui

This commit is contained in:
hh committed 2026-08-06 00:51:58 +02:00
1 parent b1848a6620
commit 1898a51a9d
11 files changed
+207 -13

No files matched your search

+15 -5
View File
@@ -18,6 +18,7 @@ from utils.logging import logger, setup_logging
from utils.read.accounts import (
ACCOUNTS_CHANGED_CHANNEL,
inactive_session_names,
session_device_models,
sync_account,
)
from utils.read.watches import WATCHES_CHANGED_CHANNEL
@@ -30,6 +31,7 @@ setup_logging()
class RunningAccount:
client: PyroClient
consumer_task: asyncio.Task
device_model: str | None
def _sessions_dir() -> Path:
@@ -70,14 +72,20 @@ class AccountRegistry:
async def sync(self) -> None:
async with self._lock:
inactive = await inactive_session_names(self._pool)
models = await session_device_models(self._pool)
present: set[str] = set()
for path in sorted(_sessions_dir().glob("*.session")):
if path.stem in inactive:
await self._log_out(path)
continue
present.add(path.stem)
if path.stem not in self._running:
await self._start(path)
device_model = models.get(path.stem)
running = self._running.get(path.stem)
if running is not None and running.device_model != device_model:
await self._stop(path.stem)
running = None
if running is None:
await self._start(path, device_model)
for session_name in set(self._running) - present:
await self._stop(session_name)
@@ -85,9 +93,11 @@ class AccountRegistry:
for session_name in list(self._running):
await self._stop(session_name)
async def _start(self, path: Path) -> None:
async def _start(self, path: Path, device_model: str | None) -> None:
session_name = path.stem
client = PyroClient(session_name, workdir=str(path.parent))
client = PyroClient(
session_name, workdir=str(path.parent), device_model=device_model
)
try:
await client.start()
me = client.me
@@ -105,7 +115,7 @@ class AccountRegistry:
return
consumer = JobConsumer(client, self._pool, account_id)
self._running[session_name] = RunningAccount(
client, asyncio.create_task(consumer.run())
client, asyncio.create_task(consumer.run()), device_model
)
logger.info(f"[green]Client started:[/] {me.full_name} ({me.id})")
await _enqueue_once(self._pool, account_id, "sync_dialogs")