mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 The plugin switch status is not synchronized https://github.com/siyuan-note/siyuan/issues/16155
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
f2191aad5f
commit
2815a744d5
3 changed files with 42 additions and 16 deletions
|
|
@ -58,7 +58,7 @@ require (
|
||||||
github.com/sashabaranov/go-openai v1.41.2
|
github.com/sashabaranov/go-openai v1.41.2
|
||||||
github.com/shirou/gopsutil/v4 v4.25.9
|
github.com/shirou/gopsutil/v4 v4.25.9
|
||||||
github.com/siyuan-note/dataparser v0.0.0-20250804100744-b41253b236f3
|
github.com/siyuan-note/dataparser v0.0.0-20250804100744-b41253b236f3
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20251023124826-f16d230d7692
|
github.com/siyuan-note/dejavu v0.0.0-20251023133203-b2133372a0ed
|
||||||
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec
|
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec
|
||||||
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97
|
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97
|
||||||
github.com/siyuan-note/filelock v0.0.0-20251010020544-2603449ff16d
|
github.com/siyuan-note/filelock v0.0.0-20251010020544-2603449ff16d
|
||||||
|
|
|
||||||
|
|
@ -374,8 +374,8 @@ github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05Ut
|
||||||
github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8=
|
github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8=
|
||||||
github.com/siyuan-note/dataparser v0.0.0-20250804100744-b41253b236f3 h1:EH063L0HD1f82DvddurUmEXS0obXypv8pQrcaC/zNgI=
|
github.com/siyuan-note/dataparser v0.0.0-20250804100744-b41253b236f3 h1:EH063L0HD1f82DvddurUmEXS0obXypv8pQrcaC/zNgI=
|
||||||
github.com/siyuan-note/dataparser v0.0.0-20250804100744-b41253b236f3/go.mod h1:8lb+SsWAPQblGbjmwEBsBdJszMCcLeECtB95fv6mReg=
|
github.com/siyuan-note/dataparser v0.0.0-20250804100744-b41253b236f3/go.mod h1:8lb+SsWAPQblGbjmwEBsBdJszMCcLeECtB95fv6mReg=
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20251023124826-f16d230d7692 h1:iIsqhSYVWj2VR2Tzh+rvPfTfloMJFTmtl4sRj/9++zM=
|
github.com/siyuan-note/dejavu v0.0.0-20251023133203-b2133372a0ed h1:8Yeyw09xNtCGyjw0Jjun6ScGf5r+WyAGDe94h3Bb9dM=
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20251023124826-f16d230d7692/go.mod h1:VUnpgjNMd3/SJwoWFPRb4nAEfvmfajBSMnsmadNptH8=
|
github.com/siyuan-note/dejavu v0.0.0-20251023133203-b2133372a0ed/go.mod h1:VUnpgjNMd3/SJwoWFPRb4nAEfvmfajBSMnsmadNptH8=
|
||||||
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec h1:D8Sjwa+7WxP3XrIBscT4PxBZZddZ83/O+5nX1sq6g6g=
|
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec h1:D8Sjwa+7WxP3XrIBscT4PxBZZddZ83/O+5nX1sq6g6g=
|
||||||
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec/go.mod h1:6iAxXPOOAG3+M4bCiKQZTQ+n4gSUx/OyHhsP57dJlS8=
|
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec/go.mod h1:6iAxXPOOAG3+M4bCiKQZTQ+n4gSUx/OyHhsP57dJlS8=
|
||||||
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97 h1:lM5v8BfNtbOL5jYwhCdMYBcYtr06IYBKjjSLAPMKTM8=
|
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97 h1:lM5v8BfNtbOL5jYwhCdMYBcYtr06IYBKjjSLAPMKTM8=
|
||||||
|
|
|
||||||
|
|
@ -1148,6 +1148,8 @@ func syncRepoDownload() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeSyncPetals := getPetals()
|
||||||
|
|
||||||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||||
mergeResult, trafficStat, err := repo.SyncDownload(syncContext)
|
mergeResult, trafficStat, err := repo.SyncDownload(syncContext)
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
|
|
@ -1178,6 +1180,7 @@ func syncRepoDownload() (err error) {
|
||||||
autoSyncErrCount = 0
|
autoSyncErrCount = 0
|
||||||
BootSyncSucc = 0
|
BootSyncSucc = 0
|
||||||
|
|
||||||
|
calcPetalDiff(beforeSyncPetals, mergeResult)
|
||||||
processSyncMergeResult(false, true, mergeResult, trafficStat, "d", elapsed)
|
processSyncMergeResult(false, true, mergeResult, trafficStat, "d", elapsed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1441,6 +1444,8 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeSyncPetals := getPetals()
|
||||||
|
|
||||||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||||
mergeResult, trafficStat, err := repo.Sync(syncContext)
|
mergeResult, trafficStat, err := repo.Sync(syncContext)
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
|
|
@ -1478,6 +1483,7 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
|
||||||
Conf.Save()
|
Conf.Save()
|
||||||
autoSyncErrCount = 0
|
autoSyncErrCount = 0
|
||||||
|
|
||||||
|
calcPetalDiff(beforeSyncPetals, mergeResult)
|
||||||
processSyncMergeResult(exit, byHand, mergeResult, trafficStat, "a", elapsed)
|
processSyncMergeResult(exit, byHand, mergeResult, trafficStat, "a", elapsed)
|
||||||
|
|
||||||
if !exit {
|
if !exit {
|
||||||
|
|
@ -1491,6 +1497,30 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calcPetalDiff(beforeSyncPetals []*Petal, mergeResult *dejavu.MergeResult) {
|
||||||
|
var upsertPetals, removePetals []string
|
||||||
|
afterSyncPetals := getPetals()
|
||||||
|
for _, afterSyncPetal := range afterSyncPetals {
|
||||||
|
if beforeSyncPetal := getPetalByName(afterSyncPetal.Name, beforeSyncPetals); nil != beforeSyncPetal {
|
||||||
|
a, _ := gulu.JSON.MarshalJSON(afterSyncPetal)
|
||||||
|
b, _ := gulu.JSON.MarshalJSON(beforeSyncPetal)
|
||||||
|
if !bytes.Equal(a, b) {
|
||||||
|
upsertPetals = append(upsertPetals, afterSyncPetal.Name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
upsertPetals = append(upsertPetals, afterSyncPetal.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, beforeSyncPetal := range beforeSyncPetals {
|
||||||
|
if nil == getPetalByName(beforeSyncPetal.Name, afterSyncPetals) {
|
||||||
|
removePetals = append(removePetals, beforeSyncPetal.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mergeResult.UpsertPetals = gulu.Str.RemoveDuplicatedElem(upsertPetals)
|
||||||
|
mergeResult.RemovePetals = gulu.Str.RemoveDuplicatedElem(removePetals)
|
||||||
|
}
|
||||||
|
|
||||||
func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult, trafficStat *dejavu.TrafficStat, mode string, elapsed time.Duration) {
|
func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult, trafficStat *dejavu.TrafficStat, mode string, elapsed time.Duration) {
|
||||||
logging.LogInfof("synced data repo [device=%s, kernel=%s, provider=%d, mode=%s/%t, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs], merge result [conflicts=%d, upserts=%d, removes=%d]\n\n",
|
logging.LogInfof("synced data repo [device=%s, kernel=%s, provider=%d, mode=%s/%t, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs], merge result [conflicts=%d, upserts=%d, removes=%d]\n\n",
|
||||||
Conf.System.ID, KernelID, Conf.Sync.Provider, mode, byHand,
|
Conf.System.ID, KernelID, Conf.Sync.Provider, mode, byHand,
|
||||||
|
|
@ -1586,19 +1616,6 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
||||||
if parts := strings.Split(file.Path, "/"); 3 < len(parts) {
|
if parts := strings.Split(file.Path, "/"); 3 < len(parts) {
|
||||||
if pluginName := parts[3]; "petals.json" != pluginName {
|
if pluginName := parts[3]; "petals.json" != pluginName {
|
||||||
upsertPluginSet.Add(pluginName)
|
upsertPluginSet.Add(pluginName)
|
||||||
} else {
|
|
||||||
// 修改了 petals.json 则重新加载所有插件
|
|
||||||
// The plugin switch status is not synchronized https://github.com/siyuan-note/siyuan/issues/16155
|
|
||||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, "plugins"))
|
|
||||||
if nil != err {
|
|
||||||
logging.LogErrorf("read plugins dir failed: %s", err)
|
|
||||||
} else {
|
|
||||||
for _, entry := range entries {
|
|
||||||
if entry.IsDir() {
|
|
||||||
upsertPluginSet.Add(entry.Name())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1655,6 +1672,15 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, upsertPetal := range mergeResult.UpsertPetals {
|
||||||
|
needReloadPlugin = true
|
||||||
|
upsertPluginSet.Add(upsertPetal)
|
||||||
|
}
|
||||||
|
for _, removePetal := range mergeResult.RemovePetals {
|
||||||
|
needReloadPlugin = true
|
||||||
|
removePluginSet.Add(removePetal)
|
||||||
|
}
|
||||||
|
|
||||||
if needReloadFlashcard {
|
if needReloadFlashcard {
|
||||||
LoadFlashcards()
|
LoadFlashcards()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue