fix: game plugin cache + test mode NullPointer crash on shutdown

- game_manager: add _scanned cache, _ensure_scanned() avoids re-scanning on every API call
- test_mode: fix AttributeError when stop_test_mode called before start
- listener: safe stop_test_mode with null check
This commit is contained in:
2026-07-26 18:19:03 +08:00
parent 90ab5f9c0b
commit 3b7edc4f14
2 changed files with 18 additions and 11 deletions
+8 -4
View File
@@ -68,11 +68,11 @@ class GamePluginManager:
USER_DIR.mkdir(parents=True, exist_ok=True)
self._plugins: dict[str, GamePlugin] = {}
self._parser_cache: dict[str, Any] = {}
self._scanned = False
self._discover()
def _discover(self):
self._plugins.clear()
for d in [BUILTIN_DIR, USER_DIR]:
if not d.exists():
continue
@@ -84,14 +84,18 @@ class GamePluginManager:
gp = GamePlugin.from_manifest(manifest, is_builtin)
if gp:
self._plugins[gp.id] = gp
logger.debug("Discovered game plugin: %s", gp.id)
self._scanned = True
def _ensure_scanned(self):
if not self._scanned:
self._discover()
def list_all(self) -> list[dict[str, Any]]:
self._discover()
self._ensure_scanned()
return [p.to_dict() for p in self._plugins.values()]
def get(self, plugin_id: str) -> GamePlugin | None:
self._discover()
self._ensure_scanned()
return self._plugins.get(plugin_id)
def get_parser(self, plugin_id: str) -> Any | None: