From 7acf83acc9b1d17236fe6515729db0a688025d61 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 15 Dec 2024 12:13:11 +0800 Subject: [PATCH] :art: Improve petals loading https://github.com/siyuan-note/siyuan/issues/13472 --- kernel/model/bazzar.go | 3 --- kernel/model/plugin.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/kernel/model/bazzar.go b/kernel/model/bazzar.go index 6b3f41439..106ffabfc 100644 --- a/kernel/model/bazzar.go +++ b/kernel/model/bazzar.go @@ -253,9 +253,6 @@ func UninstallBazaarPlugin(pluginName, frontend string) error { } } petals = tmp - if 1 > len(petals) { - petals = []*Petal{} - } savePetals(petals) return nil } diff --git a/kernel/model/plugin.go b/kernel/model/plugin.go index 1a1a71828..8f2806c04 100644 --- a/kernel/model/plugin.go +++ b/kernel/model/plugin.go @@ -184,6 +184,13 @@ var petalsStoreLock = sync.Mutex{} func savePetals(petals []*Petal) { petalsStoreLock.Lock() defer petalsStoreLock.Unlock() + savePetals0(petals) +} + +func savePetals0(petals []*Petal) { + if 1 > len(petals) { + petals = []*Petal{} + } petalDir := filepath.Join(util.DataDir, "storage", "petal") confPath := filepath.Join(petalDir, "petals.json") @@ -233,6 +240,21 @@ func getPetals() (ret []*Petal) { logging.LogErrorf("unmarshal petals failed: %s", err) return } + + var tmp []*Petal + pluginsDir := filepath.Join(util.DataDir, "plugins") + for _, petal := range ret { + if petal.Enabled && filelock.IsExist(filepath.Join(pluginsDir, petal.Name)) { + tmp = append(tmp, petal) + } + } + if len(tmp) != len(ret) { + savePetals0(tmp) + ret = tmp + } + if 1 > len(ret) { + ret = []*Petal{} + } return }