Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/src/plugin/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,16 @@ export const afterLoadPlugin = (plugin: Plugin) => {
export const reloadPlugin = async (app: App, data: {
upsertCodePlugins?: string[],
upsertDataPlugins?: string[],
removePlugins?: string[]
unloadPlugins?: string[],
uninstallPlugins?: string[],
} = {}) => {
const {upsertCodePlugins = [], upsertDataPlugins = [], removePlugins = []} = data;
removePlugins.forEach((item) => {
const {upsertCodePlugins = [], upsertDataPlugins = [], unloadPlugins = [], uninstallPlugins = []} = data;
// 禁用
unloadPlugins.forEach((item) => {
uninstall(app, item, true);
});
// 卸载
uninstallPlugins.forEach((item) => {
uninstall(app, item, false);
});
upsertCodePlugins.forEach((item) => {
Expand Down
6 changes: 3 additions & 3 deletions kernel/api/petal.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func setPetalEnabled(c *gin.Context) {
}
if enabled {
upsertPluginCodeSet := hashset.New(packageName)
model.PushReloadPlugin(upsertPluginCodeSet, nil, nil, app)
model.PushReloadPlugin(upsertPluginCodeSet, nil, nil, nil, app)
} else {
removePluginSet := hashset.New(packageName)
model.PushReloadPlugin(nil, nil, removePluginSet, app)
unloadPluginSet := hashset.New(packageName)
model.PushReloadPlugin(nil, nil, unloadPluginSet, nil, app)
}
}
4 changes: 2 additions & 2 deletions kernel/model/bazzar.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ func UninstallBazaarPlugin(pluginName, frontend string) error {
petals = tmp
savePetals(petals)

removePluginSet := hashset.New(pluginName)
PushReloadPlugin(nil, nil, removePluginSet, "")
uninstallPluginSet := hashset.New(pluginName)
PushReloadPlugin(nil, nil, nil, uninstallPluginSet, "")
return nil
}

Expand Down
48 changes: 34 additions & 14 deletions kernel/model/push_reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,25 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)

func PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, removePluginNameSet *hashset.Set, excludeApp string) {
if nil != removePluginNameSet {
for _, n := range removePluginNameSet.Values() {
func PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, unloadPluginNameSet, uninstallPluginNameSet *hashset.Set, excludeApp string) {
// 集合去重
if nil != uninstallPluginNameSet {
for _, n := range uninstallPluginNameSet.Values() {
pluginName := n.(string)
if nil != upsertCodePluginSet {
upsertCodePluginSet.Remove(pluginName)
}
if nil != upsertDataPluginSet {
upsertDataPluginSet.Remove(pluginName)
}
if nil != unloadPluginNameSet {
unloadPluginNameSet.Remove(pluginName)
}
}
}
if nil != unloadPluginNameSet {
for _, n := range unloadPluginNameSet.Values() {
pluginName := n.(string)
// 如果插件在 removePluginSet 中,从其他集合中移除
if nil != upsertCodePluginSet {
upsertCodePluginSet.Remove(pluginName)
}
Expand All @@ -54,14 +68,13 @@ func PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, removePluginName
if nil != upsertCodePluginSet {
for _, n := range upsertCodePluginSet.Values() {
pluginName := n.(string)
// 如果插件在 upsertCodePluginSet 中,从 upsertDataPluginSet 中移除
if nil != upsertDataPluginSet {
upsertDataPluginSet.Remove(pluginName)
}
}
}

upsertCodePlugins, upsertDataPlugins, removePlugins := []string{}, []string{}, []string{}
upsertCodePlugins, upsertDataPlugins, unloadPlugins, uninstallPlugins := []string{}, []string{}, []string{}, []string{}
if nil != upsertCodePluginSet {
for _, n := range upsertCodePluginSet.Values() {
upsertCodePlugins = append(upsertCodePlugins, n.(string))
Expand All @@ -72,30 +85,37 @@ func PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, removePluginName
upsertDataPlugins = append(upsertDataPlugins, n.(string))
}
}
if nil != removePluginNameSet {
for _, n := range removePluginNameSet.Values() {
removePlugins = append(removePlugins, n.(string))
if nil != unloadPluginNameSet {
for _, n := range unloadPluginNameSet.Values() {
unloadPlugins = append(unloadPlugins, n.(string))
}
}
if nil != uninstallPluginNameSet {
for _, n := range uninstallPluginNameSet.Values() {
uninstallPlugins = append(uninstallPlugins, n.(string))
}
}

pushReloadPlugin0(upsertCodePlugins, upsertDataPlugins, removePlugins, excludeApp)
pushReloadPlugin0(upsertCodePlugins, upsertDataPlugins, unloadPlugins, uninstallPlugins, excludeApp)
}

func pushReloadPlugin0(upsertCodePlugins, upsertDataPlugins, removePlugins []string, excludeApp string) {
logging.LogInfof("reload plugins [codeChanges=%v, dataChanges=%v, removes=%v]", upsertCodePlugins, upsertDataPlugins, removePlugins)
func pushReloadPlugin0(upsertCodePlugins, upsertDataPlugins, unloadPlugins, uninstallPlugins []string, excludeApp string) {
logging.LogInfof("reload plugins [codeChanges=%v, dataChanges=%v, unloads=%v, uninstalls=%v]", upsertCodePlugins, upsertDataPlugins, unloadPlugins, uninstallPlugins)
if "" == excludeApp {
util.BroadcastByType("main", "reloadPlugin", 0, "", map[string]interface{}{
"upsertCodePlugins": upsertCodePlugins,
"upsertDataPlugins": upsertDataPlugins,
"removePlugins": removePlugins,
"unloadPlugins": unloadPlugins,
"uninstallPlugins": uninstallPlugins,
})
return
}

util.BroadcastByTypeAndExcludeApp(excludeApp, "main", "reloadPlugin", 0, "", map[string]interface{}{
"upsertCodePlugins": upsertCodePlugins,
"upsertDataPlugins": upsertDataPlugins,
"removePlugins": removePlugins,
"unloadPlugins": unloadPlugins,
"uninstallPlugins": uninstallPlugins,
})
}

Expand Down
10 changes: 6 additions & 4 deletions kernel/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
}
}

removeWidgetDirSet, removePluginSet := hashset.New(), hashset.New()
removeWidgetDirSet, unloadPluginSet, uninstallPluginSet := hashset.New(), hashset.New(), hashset.New()
for _, file := range mergeResult.Removes {
removes = append(removes, file.Path)
if strings.HasPrefix(file.Path, "/storage/riff/") {
Expand Down Expand Up @@ -1664,7 +1664,8 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
if strings.HasPrefix(file.Path, "/plugins/") {
if parts := strings.Split(file.Path, "/"); 2 < len(parts) {
needReloadPlugin = true
removePluginSet.Add(parts[2])
// 删除插件目录:卸载
uninstallPluginSet.Add(parts[2])
}
}

Expand All @@ -1681,7 +1682,8 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
}
for _, removePetal := range mergeResult.RemovePetals {
needReloadPlugin = true
removePluginSet.Add(removePetal)
// Petal 中删除插件:卸载
uninstallPluginSet.Add(removePetal)
}

if needReloadFlashcard {
Expand All @@ -1693,7 +1695,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
}

if needReloadPlugin {
PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, removePluginSet, "")
PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, unloadPluginSet, uninstallPluginSet, "")
}

for _, widgetDir := range removeWidgetDirSet.Values() {
Expand Down