🐛 After uninstalling the plugin, data synchronization does not uninstall it https://github.com/siyuan-note/siyuan/issues/11277

This commit is contained in:
Daniel 2024-05-12 23:41:54 +08:00
parent 0dec8802bc
commit 95764352f8
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1410,6 +1410,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
var upsertTrees int var upsertTrees int
// 可能需要重新加载部分功能 // 可能需要重新加载部分功能
var needReloadFlashcard, needReloadOcrTexts, needReloadPlugin bool var needReloadFlashcard, needReloadOcrTexts, needReloadPlugin bool
upsertPluginSet := hashset.New()
for _, file := range mergeResult.Upserts { for _, file := range mergeResult.Upserts {
upserts = append(upserts, file.Path) upserts = append(upserts, file.Path)
if strings.HasPrefix(file.Path, "/storage/riff/") { if strings.HasPrefix(file.Path, "/storage/riff/") {
@ -1428,12 +1429,19 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
needReloadPlugin = true needReloadPlugin = true
} }
if strings.HasPrefix(file.Path, "/plugins/") {
if parts := strings.Split(file.Path, "/"); 2 < len(parts) {
needReloadPlugin = true
upsertPluginSet.Add(parts[2])
}
}
if strings.HasSuffix(file.Path, ".sy") { if strings.HasSuffix(file.Path, ".sy") {
upsertTrees++ upsertTrees++
} }
} }
clearWidgetsDir := hashset.New() removeWidgetDirSet, removePluginSet := hashset.New(), hashset.New()
for _, file := range mergeResult.Removes { for _, file := range mergeResult.Removes {
removes = append(removes, file.Path) removes = append(removes, file.Path)
if strings.HasPrefix(file.Path, "/storage/riff/") { if strings.HasPrefix(file.Path, "/storage/riff/") {
@ -1452,9 +1460,16 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
needReloadPlugin = true needReloadPlugin = true
} }
if strings.HasPrefix(file.Path, "/plugins/") {
if parts := strings.Split(file.Path, "/"); 2 < len(parts) {
needReloadPlugin = true
removePluginSet.Add(parts[2])
}
}
if strings.HasPrefix(file.Path, "/widgets/") { if strings.HasPrefix(file.Path, "/widgets/") {
if parts := strings.Split(file.Path, "/"); 2 < len(parts) { if parts := strings.Split(file.Path, "/"); 2 < len(parts) {
clearWidgetsDir.Add(parts[2]) removeWidgetDirSet.Add(parts[2])
} }
} }
} }
@ -1468,10 +1483,10 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
} }
if needReloadPlugin { if needReloadPlugin {
pushReloadPlugin() pushReloadPlugin(upsertPluginSet, removePluginSet)
} }
for _, widgetDir := range clearWidgetsDir.Values() { for _, widgetDir := range removeWidgetDirSet.Values() {
widgetDirPath := filepath.Join(util.DataDir, "widgets", widgetDir.(string)) widgetDirPath := filepath.Join(util.DataDir, "widgets", widgetDir.(string))
gulu.File.RemoveEmptyDirs(widgetDirPath) gulu.File.RemoveEmptyDirs(widgetDirPath)
} }
@ -2002,6 +2017,16 @@ func getCloudSpace() (stat *cloud.Stat, err error) {
return return
} }
func pushReloadPlugin() { func pushReloadPlugin(upsertPluginSet, removePluginNameSet *hashset.Set) {
util.BroadcastByType("main", "reloadPlugin", 0, "", nil) var upsertPlugins, removePlugins []string
for _, n := range upsertPluginSet.Values() {
upsertPlugins = append(upsertPlugins, n.(string))
}
for _, n := range removePluginNameSet.Values() {
removePlugins = append(removePlugins, n.(string))
}
util.BroadcastByType("main", "reloadPlugin", 0, "", map[string]interface{}{
"upsertPlugins": upsertPlugins,
"removePlugins": removePlugins,
})
} }