mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 Improve load plugins
This commit is contained in:
parent
73b980af69
commit
a5c24c825c
1 changed files with 16 additions and 12 deletions
|
|
@ -73,19 +73,23 @@ func SetPetalEnabled(name string, enabled bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadPetals() (ret []*Petal) {
|
func LoadPetals() (ret []*Petal) {
|
||||||
ret = getPetals()
|
ret = []*Petal{}
|
||||||
|
petals := getPetals()
|
||||||
plugins := bazaar.InstalledPlugins()
|
for _, petal := range petals {
|
||||||
for _, plugin := range plugins {
|
if !petal.Enabled {
|
||||||
petal := getPetalByName(plugin.Name, ret)
|
|
||||||
if nil == petal {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginDir := filepath.Join(util.DataDir, "plugins", plugin.Name)
|
pluginDir := filepath.Join(util.DataDir, "plugins", petal.Name)
|
||||||
data, err := filelock.ReadFile(filepath.Join(pluginDir, "index.js"))
|
jsPath := filepath.Join(pluginDir, "index.js")
|
||||||
|
if !gulu.File.IsExist(jsPath) {
|
||||||
|
logging.LogErrorf("plugin [%s] js not found", petal.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := filelock.ReadFile(jsPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("read plugin [%s] js failed: %s", plugin.Name, err)
|
logging.LogErrorf("read plugin [%s] js failed: %s", petal.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
petal.JS = string(data)
|
petal.JS = string(data)
|
||||||
|
|
@ -94,7 +98,7 @@ func LoadPetals() (ret []*Petal) {
|
||||||
if gulu.File.IsExist(cssPath) {
|
if gulu.File.IsExist(cssPath) {
|
||||||
data, err := filelock.ReadFile(cssPath)
|
data, err := filelock.ReadFile(cssPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("read plugin [%s] css failed: %s", plugin.Name, err)
|
logging.LogErrorf("read plugin [%s] css failed: %s", petal.Name, err)
|
||||||
} else {
|
} else {
|
||||||
petal.CSS = string(data)
|
petal.CSS = string(data)
|
||||||
}
|
}
|
||||||
|
|
@ -104,11 +108,11 @@ func LoadPetals() (ret []*Petal) {
|
||||||
if gulu.File.IsExist(i18nPath) {
|
if gulu.File.IsExist(i18nPath) {
|
||||||
data, err := filelock.ReadFile(i18nPath)
|
data, err := filelock.ReadFile(i18nPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("read plugin [%s] i18n failed: %s", plugin.Name, err)
|
logging.LogErrorf("read plugin [%s] i18n failed: %s", petal.Name, err)
|
||||||
} else {
|
} else {
|
||||||
petal.I18n = map[string]interface{}{}
|
petal.I18n = map[string]interface{}{}
|
||||||
if err = gulu.JSON.UnmarshalJSON(data, &petal.I18n); nil != err {
|
if err = gulu.JSON.UnmarshalJSON(data, &petal.I18n); nil != err {
|
||||||
logging.LogErrorf("unmarshal plugin [%s] i18n failed: %s", plugin.Name, err)
|
logging.LogErrorf("unmarshal plugin [%s] i18n failed: %s", petal.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue