Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-05-12 23:49:18 +08:00
commit 09096229ce

View file

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