mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-05-07 03:09:56 -05:00
🎨 Automatically apply code snippets after data synchronization https://github.com/siyuan-note/siyuan/issues/16736
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
@@ -79,7 +79,7 @@ func setConfSnippet(c *gin.Context) {
|
||||
model.Conf.Save()
|
||||
|
||||
ret.Data = snippet
|
||||
util.BroadcastByType("main", "setSnippet", 0, "", snippet)
|
||||
model.PushReloadSnippet(snippet)
|
||||
}
|
||||
|
||||
func addVirtualBlockRefExclude(c *gin.Context) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/task"
|
||||
@@ -38,6 +39,10 @@ import (
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func PushReloadSnippet(snippet *conf.Snpt) {
|
||||
util.BroadcastByType("main", "setSnippet", 0, "", snippet)
|
||||
}
|
||||
|
||||
func PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, unloadPluginNameSet, uninstallPluginNameSet *hashset.Set, excludeApp string) {
|
||||
// 集合去重
|
||||
if nil != uninstallPluginNameSet {
|
||||
|
||||
@@ -1595,7 +1595,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
||||
var upserts, removes []string
|
||||
var upsertTrees int
|
||||
// 可能需要重新加载部分功能
|
||||
var needReloadFlashcard, needReloadOcrTexts, needReloadPlugin bool
|
||||
var needReloadFlashcard, needReloadOcrTexts, needReloadPlugin, needReloadSnippet bool
|
||||
upsertCodePluginSet := hashset.New() // 插件代码变更 data/plugins/
|
||||
upsertDataPluginSet := hashset.New() // 插件存储数据变更 data/storage/petal/
|
||||
needUnindexBoxes, needIndexBoxes := map[string]bool{}, map[string]bool{}
|
||||
@@ -1640,6 +1640,10 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
||||
absPath := filepath.Join(util.DataDir, file.Path)
|
||||
HandleAssetsChangeEvent(absPath)
|
||||
}
|
||||
|
||||
if file.Path == "/snippets/conf.json" {
|
||||
needReloadSnippet = true
|
||||
}
|
||||
}
|
||||
|
||||
removeWidgetDirSet, unloadPluginSet, uninstallPluginSet := hashset.New(), hashset.New(), hashset.New()
|
||||
@@ -1686,6 +1690,10 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
||||
absPath := filepath.Join(util.DataDir, file.Path)
|
||||
HandleAssetsRemoveEvent(absPath)
|
||||
}
|
||||
|
||||
if file.Path == "/snippets/conf.json" {
|
||||
needReloadSnippet = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, upsertPetal := range mergeResult.UpsertPetals {
|
||||
@@ -1710,6 +1718,10 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
||||
PushReloadPlugin(upsertCodePluginSet, upsertDataPluginSet, unloadPluginSet, uninstallPluginSet, "")
|
||||
}
|
||||
|
||||
if needReloadSnippet {
|
||||
PushReloadSnippet(Conf.Snippet)
|
||||
}
|
||||
|
||||
for _, widgetDir := range removeWidgetDirSet.Values() {
|
||||
widgetDirPath := filepath.Join(util.DataDir, "widgets", widgetDir.(string))
|
||||
gulu.File.RemoveEmptyDirs(widgetDirPath)
|
||||
|
||||
Reference in New Issue
Block a user