mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Remove non-existent plugins from petals.json (#16328)
This commit is contained in:
parent
d3ce6dc1f2
commit
ecbe8b8131
1 changed files with 25 additions and 12 deletions
|
|
@ -74,6 +74,16 @@ func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPetalByName(name string, petals []*Petal) (ret *Petal) {
|
||||||
|
for _, p := range petals {
|
||||||
|
if name == p.Name {
|
||||||
|
ret = p
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func LoadPetals(frontend string, isPublish bool) (ret []*Petal) {
|
func LoadPetals(frontend string, isPublish bool) (ret []*Petal) {
|
||||||
ret = []*Petal{}
|
ret = []*Petal{}
|
||||||
|
|
||||||
|
|
@ -90,11 +100,6 @@ func LoadPetals(frontend string, isPublish bool) (ret []*Petal) {
|
||||||
|
|
||||||
petals := getPetals()
|
petals := getPetals()
|
||||||
for _, petal := range petals {
|
for _, petal := range petals {
|
||||||
installPath := filepath.Join(util.DataDir, "plugins", petal.Name)
|
|
||||||
if !filelock.IsExist(installPath) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, petal.DisplayName, petal.Incompatible, petal.DisabledInPublish = bazaar.ParseInstalledPlugin(petal.Name, frontend)
|
_, petal.DisplayName, petal.Incompatible, petal.DisabledInPublish = bazaar.ParseInstalledPlugin(petal.Name, frontend)
|
||||||
if !petal.Enabled || petal.Incompatible || (isPublish && petal.DisabledInPublish) {
|
if !petal.Enabled || petal.Incompatible || (isPublish && petal.DisabledInPublish) {
|
||||||
continue
|
continue
|
||||||
|
|
@ -244,7 +249,8 @@ func getPetals() (ret []*Petal) {
|
||||||
var tmp []*Petal
|
var tmp []*Petal
|
||||||
pluginsDir := filepath.Join(util.DataDir, "plugins")
|
pluginsDir := filepath.Join(util.DataDir, "plugins")
|
||||||
for _, petal := range ret {
|
for _, petal := range ret {
|
||||||
if petal.Enabled && filelock.IsExist(filepath.Join(pluginsDir, petal.Name)) {
|
pluginPath := filepath.Join(pluginsDir, petal.Name)
|
||||||
|
if hasPluginFiles(pluginPath) {
|
||||||
tmp = append(tmp, petal)
|
tmp = append(tmp, petal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -258,12 +264,19 @@ func getPetals() (ret []*Petal) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPetalByName(name string, petals []*Petal) (ret *Petal) {
|
// hasPluginFiles 检查插件安装目录是否存在且包含文件
|
||||||
for _, p := range petals {
|
func hasPluginFiles(pluginPath string) bool {
|
||||||
if name == p.Name {
|
if !filelock.IsExist(pluginPath) {
|
||||||
ret = p
|
return false
|
||||||
break
|
}
|
||||||
|
entries, err := os.ReadDir(pluginPath)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
if !entry.IsDir() {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue