Fix multiproile settings #29
@@ -61,7 +61,7 @@ def _apply_profile(socketio, profile: dict) -> None:
|
|||||||
return
|
return
|
||||||
_applied_profiles.add(profile_id)
|
_applied_profiles.add(profile_id)
|
||||||
_log_status(profile, "applied", "Saved rTorrent startup config overrides applied", result=result)
|
_log_status(profile, "applied", "Saved rTorrent startup config overrides applied", result=result)
|
||||||
socketio.emit("rtorrent_config_applied", {"profile_id": profile_id, "result": result})
|
socketio.emit("rtorrent_config_applied", {"profile_id": profile_id, "result": result}, to=f"profile:{int(profile_id)}")
|
||||||
|
|
||||||
|
|
||||||
def schedule_startup_config_apply(socketio, delay_seconds: int = 60, retry_seconds: int = 30, max_wait_seconds: int = 3600) -> None:
|
def schedule_startup_config_apply(socketio, delay_seconds: int = 60, retry_seconds: int = 30, max_wait_seconds: int = 3600) -> None:
|
||||||
@@ -97,7 +97,7 @@ def schedule_startup_config_apply(socketio, delay_seconds: int = 60, retry_secon
|
|||||||
action="rtorrent_config",
|
action="rtorrent_config",
|
||||||
details={"error": str(exc)},
|
details={"error": str(exc)},
|
||||||
)
|
)
|
||||||
socketio.emit("rtorrent_config_applied", {"ok": False, "error": str(exc)})
|
socketio.emit("rtorrent_config_applied", {"ok": False, "profile_id": int(profile_id or 0), "error": str(exc)}, to=f"profile:{int(profile_id or 0)}" if profile_id else None)
|
||||||
socketio.sleep(max(5, int(retry_seconds)))
|
socketio.sleep(max(5, int(retry_seconds)))
|
||||||
|
|
||||||
socketio.start_background_task(runner)
|
socketio.start_background_task(runner)
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ def _poller_profiles() -> list[dict]:
|
|||||||
|
|
||||||
|
|
||||||
def emit_profile_event(socketio, event: str, payload: dict, profile_id: int) -> None:
|
def emit_profile_event(socketio, event: str, payload: dict, profile_id: int) -> None:
|
||||||
target = _profile_room(profile_id) if auth.enabled() else None
|
# Note: Profile-scoped events always go to the selected profile room, even when authentication is disabled.
|
||||||
socketio.emit(event, payload, to=target) if target else socketio.emit(event, payload)
|
scoped_payload = {**(payload or {}), "profile_id": int(profile_id)}
|
||||||
|
socketio.emit(event, scoped_payload, to=_profile_room(profile_id))
|
||||||
|
|
||||||
|
|
||||||
def _emit_profile(socketio, event: str, payload: dict, profile_id: int) -> None:
|
def _emit_profile(socketio, event: str, payload: dict, profile_id: int) -> None:
|
||||||
@@ -51,7 +52,7 @@ def _run_slow_profile_tasks(socketio, profile: dict, profile_id: int) -> None:
|
|||||||
profile_user_id = int(profile.get("user_id") or default_user_id())
|
profile_user_id = int(profile.get("user_id") or default_user_id())
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
torrent_stats.queue_refresh(socketio, profile, force=False, room=_profile_room(profile_id) if auth.enabled() else None)
|
torrent_stats.queue_refresh(socketio, profile, force=False, room=_profile_room(profile_id))
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_emit_profile(socketio, "torrent_stats_update", {"ok": False, "profile_id": profile_id, "error": str(exc)}, profile_id)
|
_emit_profile(socketio, "torrent_stats_update", {"ok": False, "profile_id": profile_id, "error": str(exc)}, profile_id)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ def _emit(name: str, payload: dict):
|
|||||||
if not _socketio:
|
if not _socketio:
|
||||||
return
|
return
|
||||||
profile_id = payload.get("profile_id")
|
profile_id = payload.get("profile_id")
|
||||||
if auth.enabled() and profile_id:
|
if profile_id:
|
||||||
# Note: Job/socket events are sent only to clients joined to the affected profile room.
|
# Note: Job/socket events are profile-room scoped so modals and toasts do not leak between rTorrent profiles.
|
||||||
_socketio.emit(name, payload, to=f"profile:{int(profile_id)}")
|
_socketio.emit(name, payload, to=f"profile:{int(profile_id)}")
|
||||||
else:
|
else:
|
||||||
_socketio.emit(name, payload)
|
_socketio.emit(name, payload)
|
||||||
@@ -359,9 +359,9 @@ def _emit_torrent_refresh(profile: dict, action_name: str) -> None:
|
|||||||
profile_id = int(profile["id"])
|
profile_id = int(profile["id"])
|
||||||
if diff.get("ok"):
|
if diff.get("ok"):
|
||||||
rows = torrent_cache.snapshot(profile_id)
|
rows = torrent_cache.snapshot(profile_id)
|
||||||
_emit("torrent_patch", {**diff, "summary": cached_summary(profile_id, rows, force=True)})
|
_emit("torrent_patch", {**diff, "profile_id": profile_id, "summary": cached_summary(profile_id, rows, force=True)})
|
||||||
else:
|
else:
|
||||||
_emit("rtorrent_error", diff)
|
_emit("rtorrent_error", {**diff, "profile_id": profile_id})
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
# Note: A failed live refresh must not change the already completed job result.
|
# Note: A failed live refresh must not change the already completed job result.
|
||||||
_emit("rtorrent_error", {"profile_id": int(profile.get("id") or 0), "error": str(exc)})
|
_emit("rtorrent_error", {"profile_id": int(profile.get("id") or 0), "error": str(exc)})
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user