From bb0995eb6bc0af934bdb8f0f418e9aefedff0d25 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 2 Sep 2022 11:03:10 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E9=9B=86=E5=B8=82=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=B7=B2=E5=AE=89=E8=A3=85=E7=9A=84=E5=8C=85=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/5678?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/bazaar/icon.go | 6 +++--- kernel/bazaar/package.go | 30 +++++++++++++++++------------- kernel/bazaar/template.go | 2 +- kernel/bazaar/theme.go | 2 +- kernel/bazaar/widget.go | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/kernel/bazaar/icon.go b/kernel/bazaar/icon.go index c8d40860c..8251ca37c 100644 --- a/kernel/bazaar/icon.go +++ b/kernel/bazaar/icon.go @@ -96,7 +96,7 @@ func Icons() (icons []*Icon) { func InstalledIcons() (ret []*Icon) { ret = []*Icon{} - dir, err := os.Open(filepath.Join(util.AppearancePath, "icons")) + dir, err := os.Open(util.IconsPath) if nil != err { logging.LogWarnf("open icons folder failed: %s", err) return @@ -137,14 +137,14 @@ func InstalledIcons() (ret []*Icon) { icon.Size = iconDir.Size() icon.HSize = humanize.Bytes(uint64(icon.Size)) icon.HUpdated = formatUpdated(icon.Updated) - readme, readErr := os.ReadFile(filepath.Join(util.AppearancePath, "icons", dirName, "README.md")) + readme, readErr := os.ReadFile(filepath.Join(util.IconsPath, dirName, "README.md")) if nil != readErr { logging.LogWarnf("read install icon README.md failed: %s", readErr) continue } icon.README, _ = renderREADME(icon.URL, readme) - icon.Outdated = isOutdatedIcon(icon.URL, icon.Version, bazaarIcons) + icon.Outdated = isOutdatedIcon(icon, bazaarIcons) ret = append(ret, icon) } return diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index 93749cb20..5f67adcb1 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -85,7 +85,7 @@ func WidgetJSON(widgetDirName string) (ret map[string]interface{}, err error) { } func IconJSON(iconDirName string) (ret map[string]interface{}, err error) { - p := filepath.Join(util.AppearancePath, "icons", iconDirName, "icon.json") + p := filepath.Join(util.IconsPath, iconDirName, "icon.json") if !gulu.File.IsExist(p) { err = os.ErrNotExist return @@ -172,52 +172,56 @@ func getPkgIndex(pkgType string) (ret map[string]interface{}, err error) { return } -func isOutdatedTheme(fullURL, version string, bazaarThemes []*Theme) bool { - if !strings.HasPrefix(fullURL, "https://github.com/") { +func isOutdatedTheme(theme *Theme, bazaarThemes []*Theme) bool { + if !strings.HasPrefix(theme.URL, "https://github.com/") { return false } for _, pkg := range bazaarThemes { - if fullURL == pkg.URL && version != pkg.Version { + if theme.URL == pkg.URL && theme.Version != pkg.Version { + theme.RepoHash = pkg.RepoHash return true } } return false } -func isOutdatedIcon(fullURL, version string, bazaarIcons []*Icon) bool { - if !strings.HasPrefix(fullURL, "https://github.com/") { +func isOutdatedIcon(icon *Icon, bazaarIcons []*Icon) bool { + if !strings.HasPrefix(icon.URL, "https://github.com/") { return false } for _, pkg := range bazaarIcons { - if fullURL == pkg.URL && version != pkg.Version { + if icon.URL == pkg.URL && icon.Version != pkg.Version { + icon.RepoHash = pkg.RepoHash return true } } return false } -func isOutdatedWidget(fullURL, version string, bazaarWidgets []*Widget) bool { - if !strings.HasPrefix(fullURL, "https://github.com/") { +func isOutdatedWidget(widget *Widget, bazaarWidgets []*Widget) bool { + if !strings.HasPrefix(widget.URL, "https://github.com/") { return false } for _, pkg := range bazaarWidgets { - if fullURL == pkg.URL && version != pkg.Version { + if widget.URL == pkg.URL && widget.Version != pkg.Version { + widget.RepoHash = pkg.RepoHash return true } } return false } -func isOutdatedTemplate(fullURL, version string, bazaarTemplates []*Template) bool { - if !strings.HasPrefix(fullURL, "https://github.com/") { +func isOutdatedTemplate(template *Template, bazaarTemplates []*Template) bool { + if !strings.HasPrefix(template.URL, "https://github.com/") { return false } for _, pkg := range bazaarTemplates { - if fullURL == pkg.URL && version != pkg.Version { + if template.URL == pkg.URL && template.Version != pkg.Version { + template.RepoHash = pkg.RepoHash return true } } diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go index 10f3c435f..57fd6098b 100644 --- a/kernel/bazaar/template.go +++ b/kernel/bazaar/template.go @@ -143,7 +143,7 @@ func InstalledTemplates() (ret []*Template) { continue } template.README, _ = renderREADME(template.URL, readme) - template.Outdated = isOutdatedTemplate(template.URL, template.Version, bazaarTemplates) + template.Outdated = isOutdatedTemplate(template, bazaarTemplates) ret = append(ret, template) } return diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.go index e4bda1cf4..3068a42d9 100644 --- a/kernel/bazaar/theme.go +++ b/kernel/bazaar/theme.go @@ -146,7 +146,7 @@ func InstalledThemes() (ret []*Theme) { continue } theme.README, _ = renderREADME(theme.URL, readme) - theme.Outdated = isOutdatedTheme(theme.URL, theme.Version, bazaarThemes) + theme.Outdated = isOutdatedTheme(theme, bazaarThemes) ret = append(ret, theme) } return diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go index 60d81eb20..db3695fc1 100644 --- a/kernel/bazaar/widget.go +++ b/kernel/bazaar/widget.go @@ -141,7 +141,7 @@ func InstalledWidgets() (ret []*Widget) { continue } widget.README, _ = renderREADME(widget.URL, readme) - widget.Outdated = isOutdatedWidget(widget.URL, widget.Version, bazaarWidgets) + widget.Outdated = isOutdatedWidget(widget, bazaarWidgets) ret = append(ret, widget) } return