Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/16156

Daniel957a92895954
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts
index 8d87a166c3..0d744743e8 100644
--- a/app/src/config/bazaar.ts
+++ b/app/src/config/bazaar.ts
@@ -704,7 +704,8 @@ export const bazaar = {
fetchPost("/api/petal/setPetalEnabled", {
packageName: dataObj.name,
enabled: true,
- frontend: getFrontend()
+ frontend: getFrontend(),
+ app: Constants.SIYUAN_APPID,
}, (response) => {
loadPlugin(app, response.data);
bazaar._genMyHTML(bazaarType, app, false);
@@ -946,7 +947,8 @@ export const bazaar = {
fetchPost("/api/petal/setPetalEnabled", {
packageName: dataObj.name,
enabled,
- frontend: getFrontend()
+ frontend: getFrontend(),
+ app: Constants.SIYUAN_APPID,
}, (response) => {
target.removeAttribute("disabled");
if (enabled) {
diff --git a/kernel/api/petal.go b/kernel/api/petal.go
index 93206ef317..738d7cdcb7 100644
--- a/kernel/api/petal.go
+++ b/kernel/api/petal.go
@@ -20,6 +20,7 @@ import (
"net/http"
"github.com/88250/gulu"
+ "github.com/emirpasic/gods/sets/hashset"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -60,4 +61,16 @@ func setPetalEnabled(c *gin.Context) {
}
ret.Data = data
+
+ var app string
+ if nil != arg["app"] {
+ app = arg["app"].(string)
+ }
+ if enabled {
+ upsertPluginSet := hashset.New(packageName)
+ model.PushReloadPlugin(upsertPluginSet, nil, app)
+ } else {
+ removePluginSet := hashset.New(packageName)
+ model.PushReloadPlugin(nil, removePluginSet, app)
+ }
}
diff --git a/kernel/model/bazzar.go b/kernel/model/bazzar.go
index 5323253890..fd1d28f1b4 100644
--- a/kernel/model/bazzar.go
+++ b/kernel/model/bazzar.go
@@ -26,6 +26,7 @@ import (
"time"
"github.com/88250/gulu"
+ "github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/bazaar"
"github.com/siyuan-note/siyuan/kernel/task"
@@ -254,6 +255,9 @@ func UninstallBazaarPlugin(pluginName, frontend string) error {
}
petals = tmp
savePetals(petals)
+
+ removePluginSet := hashset.New(pluginName)
+ pushReloadPlugin(nil, removePluginSet, "")
return nil
}
diff --git a/kernel/model/push_reload.go b/kernel/model/push_reload.go
index 75b108379f..84a5061584 100644
--- a/kernel/model/push_reload.go
+++ b/kernel/model/push_reload.go
@@ -29,6 +29,7 @@ import (
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/emirpasic/gods/sets/hashset"
+ "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
@@ -37,6 +38,42 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
+func PushReloadPlugin(upsertPluginSet, removePluginNameSet *hashset.Set, excludeApp string) {
+ pushReloadPlugin(upsertPluginSet, removePluginNameSet, excludeApp)
+}
+
+func pushReloadPlugin(upsertPluginSet, removePluginNameSet *hashset.Set, excludeApp string) {
+ upsertPlugins, removePlugins := []string{}, []string{}
+ if nil != upsertPluginSet {
+ for _, n := range upsertPluginSet.Values() {
+ upsertPlugins = append(upsertPlugins, n.(string))
+ }
+ }
+ if nil != removePluginNameSet {
+ for _, n := range removePluginNameSet.Values() {
+ removePlugins = append(removePlugins, n.(string))
+ }
+ }
+
+ pushReloadPlugin0(upsertPlugins, removePlugins, excludeApp)
+}
+
+func pushReloadPlugin0(upsertPlugins, removePlugins []string, excludeApp string) {
+ logging.LogInfof("reload plugins [upserts=%v, removes=%v]", upsertPlugins, removePlugins)
+ if "" == excludeApp {
+ util.BroadcastByType("main", "reloadPlugin", 0, "", map[string]interface{}{
+ "upsertPlugins": upsertPlugins,
+ "removePlugins": removePlugins,
+ })
+ return
+ }
+
+ util.BroadcastByTypeAndExcludeApp(excludeApp, "main", "reloadPlugin", 0, "", map[string]interface{}{
+ "upsertPlugins": upsertPlugins,
+ "removePlugins": removePlugins,
+ })
+}
+
func refreshDocInfo(tree *parse.Tree) {
if nil == tree {
return
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 2fc718742b..d6cd3d3e5c 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -1690,7 +1690,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
}
if needReloadPlugin {
- pushReloadPlugin(upsertPluginSet, removePluginSet)
+ pushReloadPlugin(upsertPluginSet, removePluginSet, "")
}
for _, widgetDir := range removeWidgetDirSet.Values() {
@@ -2258,19 +2258,3 @@ func getCloudSpace() (stat *cloud.Stat, err error) {
}
return
}
-
-func pushReloadPlugin(upsertPluginSet, removePluginNameSet *hashset.Set) {
- upsertPlugins, removePlugins := []string{}, []string{}
- for _, n := range upsertPluginSet.Values() {
- upsertPlugins = append(upsertPlugins, n.(string))
- }
- for _, n := range removePluginNameSet.Values() {
- removePlugins = append(removePlugins, n.(string))
- }
-
- logging.LogInfof("reload plugins [upserts=%v, removes=%v]", upsertPlugins, removePlugins)
- util.BroadcastByType("main", "reloadPlugin", 0, "", map[string]interface{}{
- "upsertPlugins": upsertPlugins,
- "removePlugins": removePlugins,
- })
-}
diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go
index 7871f106aa..2e1f3c0224 100644
--- a/kernel/util/websocket.go
+++ b/kernel/util/websocket.go
@@ -32,6 +32,29 @@ var (
sessions = sync.Map{} // {appId, {sessionId, session}}
)
+func BroadcastByTypeAndExcludeApp(excludeApp, typ, cmd string, code int, msg string, data interface{}) {
+ sessions.Range(func(key, value interface{}) bool {
+ appSessions := value.(*sync.Map)
+ if key == excludeApp {
+ return true
+ }
+
+ appSessions.Range(func(key, value interface{}) bool {
+ session := value.(*melody.Session)
+ if t, ok := session.Get("type"); ok && typ == t {
+ event := NewResult()
+ event.Cmd = cmd
+ event.Code = code
+ event.Msg = msg
+ event.Data = data
+ session.Write(event.Bytes())
+ }
+ return true
+ })
+ return true
+ })
+}
+
func BroadcastByTypeAndApp(typ, app, cmd string, code int, msg string, data interface{}) {
appSessions, ok := sessions.Load(app)
if !ok {