siyuan-note / siyuan

A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang.
https://b3log.org/siyuan
GNU Affero General Public License v3.0
17.84k stars 1.32k forks source link

请求新增开启/关闭文档的 API #11979

Closed M2uyo closed 1 month ago

M2uyo commented 1 month ago

In what scenarios do you need this feature?

想自己做个关闭指定窗口时重新打开并并钉住的插件 真的很需要 某个文档始终不被关闭

Describe the optimal solution

新增API

  1. 开启文档
  2. 关闭文档
  3. 钉住文档

    新增事件

  4. 文档打开事件
  5. 文档关闭事件

Describe the candidate solution

No response

Other information

No response

leolee9086 commented 1 month ago

开启文档的api在这里可以找到:https://github.com/siyuan-note/plugin-sample/blob/main/src/index.ts image

这个方法的实现在:https://github.com/siyuan-note/siyuan/blob/master/app/src/plugin/API.ts image

文档事件可以监听protyle的相关事件,也就是

                    this.eventBus.on("loaded-protyle-static", this.eventBusLog);
                    this.eventBus.on("loaded-protyle-dynamic", this.eventBusLog);
                    this.eventBus.on("switch-protyle", this.eventBusLog);
                    this.eventBus.on("destroy-protyle", this.eventBusLog);

相关示例代码同样在:https://github.com/siyuan-note/plugin-sample/blob/main/src/index.ts

M2uyo commented 1 month ago

感谢,有时间我自己尝试一下,但是好似还缺少一个订住文档的API。

M2uyo commented 1 month ago

@leolee9086 不知道我写的哪里有差错, 当我关闭 钉住的文档时就会报错(纯后端, 不是很能看明白前端的报错 (╯︵╰,)) 只开启了本插件和Asri主题

    async onload() {
        this.eventBus.on("destroy-protyle", this.OnDestroy_protyle);
    }

    private async OnDestroy_protyle({detail}: any) {
        if (detail.protyle.model.headElement.classList.contains("item--pin")) {
            console.log("inner", detail.protyle.block.id)
            await openTab({
                app: this.app,
                doc: {
                    id: detail.protyle.block.id
                },
                keepCursor: true
            })
        }
    }

image

88250 commented 1 month ago

我先关闭了,如果还有问题请继续跟帖,谢谢 :pray: