mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-04 06:15:09 +00:00
fix(web): find installed plugins before anything has discovered them (#594)
The web process discovers plugins lazily: plugin_manifests is empty until some endpoint calls discover_plugins(). Three routes consulted it without discovering, so they misbehaved for as long as nothing else had run -- which, after every ledmatrix-web restart, is until someone opens the dashboard: - POST /display/on-demand/start answered 404 "Plugin <id> not found" (or "Mode <mode> not found"). Measured on a rig: 404 for over three minutes after a web restart, until GET /plugins/installed ran. The browser UI loads the plugin list first, so API-only callers (the Home Assistant MQTT bridge, scripts) are the ones who hit it. - POST /plugins/toggle answered 404 "Plugin not found". - POST /config/main did not recognise a plugin section, so it skipped secret separation and merged the section as-is: the plugin's API key was written to config.json in plain text instead of config_secrets.json. Add _discovered_plugin_manifests(), which discovers when nothing has been yet, and rescans once when a specific plugin id (or, for on-demand by mode, a mode) is not found, so a plugin installed since the last scan is found too. _installed_plugin_ids() now uses it. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -568,21 +568,41 @@ def _installed_plugin_ids():
|
||||
enumerate the installed plugins and read each one's persisted summary by ID
|
||||
instead of relying on the tracker's in-memory `get_all_*` view.
|
||||
"""
|
||||
pm = api_v3.plugin_manager
|
||||
manifests = getattr(pm, 'plugin_manifests', None)
|
||||
if not manifests:
|
||||
# Only pay for a discovery scan when we haven't discovered anything yet;
|
||||
# subsequent polls reuse the already-populated manifest map.
|
||||
try:
|
||||
pm.discover_plugins()
|
||||
except Exception:
|
||||
logger.debug('discover_plugins failed while listing plugin ids', exc_info=True)
|
||||
manifests = getattr(pm, 'plugin_manifests', None)
|
||||
manifests = _discovered_plugin_manifests()
|
||||
try:
|
||||
return list(manifests.keys()) if manifests else []
|
||||
except Exception:
|
||||
logger.debug('listing plugin_manifests failed while building plugin ids', exc_info=True)
|
||||
return []
|
||||
def _discovered_plugin_manifests(plugin_id=None, rescan=False):
|
||||
"""The plugin manager's manifests, discovering plugins first if needed.
|
||||
|
||||
The web process discovers plugins lazily (see app.py): nothing scans at
|
||||
startup, so plugin_manifests is empty until some endpoint calls
|
||||
discover_plugins(). A route that looks a plugin up without coming through
|
||||
here answers "not found" for every installed plugin until something else
|
||||
has run -- after a web restart, POST /display/on-demand/start returned 404
|
||||
for minutes on a real rig, and only API-only callers ever noticed.
|
||||
|
||||
Scans when nothing is discovered yet, when ``plugin_id`` is given and not
|
||||
among the manifests (it may have been installed since the last scan), or
|
||||
when ``rescan`` is set (for lookups that are not by id, such as a mode).
|
||||
Otherwise the existing map is reused, so a steady stream of requests
|
||||
for known plugins costs nothing.
|
||||
|
||||
Returns the manifest map, or {} when there is no plugin manager.
|
||||
"""
|
||||
pm = api_v3.plugin_manager
|
||||
if pm is None:
|
||||
return {}
|
||||
manifests = getattr(pm, 'plugin_manifests', None)
|
||||
if not manifests or rescan or (plugin_id is not None and plugin_id not in manifests):
|
||||
try:
|
||||
pm.discover_plugins()
|
||||
except Exception:
|
||||
logger.warning('Plugin discovery failed', exc_info=True)
|
||||
manifests = getattr(pm, 'plugin_manifests', None)
|
||||
return manifests or {}
|
||||
def _do_transactional_uninstall(plugin_id, preserve_config):
|
||||
"""Execute an uninstall with snapshot-based rollback.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user