Improve onDataChanged method (#16472)

* 🐛 Improve onDataChanged method

fix https://github.com/siyuan-note/siyuan/pull/16244

重构、修复插件重启逻辑

重构

比如插件在 onload() 中插入了图标,uninstall 会把图标删除,afterLoadPlugin 又不能执行 onload() 把图标加回来

使用 getElementById

先加载插件样式

避免插入重复的样式

改进插件样式插入位置

* reloadPlugin
This commit is contained in:
Jeffrey Chen 2025-12-02 09:57:50 +08:00 committed by GitHub
parent d620daa530
commit bcdef64d0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 60 additions and 37 deletions

View file

@ -16,8 +16,7 @@ import {BlockPanel} from "../block/Panel";
import {Setting} from "./Setting";
import {clearOBG} from "../layout/dock/util";
import {Constants} from "../constants";
import {uninstall} from "./uninstall";
import {afterLoadPlugin} from "./loader";
import {restartPlugin} from "./loader";
export class Plugin {
private app: App;
@ -103,7 +102,7 @@ export class Plugin {
});
}
public onload() {
public onload(): Promise<void> | void {
// 加载
}
@ -118,8 +117,7 @@ export class Plugin {
public onDataChanged() {
// 存储数据变更
// 兼容 3.4.1 以前同步数据使用重载插件的问题
uninstall(this.app, this.name, false);
afterLoadPlugin(this);
restartPlugin(this.app, this);
}
public async updateCards(options: ICardData) {