Unregister plugin event bus on unload; expose registerCustomEventBus on window.siyuan#17066
Open
TCOTC wants to merge 2 commits intosiyuan-note:devfrom
Open
Unregister plugin event bus on unload; expose registerCustomEventBus on window.siyuan#17066TCOTC wants to merge 2 commits intosiyuan-note:devfrom
TCOTC wants to merge 2 commits intosiyuan-note:devfrom
Conversation
456308c to
44281b3
Compare
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the plugin event bus lifecycle and makes the event bus available to non-plugin code (JS snippets/themes) by exposing registerCustomEventBus() on window.siyuan, while also refactoring many internal event emissions to go through a shared emitToEventBus() helper.
Changes:
- Add
EventBus.destroy()and invoke it on plugin uninstall to auto-unregister event listeners on unload. - Expose
registerCustomEventBus()onwindow.siyuan(and type it) so snippets/themes can register their own event buses. - Refactor many
plugin.eventBus.emit(...)loops to a centralizedemitToEventBus(...)helper and simplify some call signatures (e.g.,lockScreen,processSync, flashcard emit helper).
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/window/index.ts | Adds registerCustomEventBus to window.siyuan and routes websocket/plugin events via emitToEventBus. |
| app/src/types/index.d.ts | Types window.siyuan.registerCustomEventBus() for external usage. |
| app/src/search/util.ts | Routes input-search emission through emitToEventBus. |
| app/src/protyle/wysiwyg/index.ts | Routes editor click event emission through emitToEventBus. |
| app/src/protyle/util/setEditMode.ts | Routes protyle mode switch emission through emitToEventBus. |
| app/src/protyle/util/paste.ts | Extends paste event handling to include customEventBuses in addition to plugin buses. |
| app/src/protyle/util/onGet.ts | Routes protyle load events through emitToEventBus. |
| app/src/protyle/util/destroy.ts | Routes protyle destroy event through emitToEventBus. |
| app/src/protyle/toolbar/index.ts | Routes several toolbar-related plugin events through emitToEventBus. |
| app/src/plugin/uninstall.ts | Calls plugin.eventBus.destroy() on uninstall instead of removing DOM comment nodes directly. |
| app/src/plugin/EventBus.ts | Implements listener tracking + destroy(), adds emitToEventBus, customEventBuses, and registerCustomEventBus. |
| app/src/mobile/util/onMessage.ts | Uses new processSync(data) signature and minor formatting fixes. |
| app/src/mobile/util/keyboardToolbar.ts | Routes mobile keyboard show/hide events through emitToEventBus. |
| app/src/mobile/util/MobileBackFoward.ts | Routes protyle switch/load events through emitToEventBus. |
| app/src/mobile/menu/index.ts | Updates lockScreen() call to new signature. |
| app/src/mobile/index.ts | Adds registerCustomEventBus to window.siyuan and routes websocket events via emitToEventBus. |
| app/src/mobile/editor.ts | Routes switch-protyle emission through emitToEventBus. |
| app/src/menus/workspace.ts | Updates lockScreen() call to new signature. |
| app/src/layout/dock/Files.ts | Routes notebook open/close events through emitToEventBus. |
| app/src/index.ts | Adds registerCustomEventBus to window.siyuan and routes websocket/plugin events via emitToEventBus. |
| app/src/editor/util.ts | Routes switch-protyle emission through emitToEventBus. |
| app/src/editor/openLink.ts | Routes open-siyuan-url-block emission through emitToEventBus. |
| app/src/dialog/processSystem.ts | Updates lockScreen() and processSync() to use emitToEventBus instead of iterating plugins. |
| app/src/card/openCard.ts | Routes flashcard action emission through emitToEventBus and removes redundant app parameter. |
| app/src/boot/globalEvent/keydown.ts | Updates lockScreen() call to new signature. |
| app/src/boot/globalEvent/command/global.ts | Updates lockScreen() call to new signature. |
| app/src/asset/index.ts | Routes PDF click event through emitToEventBus. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…gisterCustomEventBus on window.siyuan
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 33 out of 34 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description / 描述
Type of change / 变更类型
缺陷修复
新功能
修改文案或增加新语言
Checklist / 检查清单
我对自己的代码进行了自我审查
我拥有所提交代码的完整权利,并同意其以本项目的 AGPL-3.0 许可证授权
devbranch and has no merge conflictsPR 提交到
dev分支,并且没有合并冲突