Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-10-25 17:24:24 +08:00
parent a8f56e55e3
commit 957a928959
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 82 additions and 19 deletions

View file

@ -704,7 +704,8 @@ export const bazaar = {
fetchPost("/api/petal/setPetalEnabled", { fetchPost("/api/petal/setPetalEnabled", {
packageName: dataObj.name, packageName: dataObj.name,
enabled: true, enabled: true,
frontend: getFrontend() frontend: getFrontend(),
app: Constants.SIYUAN_APPID,
}, (response) => { }, (response) => {
loadPlugin(app, response.data); loadPlugin(app, response.data);
bazaar._genMyHTML(bazaarType, app, false); bazaar._genMyHTML(bazaarType, app, false);
@ -946,7 +947,8 @@ export const bazaar = {
fetchPost("/api/petal/setPetalEnabled", { fetchPost("/api/petal/setPetalEnabled", {
packageName: dataObj.name, packageName: dataObj.name,
enabled, enabled,
frontend: getFrontend() frontend: getFrontend(),
app: Constants.SIYUAN_APPID,
}, (response) => { }, (response) => {
target.removeAttribute("disabled"); target.removeAttribute("disabled");
if (enabled) { if (enabled) {

View file

@ -20,6 +20,7 @@ import (
"net/http" "net/http"
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/emirpasic/gods/sets/hashset"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/model" "github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util" "github.com/siyuan-note/siyuan/kernel/util"
@ -60,4 +61,16 @@ func setPetalEnabled(c *gin.Context) {
} }
ret.Data = data 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)
}
} }

View file

@ -26,6 +26,7 @@ import (
"time" "time"
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/bazaar" "github.com/siyuan-note/siyuan/kernel/bazaar"
"github.com/siyuan-note/siyuan/kernel/task" "github.com/siyuan-note/siyuan/kernel/task"
@ -254,6 +255,9 @@ func UninstallBazaarPlugin(pluginName, frontend string) error {
} }
petals = tmp petals = tmp
savePetals(petals) savePetals(petals)
removePluginSet := hashset.New(pluginName)
pushReloadPlugin(nil, removePluginSet, "")
return nil return nil
} }

View file

@ -29,6 +29,7 @@ import (
"github.com/88250/lute/parse" "github.com/88250/lute/parse"
"github.com/88250/lute/render" "github.com/88250/lute/render"
"github.com/emirpasic/gods/sets/hashset" "github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/av" "github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/filesys" "github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/sql"
@ -37,6 +38,42 @@ import (
"github.com/siyuan-note/siyuan/kernel/util" "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) { func refreshDocInfo(tree *parse.Tree) {
if nil == tree { if nil == tree {
return return

View file

@ -1690,7 +1690,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
} }
if needReloadPlugin { if needReloadPlugin {
pushReloadPlugin(upsertPluginSet, removePluginSet) pushReloadPlugin(upsertPluginSet, removePluginSet, "")
} }
for _, widgetDir := range removeWidgetDirSet.Values() { for _, widgetDir := range removeWidgetDirSet.Values() {
@ -2258,19 +2258,3 @@ func getCloudSpace() (stat *cloud.Stat, err error) {
} }
return 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,
})
}

View file

@ -32,6 +32,29 @@ var (
sessions = sync.Map{} // {appId, {sessionId, session}} 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{}) { func BroadcastByTypeAndApp(typ, app, cmd string, code int, msg string, data interface{}) {
appSessions, ok := sessions.Load(app) appSessions, ok := sessions.Load(app)
if !ok { if !ok {