From 818846025ba3c1c33c6c04aa67207242f378630b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 30 Dec 2025 17:27:23 +0800 Subject: [PATCH] :art: Improve minimum version requirements for marketplace packages https://github.com/siyuan-note/siyuan/issues/16688 Signed-off-by: Daniel <845765@qq.com> --- kernel/bazaar/icon.go | 16 ++++++++++++++++ kernel/bazaar/package.go | 30 ++++++++++++++++-------------- kernel/bazaar/plugin.go | 22 +++++++++++++++++----- kernel/bazaar/template.go | 15 +++++++++++++++ kernel/bazaar/theme.go | 15 +++++++++++++++ kernel/bazaar/widget.go | 15 +++++++++++++++ kernel/model/bazzar.go | 8 +++++++- 7 files changed, 101 insertions(+), 20 deletions(-) diff --git a/kernel/bazaar/icon.go b/kernel/bazaar/icon.go index 5372ea632..92af7c44b 100644 --- a/kernel/bazaar/icon.go +++ b/kernel/bazaar/icon.go @@ -86,6 +86,9 @@ func Icons() (icons []*Icon) { } icon.DisallowInstall = disallowInstallBazaarPackage(icon.Package) + icon.DisallowUpdate = disallowInstallBazaarPackage(icon.Package) + icon.UpdateRequiredMinAppVer = icon.MinAppVersion + icon.URL = strings.TrimSuffix(icon.URL, "/") repoURLHash := strings.Split(repoURL, "@") icon.RepoURL = "https://github.com/" + repoURLHash[0] @@ -157,6 +160,10 @@ func InstalledIcons() (ret []*Icon) { } icon.DisallowInstall = disallowInstallBazaarPackage(icon.Package) + if bazaarPkg := getBazaarIcon(icon.Name, bazaarIcons); nil != bazaarPkg { + icon.DisallowUpdate = disallowInstallBazaarPackage(bazaarPkg.Package) + icon.UpdateRequiredMinAppVer = bazaarPkg.MinAppVersion + } installPath := filepath.Join(util.IconsPath, dirName) icon.Installed = true @@ -192,6 +199,15 @@ func isBuiltInIcon(dirName string) bool { return "ant" == dirName || "material" == dirName } +func getBazaarIcon(name string, icon []*Icon) *Icon { + for _, p := range icon { + if p.Name == name { + return p + } + } + return nil +} + func InstallIcon(repoURL, repoHash, installPath string, systemID string) error { repoURLHash := repoURL + "@" + repoHash data, err := downloadPackage(repoURLHash, true, systemID) diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index dd53ef473..85a132e36 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -130,20 +130,22 @@ type Package struct { PreviewURLThumb string `json:"previewURLThumb"` IconURL string `json:"iconURL"` - Installed bool `json:"installed"` - Outdated bool `json:"outdated"` - Current bool `json:"current"` - Updated string `json:"updated"` - Stars int `json:"stars"` - OpenIssues int `json:"openIssues"` - Size int64 `json:"size"` - HSize string `json:"hSize"` - InstallSize int64 `json:"installSize"` - HInstallSize string `json:"hInstallSize"` - HInstallDate string `json:"hInstallDate"` - HUpdated string `json:"hUpdated"` - Downloads int `json:"downloads"` - DisallowInstall bool `json:"disallowInstall"` + Installed bool `json:"installed"` + Outdated bool `json:"outdated"` + Current bool `json:"current"` + Updated string `json:"updated"` + Stars int `json:"stars"` + OpenIssues int `json:"openIssues"` + Size int64 `json:"size"` + HSize string `json:"hSize"` + InstallSize int64 `json:"installSize"` + HInstallSize string `json:"hInstallSize"` + HInstallDate string `json:"hInstallDate"` + HUpdated string `json:"hUpdated"` + Downloads int `json:"downloads"` + DisallowInstall bool `json:"disallowInstall"` + DisallowUpdate bool `json:"disallowUpdate"` + UpdateRequiredMinAppVer string `json:"updateRequiredMinAppVer"` Incompatible bool `json:"incompatible"` } diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go index bfaa44c15..4f1962749 100644 --- a/kernel/bazaar/plugin.go +++ b/kernel/bazaar/plugin.go @@ -88,6 +88,8 @@ func Plugins(frontend string) (plugins []*Plugin) { } plugin.DisallowInstall = disallowInstallBazaarPackage(plugin.Package) + plugin.DisallowUpdate = disallowInstallBazaarPackage(plugin.Package) + plugin.UpdateRequiredMinAppVer = plugin.MinAppVersion plugin.Incompatible = isIncompatiblePlugin(plugin, frontend) plugin.URL = strings.TrimSuffix(plugin.URL, "/") @@ -166,7 +168,7 @@ func ParseInstalledPlugin(name, frontend string) (found bool, displayName string return } -func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) { +func InstalledPlugins(frontend string) (ret []*Plugin) { ret = []*Plugin{} pluginsPath := filepath.Join(util.DataDir, "plugins") @@ -180,10 +182,7 @@ func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) { return } - var bazaarPlugins []*Plugin - if checkUpdate { - bazaarPlugins = Plugins(frontend) - } + bazaarPlugins := Plugins(frontend) for _, pluginDir := range pluginDirs { if !util.IsDirRegularOrSymlink(pluginDir) { @@ -197,6 +196,10 @@ func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) { } plugin.DisallowInstall = disallowInstallBazaarPackage(plugin.Package) + if bazaarPkg := getBazaarPlugin(plugin.Name, bazaarPlugins); nil != bazaarPkg { + plugin.DisallowUpdate = disallowInstallBazaarPackage(bazaarPkg.Package) + plugin.UpdateRequiredMinAppVer = bazaarPkg.MinAppVersion + } installPath := filepath.Join(util.DataDir, "plugins", dirName) plugin.Installed = true @@ -229,6 +232,15 @@ func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) { return } +func getBazaarPlugin(name string, plugins []*Plugin) *Plugin { + for _, p := range plugins { + if p.Name == name { + return p + } + } + return nil +} + func InstallPlugin(repoURL, repoHash, installPath string, systemID string) error { repoURLHash := repoURL + "@" + repoHash data, err := downloadPackage(repoURLHash, true, systemID) diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go index 519251efc..b36de3a04 100644 --- a/kernel/bazaar/template.go +++ b/kernel/bazaar/template.go @@ -87,6 +87,8 @@ func Templates() (templates []*Template) { } template.DisallowInstall = disallowInstallBazaarPackage(template.Package) + template.DisallowUpdate = disallowInstallBazaarPackage(template.Package) + template.UpdateRequiredMinAppVer = template.MinAppVersion template.URL = strings.TrimSuffix(template.URL, "/") repoURLHash := strings.Split(repoURL, "@") @@ -159,6 +161,10 @@ func InstalledTemplates() (ret []*Template) { } template.DisallowInstall = disallowInstallBazaarPackage(template.Package) + if bazaarPkg := getBazaarTemplate(template.Name, bazaarTemplates); nil != bazaarPkg { + template.DisallowUpdate = disallowInstallBazaarPackage(bazaarPkg.Package) + template.UpdateRequiredMinAppVer = bazaarPkg.MinAppVersion + } installPath := filepath.Join(util.DataDir, "templates", dirName) template.Installed = true @@ -190,6 +196,15 @@ func InstalledTemplates() (ret []*Template) { return } +func getBazaarTemplate(name string, templates []*Template) *Template { + for _, p := range templates { + if p.Name == name { + return p + } + } + return nil +} + func InstallTemplate(repoURL, repoHash, installPath string, systemID string) error { repoURLHash := repoURL + "@" + repoHash data, err := downloadPackage(repoURLHash, true, systemID) diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.go index 12653318d..083a7573a 100644 --- a/kernel/bazaar/theme.go +++ b/kernel/bazaar/theme.go @@ -88,6 +88,8 @@ func Themes() (ret []*Theme) { } theme.DisallowInstall = disallowInstallBazaarPackage(theme.Package) + theme.DisallowUpdate = disallowInstallBazaarPackage(theme.Package) + theme.UpdateRequiredMinAppVer = theme.MinAppVersion theme.URL = strings.TrimSuffix(theme.URL, "/") repoURLHash := strings.Split(repoURL, "@") @@ -160,6 +162,10 @@ func InstalledThemes() (ret []*Theme) { } theme.DisallowInstall = disallowInstallBazaarPackage(theme.Package) + if bazaarPkg := getBazaarTheme(theme.Name, bazaarThemes); nil != bazaarPkg { + theme.DisallowUpdate = disallowInstallBazaarPackage(bazaarPkg.Package) + theme.UpdateRequiredMinAppVer = bazaarPkg.MinAppVersion + } installPath := filepath.Join(util.ThemesPath, dirName) theme.Installed = true @@ -195,6 +201,15 @@ func isBuiltInTheme(dirName string) bool { return "daylight" == dirName || "midnight" == dirName } +func getBazaarTheme(name string, themes []*Theme) *Theme { + for _, p := range themes { + if p.Name == name { + return p + } + } + return nil +} + func InstallTheme(repoURL, repoHash, installPath string, systemID string) error { repoURLHash := repoURL + "@" + repoHash data, err := downloadPackage(repoURLHash, true, systemID) diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go index 2e8561fc7..6561ccb4d 100644 --- a/kernel/bazaar/widget.go +++ b/kernel/bazaar/widget.go @@ -86,6 +86,8 @@ func Widgets() (widgets []*Widget) { } widget.DisallowInstall = disallowInstallBazaarPackage(widget.Package) + widget.DisallowUpdate = disallowInstallBazaarPackage(widget.Package) + widget.UpdateRequiredMinAppVer = widget.MinAppVersion widget.URL = strings.TrimSuffix(widget.URL, "/") repoURLHash := strings.Split(repoURL, "@") @@ -156,6 +158,10 @@ func InstalledWidgets() (ret []*Widget) { } widget.DisallowInstall = disallowInstallBazaarPackage(widget.Package) + if bazaarPkg := getBazaarWidget(widget.Name, bazaarWidgets); nil != bazaarPkg { + widget.DisallowUpdate = disallowInstallBazaarPackage(bazaarPkg.Package) + widget.UpdateRequiredMinAppVer = bazaarPkg.MinAppVersion + } installPath := filepath.Join(util.DataDir, "widgets", dirName) widget.Installed = true @@ -187,6 +193,15 @@ func InstalledWidgets() (ret []*Widget) { return } +func getBazaarWidget(name string, widegets []*Widget) *Widget { + for _, p := range widegets { + if p.Name == name { + return p + } + } + return nil +} + func InstallWidget(repoURL, repoHash, installPath string, systemID string) error { repoURLHash := repoURL + "@" + repoHash data, err := downloadPackage(repoURLHash, true, systemID) diff --git a/kernel/model/bazzar.go b/kernel/model/bazzar.go index a597c0d57..aeb1f67e1 100644 --- a/kernel/model/bazzar.go +++ b/kernel/model/bazzar.go @@ -201,6 +201,8 @@ func BazaarPlugins(frontend, keyword string) (plugins []*bazaar.Plugin) { if pluginConf, err := bazaar.PluginJSON(plugin.Name); err == nil && nil != plugin { plugin.Outdated = 0 > semver.Compare("v"+pluginConf.Version, "v"+plugin.Version) } + } else { + plugin.Outdated = false } } return @@ -218,7 +220,7 @@ func filterPlugins(plugins []*bazaar.Plugin, keyword string) (ret []*bazaar.Plug } func InstalledPlugins(frontend, keyword string) (plugins []*bazaar.Plugin) { - plugins = bazaar.InstalledPlugins(frontend, true) + plugins = bazaar.InstalledPlugins(frontend) plugins = filterPlugins(plugins, keyword) petals := getPetals() for _, plugin := range plugins { @@ -270,6 +272,8 @@ func BazaarWidgets(keyword string) (widgets []*bazaar.Widget) { if widgetConf, err := bazaar.WidgetJSON(widget.Name); err == nil && nil != widget { widget.Outdated = 0 > semver.Compare("v"+widgetConf.Version, "v"+widget.Version) } + } else { + widget.Outdated = false } } return @@ -458,6 +462,8 @@ func BazaarTemplates(keyword string) (templates []*bazaar.Template) { if templateConf, err := bazaar.TemplateJSON(template.Name); err == nil && nil != templateConf { template.Outdated = 0 > semver.Compare("v"+templateConf.Version, "v"+template.Version) } + } else { + template.Outdated = false } } return