🎨 集市支持已安装的包单独显示 https://github.com/siyuan-note/siyuan/issues/5678

This commit is contained in:
Liang Ding 2022-09-01 21:33:24 +08:00
parent 6072f8a3a1
commit 4585cff7e6
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 89 additions and 1 deletions

View file

@ -62,6 +62,28 @@ type Package struct {
Downloads int `json:"downloads"`
}
func WidgetJSON(widgetDirName string) (ret map[string]interface{}, err error) {
p := filepath.Join(util.DataDir, widgetDirName, "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 IconJSON(iconDirName string) (ret map[string]interface{}, err error) {
p := filepath.Join(util.ThemesPath, iconDirName, "icon.json")
if !gulu.File.IsExist(p) {
@ -85,7 +107,7 @@ func IconJSON(iconDirName string) (ret map[string]interface{}, err error) {
}
func TemplateJSON(templateDirName string) (ret map[string]interface{}, err error) {
p := filepath.Join(util.ThemesPath, templateDirName, "template.json")
p := filepath.Join(util.DataDir, templateDirName, "template.json")
if !gulu.File.IsExist(p) {
err = os.ErrNotExist
return
@ -178,6 +200,20 @@ func isOutdatedIcon(fullURL, version string, bazaarIcons []*Icon) bool {
return false
}
func isOutdatedWidget(fullURL, version string, bazaarWidgets []*Widget) bool {
if !strings.HasPrefix(fullURL, "https://github.com/") {
return false
}
url := strings.TrimPrefix(fullURL, "https://github.com/")
for _, pkg := range bazaarWidgets {
if url == pkg.URL && version != pkg.Version {
return true
}
}
return false
}
func isOutdatedTemplate(fullURL, version string, bazaarTemplates []*Template) bool {
if !strings.HasPrefix(fullURL, "https://github.com/") {
return false