🎨 Community marketplace adds plugin section https://github.com/siyuan-note/siyuan/issues/8043

This commit is contained in:
Liang Ding 2023-04-25 18:56:27 +08:00
parent 4a5f3ea104
commit 88d70b0c00
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 13 additions and 80 deletions

View file

@ -17,7 +17,6 @@
package model
import (
"errors"
"fmt"
"os"
"path/filepath"
@ -142,72 +141,6 @@ func loadThemes() {
}
}
func iconJSON(iconName string) (ret map[string]interface{}, err error) {
p := filepath.Join(util.IconsPath, iconName, "icon.json")
if !gulu.File.IsExist(p) {
err = os.ErrNotExist
return
}
data, err := os.ReadFile(p)
if nil != err {
logging.LogErrorf("read icon.json [%s] failed: %s", p, err)
return
}
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
logging.LogErrorf("parse icon.json [%s] failed: %s", p, err)
return
}
if 4 > len(ret) {
logging.LogWarnf("invalid icon.json [%s]", p)
return nil, errors.New("invalid icon.json")
}
return
}
func templateJSON(templateName string) (ret map[string]interface{}, err error) {
p := filepath.Join(util.DataDir, "templates", templateName, "template.json")
if !gulu.File.IsExist(p) {
err = os.ErrNotExist
return
}
data, err := os.ReadFile(p)
if nil != err {
logging.LogErrorf("read template.json [%s] failed: %s", p, err)
return
}
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
logging.LogErrorf("parse template.json [%s] failed: %s", p, err)
return
}
if 4 > len(ret) {
logging.LogWarnf("invalid template.json [%s]", p)
return nil, errors.New("invalid template.json")
}
return
}
func widgetJSON(widgetName string) (ret map[string]interface{}, err error) {
p := filepath.Join(util.DataDir, "widgets", widgetName, "widget.json")
if !gulu.File.IsExist(p) {
err = os.ErrNotExist
return
}
data, err := os.ReadFile(p)
if nil != err {
logging.LogErrorf("read widget.json [%s] failed: %s", p, err)
return
}
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
logging.LogErrorf("parse widget.json [%s] failed: %s", p, err)
return
}
if 4 > len(ret) {
logging.LogWarnf("invalid widget.json [%s]", p)
return nil, errors.New("invalid widget.json")
}
return
}
func loadIcons() {
iconDirs, err := os.ReadDir(util.IconsPath)
if nil != err {
@ -222,7 +155,7 @@ func loadIcons() {
continue
}
name := iconDir.Name()
iconConf, err := iconJSON(name)
iconConf, err := bazaar.IconJSON(name)
if nil != err || nil == iconConf {
continue
}

View file

@ -32,15 +32,15 @@ func GetPackageREADME(repoURL, repoHash string) (ret string) {
return
}
func BazaarPlugins() (widgets []*bazaar.Widget) {
widgets = bazaar.Widgets()
for _, widget := range widgets {
widget.Installed = gulu.File.IsDir(filepath.Join(util.DataDir, "widgets", widget.Name))
if widget.Installed {
if widget.Installed {
if widgetConf, err := widgetJSON(widget.Name); nil == err && nil != widget {
if widget.Version != widgetConf["version"].(string) {
widget.Outdated = true
func BazaarPlugins() (plugins []*bazaar.Plugin) {
plugins = bazaar.Plugins()
for _, plugin := range plugins {
plugin.Installed = gulu.File.IsDir(filepath.Join(util.DataDir, "plugins", plugin.Name))
if plugin.Installed {
if plugin.Installed {
if pluginConf, err := bazaar.PluginJSON(plugin.Name); nil == err && nil != plugin {
if plugin.Version != pluginConf["version"].(string) {
plugin.Outdated = true
}
}
}
@ -78,7 +78,7 @@ func BazaarWidgets() (widgets []*bazaar.Widget) {
widget.Installed = gulu.File.IsDir(filepath.Join(util.DataDir, "widgets", widget.Name))
if widget.Installed {
if widget.Installed {
if widgetConf, err := widgetJSON(widget.Name); nil == err && nil != widget {
if widgetConf, err := bazaar.WidgetJSON(widget.Name); nil == err && nil != widget {
if widget.Version != widgetConf["version"].(string) {
widget.Outdated = true
}
@ -118,7 +118,7 @@ func BazaarIcons() (icons []*bazaar.Icon) {
for _, icon := range icons {
if installed == icon.Name {
icon.Installed = true
if themeConf, err := iconJSON(icon.Name); nil == err {
if themeConf, err := bazaar.IconJSON(icon.Name); nil == err {
if icon.Version != themeConf["version"].(string) {
icon.Outdated = true
}
@ -230,7 +230,7 @@ func BazaarTemplates() (templates []*bazaar.Template) {
for _, template := range templates {
template.Installed = gulu.File.IsExist(filepath.Join(util.DataDir, "templates", template.Name))
if template.Installed {
if themeConf, err := templateJSON(template.Name); nil == err && nil != themeConf {
if themeConf, err := bazaar.TemplateJSON(template.Name); nil == err && nil != themeConf {
if template.Version != themeConf["version"].(string) {
template.Outdated = true
}