添加模式卡片下发
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from threading import RLock
|
||||
@@ -525,6 +526,7 @@ class ModeProfileRegistry:
|
||||
self.user_root = Path(user_root) if user_root is not None else self.profile_root
|
||||
self.session_user_profiles = user_root is not None
|
||||
self._profiles: list[ModeProfile] = []
|
||||
self._change_listeners: list[Callable[["ModeProfileRegistry"], None]] = []
|
||||
self._write_lock = RLock()
|
||||
self.reload()
|
||||
|
||||
@@ -547,6 +549,30 @@ class ModeProfileRegistry:
|
||||
if path.is_file()
|
||||
)
|
||||
self._profiles = profiles
|
||||
self._notify_change_listeners()
|
||||
|
||||
def add_change_listener(
|
||||
self,
|
||||
listener: Callable[["ModeProfileRegistry"], None],
|
||||
*,
|
||||
notify: bool = True,
|
||||
) -> None:
|
||||
"""Run ``listener`` after every successful registry reload.
|
||||
|
||||
Mode profiles remain YAML-backed. Listeners are intended for derived,
|
||||
read-only projections such as the LAN scene catalog; they do not replace
|
||||
or alter the existing persistence path.
|
||||
"""
|
||||
|
||||
with self._write_lock:
|
||||
if listener not in self._change_listeners:
|
||||
self._change_listeners.append(listener)
|
||||
if notify:
|
||||
listener(self)
|
||||
|
||||
def _notify_change_listeners(self) -> None:
|
||||
for listener in tuple(self._change_listeners):
|
||||
listener(self)
|
||||
|
||||
def profiles(self) -> list[ModeProfile]:
|
||||
return list(self._profiles)
|
||||
|
||||
Reference in New Issue
Block a user