mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-09 09:26:55 +08:00
fix(module): bind config reload to module manager (#6568)
This commit is contained in:
@@ -135,7 +135,12 @@ class ModuleManager(metaclass=Singleton):
|
||||
self,
|
||||
owner_class: type,
|
||||
) -> Optional[EventHandlerBinding]:
|
||||
"""按 canonical class identity 绑定当前 generation,停止态阻断 fallback 构造。"""
|
||||
"""按类型身份绑定管理器自身或运行模块,停止态阻断 fallback 构造。"""
|
||||
if owner_class is type(self):
|
||||
return EventHandlerBinding(
|
||||
instance=self,
|
||||
owner_name=type(self).__name__,
|
||||
)
|
||||
for spec in self._specs:
|
||||
with self._lock:
|
||||
implementation = self._modules.get(spec.id)
|
||||
|
||||
@@ -499,6 +499,31 @@ def test_config_event_reloads_same_instance_and_tracks_selector_changes(
|
||||
assert running.events == ["create", "start", "stop", "start", "stop"]
|
||||
|
||||
|
||||
def test_registered_config_event_activates_newly_enabled_module(
|
||||
module_manager_harness,
|
||||
) -> None:
|
||||
"""事件总线必须把配置变更绑定回当前 ModuleManager 实例。"""
|
||||
manager = module_manager_harness.manager
|
||||
handler = next(
|
||||
listener
|
||||
for listener in _config_changed_listeners().values()
|
||||
if getattr(listener, "__self__", None) is manager
|
||||
)
|
||||
_enable_sample(module_manager_harness.config_values)
|
||||
|
||||
eventmanager._EventManager__invoke_handler_by_type_sync(
|
||||
handler,
|
||||
Event(
|
||||
EventType.ConfigChanged,
|
||||
ConfigChangeEventData(key="Notifications"),
|
||||
),
|
||||
)
|
||||
|
||||
running = manager.get_running_module("SampleModule")
|
||||
assert running is not None
|
||||
assert running.events == ["create", "start"]
|
||||
|
||||
|
||||
def test_shutdown_is_irreversible(module_manager_harness, monkeypatch) -> None:
|
||||
"""shutdown 撤销全部可见实例,并拒绝通过 load_modules 再次启动。"""
|
||||
manager = module_manager_harness.manager
|
||||
|
||||
Reference in New Issue
Block a user