Skip to content

Add opt-in state retention for plugin WebUI pages - #294

Open
BernardXiong wants to merge 4 commits into
RT-Thread:masterfrom
BernardXiong:feature/ws
Open

Add opt-in state retention for plugin WebUI pages#294
BernardXiong wants to merge 4 commits into
RT-Thread:masterfrom
BernardXiong:feature/ws

Conversation

@BernardXiong

Copy link
Copy Markdown
Member

Summary

  • Add optional manifest.webui.keep_alive, defaulting to false.
  • Keep opted-in plugin iframes mounted while navigating between plugin pages, settings, and the plugin center.
  • Preserve the existing reload behavior for plugins without keep_alive.
  • Remove the top bar and move the “Exit WebUI” action to the bottom of the sidebar.
  • Scope plugin assets per plugin and expose optional backend HTTP/WebSocket context to sandboxed WebUI pages.

Implementation

  • Track iframe state, refs, and timeout timers per plugin.
  • Clean up iframe state when a plugin is disabled, uninstalled, upgraded, or its WebUI entry changes.
  • Support explicit iframe reload from the error state.
  • Update the manifest schema, validation, project scaffolding, documentation, and frontend/server API contracts.
  • Add WebSocket negotiation header forwarding and CSP declarations for plugin backend connections.

Validation

  • npm run typecheck
  • npm test -- --run
  • npm run test:e2e
  • pytest -q plugins/tests/test_manifest_package.py plugins/tests/test_epack_cli.py plugins/tests/test_webui_package.py plugins/tests/ test_webui_server.py

All targeted tests pass.

Compatibility

Existing plugin manifests remain valid. If keep_alive is omitted, the value is treated as false, so existing plugins retain the original
reload behavior.

为 manifest.webui 增加可选 keep_alive 字段并在脚手架、Schema、校验和测试中统一默认值。\n补充插件资源令牌、宿主上下文和 WebSocket 传输约定的中英文文档。
为每个插件分配独立的资源令牌,限制静态资源和 backend 路由的插件边界。\n补全 WebSocket 协商头转发、CSP 通道声明及服务端回归测试。
按插件维护 iframe 生命周期,keep_alive 插件切换页面时保留表单和临时状态,默认插件仍按原逻辑重新加载。\n移除顶部栏并将退出 WebUI 放入侧边栏底部,补充导航与状态保持 E2E 测试并更新静态资源。

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Asynchronous plugin checks can overwrite newer lifecycle state, and cleanup behavior lacks direct coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds opt-in iframe state retention and plugin-scoped backend transport support while simplifying WebUI navigation.

Changes:

  • Adds webui.keep_alive across manifests, scaffolding, documentation, and tests.
  • Retains opted-in plugin iframes and exposes scoped HTTP/WebSocket contexts.
  • Moves WebUI exit controls into the sidebar.
File summaries
File Description
plugins/webui/static/index.html References rebuilt frontend assets.
plugins/webui/server.py Adds scoped asset tokens and backend contexts.
plugins/webui/frontend/src/utils/plugins.ts Builds browser backend endpoints.
plugins/webui/frontend/src/utils/plugins.test.ts Tests endpoint conversion.
plugins/webui/frontend/src/types/api.ts Extends plugin and session contracts.
plugins/webui/frontend/src/styles.css Updates layout and iframe stacking.
plugins/webui/frontend/src/App.vue Implements retained iframe lifecycle and sidebar exit.
plugins/webui/frontend/e2e/webui.spec.ts Tests navigation retention and UI changes.
plugins/tests/test_webui_server.py Tests scoped assets, CSP, and WebSockets.
plugins/tests/test_manifest_package.py Validates keep_alive.
plugins/tests/test_epack_cli.py Verifies scaffold defaults.
plugins/spec/README.md Documents retention and backend transport.
plugins/spec/manifest-v1.schema.json Adds the schema field.
plugins/README.zh-CN.md Updates Chinese plugin documentation.
plugins/README.md Updates plugin documentation.
plugins/manifest.py Validates the optional field.
plugins/examples/build-insight-1.0.0/README.md Documents example host context.
plugins/epack/project.py Adds the scaffold default.
Review details
  • Files reviewed: 18/21 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +490 to +493
function startPluginCheck(view: string) {
clearIframeTimer(view)
setIframeState(view, 'checking')
api.doctor(view).then((result) => {
Comment on lines +277 to +281
if (!next || !next.enabled || !next.webui || (
previous && (
previous.version !== next.version
|| Boolean(previous.webui?.keep_alive) !== Boolean(next.webui?.keep_alive)
|| previous.webui?.entry !== next.webui?.entry
为每个插件的 doctor 请求增加代次校验,清理或重新检查后忽略过期的成功、失败和超时回调。\n补充 keep-alive 插件禁用后 iframe 被销毁、重新启用后创建新 iframe 的 E2E 覆盖。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants