An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Disallow installing and updating incompatible themes https://github.com/siyuan-note/siyuan/issues/13855
Daniel968cd74de341
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex beda4e4c0d..928eb8eedf 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -399,7 +399,7 @@ export const bazaar = {if (!available || available.installed) {return "";}- return `<button ${available.disallowInstall ? `disabled aria-label="${bazaar._genInstallButtonAriaLabel(available)}" data-position="north"` : ""} class="b3-button ariaLabel fn__block" data-type="install">${window.siyuan.languages.download}</button>`;+ return `<button ${available.disallowInstall ? `disabled aria-label="${bazaar._genInstallButtonAriaLabel(available, bazaarType)}" data-position="north"` : ""} class="b3-button ariaLabel fn__block" data-type="install">${window.siyuan.languages.download}</button>`;}let primaryAction = "";@@ -451,43 +451,45 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}<svg><use xlink:href="#iconClose"></use></svg></span><div class="fn__space--small${item.outdated ? "" : " fn__none"}"></div>- ${bazaar._genUpdateButtonHTML(item)}+ ${bazaar._genUpdateButtonHTML(item, bazaarType)}</div></div></div>`;},- _genInstallButtonAriaLabel(item: IBazaarItem) {+ _genInstallButtonAriaLabel(item: IBazaarItem, bazaarType: TBazaarType) {if (!item.disallowInstall) {return window.siyuan.languages.download;}if (item.bazaarIncompatible) {- return window.siyuan.languages.incompatiblePluginTip;+ return bazaarType === "themes" ? window.siyuan.languages.incompatible :+ window.siyuan.languages.incompatiblePluginTip;}return window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.minAppVersion || "");},- _genUpdateButtonAriaLabel(item: IBazaarItem) {+ _genUpdateButtonAriaLabel(item: IBazaarItem, bazaarType: TBazaarType) {if (!item.disallowUpdate) {return window.siyuan.languages.update;}if (item.bazaarIncompatible) {- return window.siyuan.languages.incompatiblePluginTip;+ return bazaarType === "themes" ? window.siyuan.languages.incompatible :+ window.siyuan.languages.incompatiblePluginTip;}return window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.updateRequiredMinAppVer || "");},- _genUpdateButtonHTML(item?: IBazaarItem, reserveSpace = false) {+ _genUpdateButtonHTML(item: IBazaarItem | undefined, bazaarType: TBazaarType, reserveSpace = false) {if (!item?.outdated && !reserveSpace) {return "";}- const ariaLabel = item ? this._genUpdateButtonAriaLabel(item) : window.siyuan.languages.update;+ const ariaLabel = item ? this._genUpdateButtonAriaLabel(item, bazaarType) : window.siyuan.languages.update;return `<span data-position="north" data-type="install-t" ${item?.disallowUpdate ? "disabled" : ""} aria-label="${ariaLabel}" class="ariaLabel block__icon block__icon--show${item?.outdated ? "" : " fn__hidden"}"><svg class="ft__primary"><use xlink:href="#iconRefresh"></use></svg></span>`;},- _genReadmeUpdateButtonHTML(item?: IBazaarItem, reserveSpace = false) {+ _genReadmeUpdateButtonHTML(item: IBazaarItem | undefined, bazaarType: TBazaarType, reserveSpace = false) {if (!item?.outdated && !reserveSpace) {return "";}- const ariaLabel = item ? this._genUpdateButtonAriaLabel(item) : window.siyuan.languages.update;+ const ariaLabel = item ? this._genUpdateButtonAriaLabel(item, bazaarType) : window.siyuan.languages.update;return `<div data-type="readme-update-slot" class="${item?.outdated ? "" : "fn__none"}">${reserveSpace ? '<div class="fn__hr"></div>' : ""}<button ${item?.disallowUpdate ? `disabled aria-label="${ariaLabel}" data-position="north"` : ""} class="b3-button ariaLabel" style="width: 168px" data-type="install-t">${window.siyuan.languages.update}</button>@@ -510,7 +512,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}<span data-position="north" class="ariaLabel block__icon block__icon--show${isBrowser() ? " fn__none" : ""}" data-type="open" aria-label="${window.siyuan.languages.showInFolder}"><svg><use xlink:href="#iconFolder"></use></svg></span>- ${bazaar._genUpdateButtonHTML(available)}+ ${bazaar._genUpdateButtonHTML(available, bazaarType)}</div></div>`;},@@ -594,7 +596,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}return;}const available = bazaar._getUpdatedItem(type, name)?.available;- slot.outerHTML = bazaar._genUpdateButtonHTML(available, true);+ slot.outerHTML = bazaar._genUpdateButtonHTML(available, type, true);});const sideElement = bazaar.element.querySelector("#configBazaarReadme.config__view--show .item__side");if (sideElement?.getAttribute("data-from") === "downloaded") {@@ -603,7 +605,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}const slot = sideElement.querySelector('[data-type="readme-update-slot"]');const available = type && name ? bazaar._getUpdatedItem(type, name)?.available : undefined;if (slot) {- slot.outerHTML = bazaar._genReadmeUpdateButtonHTML(available, true);+ slot.outerHTML = bazaar._genReadmeUpdateButtonHTML(available, type, true);sideElement.setAttribute("data-progress-id", available?.repoURL || sideElement.getAttribute("data-repourl") || "");}}@@ -670,7 +672,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}</div></div><div class="b3-card__actions b3-card__actions--right">- ${bazaar._genUpdateButtonHTML(available, true)}+ ${bazaar._genUpdateButtonHTML(available, bazaarType, true)}${bazaar._genIncompatibleChipHTML(bazaarItem, "installed", bazaarType)}${bazaar._genFundingHTML(bazaarItem.preferredFunding)}${hasSetting ? `<span data-position="north" class="ariaLabel block__icon block__icon--show${window.siyuan.config.bazaar.petalDisabled ? " fn__none" : ""}" data-type="setting" aria-label="${window.siyuan.languages.config}">@@ -857,7 +859,7 @@ type="checkbox"></div><div class="item__actions">${bazaar._genReadmeActionsHTML(bazaarType, installed, available)}- ${bazaar._genReadmeUpdateButtonHTML(available, Boolean(installed))}+ ${bazaar._genReadmeUpdateButtonHTML(available, bazaarType, Boolean(installed))}</div></div><div class="item__main">@@ -1187,7 +1189,7 @@ type="checkbox">});break;case "theme":- fetchPost("/api/bazaar/getBazaarTheme", {}, response => {+ fetchPost("/api/bazaar/getBazaarTheme", {frontend: getFrontend()}, response => {bazaar._onBazaar(response, "themes");bazaar._data.themes = response.data.packages;});@@ -1620,7 +1622,7 @@ type="checkbox">bazaar._data.widgets = response.data.packages;});} else if (type === "theme") {- fetchPost("/api/bazaar/getBazaarTheme", {keyword}, response => {+ fetchPost("/api/bazaar/getBazaarTheme", {frontend: getFrontend(), keyword}, response => {bazaar._onBazaar(response, "themes");bazaar._data.themes = response.data.packages;});diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 620af82d4e..0e39706360 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -1025,8 +1025,8 @@ interface IBazaarItem {preferredFunding: string;disallowUpdate: boolean;updateRequiredMinAppVer?: string;- installedIncompatible?: boolean; // 仅 plugin- bazaarIncompatible?: boolean; // 仅 plugin+ installedIncompatible?: boolean; // 仅插件/主题+ bazaarIncompatible?: boolean; // 仅插件/主题enabled?: boolean; // 仅 pluginmodes?: string[]; // 仅 theme}diff --git a/kernel/api/bazaar.go b/kernel/api/bazaar.goindex 2ed3970ca9..2a15167a31 100644--- a/kernel/api/bazaar.go+++ b/kernel/api/bazaar.go@@ -620,13 +620,16 @@ func getBazaarTheme(c *gin.Context) {return}- var keyword string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("keyword", &keyword, false, false)) {+ var frontend, keyword string+ if !util.ParseJsonArgs(arg, ret,+ util.BindJsonArg("frontend", &frontend, false, false),+ util.BindJsonArg("keyword", &keyword, false, false),+ ) {return}ret.Data = map[string]any{- "packages": model.GetBazaarPackages("themes", "", keyword),+ "packages": model.GetBazaarPackages("themes", frontend, keyword),}}@@ -639,13 +642,16 @@ func getInstalledTheme(c *gin.Context) {return}- var keyword string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("keyword", &keyword, false, false)) {+ var frontend, keyword string+ if !util.ParseJsonArgs(arg, ret,+ util.BindJsonArg("frontend", &frontend, false, false),+ util.BindJsonArg("keyword", &keyword, false, false),+ ) {return}ret.Data = map[string]any{- "packages": model.GetInstalledPackages("themes", "", keyword),+ "packages": model.GetInstalledPackages("themes", frontend, keyword),}}@@ -658,8 +664,9 @@ func installBazaarTheme(c *gin.Context) {return}- var keyword, repoURL, repoHash, packageName string+ var frontend, keyword, repoURL, repoHash, packageName stringif !util.ParseJsonArgs(arg, ret,+ util.BindJsonArg("frontend", &frontend, false, false),util.BindJsonArg("keyword", &keyword, false, false),util.BindJsonArg("repoURL", &repoURL, true, true),util.BindJsonArg("repoHash", &repoHash, true, true),@@ -703,7 +710,7 @@ func installBazaarTheme(c *gin.Context) {util.PushMsg(model.Conf.Language(69), 3000)ret.Data = map[string]any{- "packages": model.GetBazaarPackages("themes", "", keyword),+ "packages": model.GetBazaarPackages("themes", frontend, keyword),"appearance": model.Conf.Appearance,}}@@ -717,8 +724,9 @@ func uninstallBazaarTheme(c *gin.Context) {return}- var keyword, packageName string+ var frontend, keyword, packageName stringif !util.ParseJsonArgs(arg, ret,+ util.BindJsonArg("frontend", &frontend, false, false),util.BindJsonArg("keyword", &keyword, false, false),util.BindJsonArg("packageName", &packageName, true, true),) {@@ -732,7 +740,7 @@ func uninstallBazaarTheme(c *gin.Context) {}ret.Data = map[string]any{- "packages": model.GetBazaarPackages("themes", "", keyword),+ "packages": model.GetBazaarPackages("themes", frontend, keyword),"appearance": model.Conf.Appearance,}}diff --git a/kernel/bazaar/bazaar.go b/kernel/bazaar/bazaar.goindex cbf5747b62..7af406c38f 100644--- a/kernel/bazaar/bazaar.go+++ b/kernel/bazaar/bazaar.go@@ -26,7 +26,7 @@ import ("github.com/siyuan-note/siyuan/kernel/util")-// GetBazaarPackages 返回指定类型的在线集市包列表(plugins 类型需要传递 frontend 参数)。+// GetBazaarPackages 返回指定类型的在线集市包列表(plugins 和 themes 类型需要传递 frontend 参数)。func GetBazaarPackages(pkgType string, frontend string) (packages []*Package) {packages, _ = getBazaarPackages(pkgType, frontend, true)return@@ -54,7 +54,7 @@ func getBazaarPackages(pkgType, frontend string, showError bool) (packages []*Pareturn}-// GetBazaarPackagesMap 返回按包名索引的在线集市包映射(plugins 类型需要传递 frontend 参数)。+// GetBazaarPackagesMap 返回按包名索引的在线集市包映射(plugins 和 themes 类型需要传递 frontend 参数)。func GetBazaarPackagesMap(pkgType, frontend string) (packagesMap map[string]*Package, err error) {packages, err := getBazaarPackages(pkgType, frontend, false)if err != nil {@@ -96,8 +96,11 @@ func buildBazaarPackageWithMetadata(repo *StageRepo, bazaarStats map[string]*bazpkg.DisallowInstall = disallowVerpkg.DisallowUpdate = disallowVerpkg.UpdateRequiredMinAppVer = pkg.MinAppVersion- if "plugins" == pkgType {- bazaarIncompatible := IsIncompatiblePlugin(&pkg, frontend)+ if "plugins" == pkgType || "themes" == pkgType {+ bazaarIncompatible := IsIncompatibleTheme(&pkg, frontend)+ if "plugins" == pkgType {+ bazaarIncompatible = IsIncompatiblePlugin(&pkg, frontend)+ }pkg.BazaarIncompatible = &bazaarIncompatibleif bazaarIncompatible {pkg.DisallowInstall = truediff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.goindex 59de60dca3..0ce475b6e5 100644--- a/kernel/bazaar/package.go+++ b/kernel/bazaar/package.go@@ -87,8 +87,8 @@ type Package struct {UpdateRequiredMinAppVer string `json:"updateRequiredMinAppVer,omitempty"` // 升级目标要求的最小应用版本// 专用字段,nil 时不序列化- InstalledIncompatible *bool `json:"installedIncompatible,omitempty"` // Plugin:本地已安装版本是否不兼容- BazaarIncompatible *bool `json:"bazaarIncompatible,omitempty"` // Plugin:在线集市版本是否不兼容+ InstalledIncompatible *bool `json:"installedIncompatible,omitempty"` // 插件/主题:本地已安装版本是否不兼容+ BazaarIncompatible *bool `json:"bazaarIncompatible,omitempty"` // 插件/主题:在线集市版本是否不兼容Enabled *bool `json:"enabled,omitempty"` // Plugin:是否启用Modes *[]string `json:"modes,omitempty"` // Theme:支持的模式列表}diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.gonew file mode 100644index 0000000000..5b4c8830d9--- /dev/null+++ b/kernel/bazaar/theme.go@@ -0,0 +1,27 @@+// SiYuan - Refactor your thinking+// Copyright (c) 2020-present, b3log.org+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as published by+// the Free Software Foundation, either version 3 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++package bazaar++// IsIncompatibleTheme 判断主题是否与当前前端不兼容+func IsIncompatibleTheme(theme *Package, frontend string) bool {+ // frontend 为空时不检查兼容性(视为兼容)+ if "" == frontend {+ return false+ }++ return !IsTargetSupported(theme.Frontends, frontend)+}diff --git a/kernel/bazaar/theme_test.go b/kernel/bazaar/theme_test.gonew file mode 100644index 0000000000..ed78dd605b--- /dev/null+++ b/kernel/bazaar/theme_test.go@@ -0,0 +1,57 @@+// SiYuan - Refactor your thinking+// Copyright (c) 2020-present, b3log.org+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as published by+// the Free Software Foundation, either version 3 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++package bazaar++import "testing"++func TestBuildBazaarThemeCompatibility(t *testing.T) {+ tests := []struct {+ name string+ frontends []string+ frontend string+ wantIncompatible bool+ wantDisallowAction bool+ }{+ {name: "missing field", frontend: "mobile"},+ {name: "all frontends", frontends: []string{"all"}, frontend: "mobile"},+ {name: "supported frontend", frontends: []string{"desktop", "mobile"}, frontend: "mobile"},+ {name: "unsupported frontend", frontends: []string{"desktop"}, frontend: "mobile", wantIncompatible: true, wantDisallowAction: true},+ {name: "missing current frontend", frontends: []string{"desktop"}},+ }++ for _, test := range tests {+ t.Run(test.name, func(t *testing.T) {+ pkg := buildBazaarPackageWithMetadata(&StageRepo{+ URL: "owner/theme@hash",+ Package: &Package{+ Name: "theme",+ Frontends: test.frontends,+ },+ }, nil, "themes", test.frontend)+ if nil == pkg || nil == pkg.BazaarIncompatible {+ t.Fatal("expected theme compatibility metadata")+ }+ if *pkg.BazaarIncompatible != test.wantIncompatible {+ t.Fatalf("expected incompatible=%v, got %v", test.wantIncompatible, *pkg.BazaarIncompatible)+ }+ if pkg.DisallowInstall != test.wantDisallowAction || pkg.DisallowUpdate != test.wantDisallowAction {+ t.Fatalf("expected install and update restriction=%v, got install=%v update=%v",+ test.wantDisallowAction, pkg.DisallowInstall, pkg.DisallowUpdate)+ }+ })+ }+}diff --git a/kernel/model/bazaar.go b/kernel/model/bazaar.goindex 3f60954135..46ff74554d 100644--- a/kernel/model/bazaar.go+++ b/kernel/model/bazaar.go@@ -151,7 +151,7 @@ func BatchUpdatePackages(frontend string) error {// GetUpdatedPackages 获取所有类型集市包的更新列表//-// - frontend 仅用于插件环境兼容性判断+// - frontend 仅用于插件和主题环境兼容性判断func GetUpdatedPackages(frontend string) (plugins, widgets, icons, themes, templates []*UpdatedPackage, err error) {wg := &sync.WaitGroup{}errs := make([]error, 5)@@ -160,7 +160,7 @@ func GetUpdatedPackages(frontend string) (plugins, widgets, icons, themes, templplugins, errs[0] = getUpdatedPackages("plugins", frontend)})wg.Go(func() {- themes, errs[1] = getUpdatedPackages("themes", "")+ themes, errs[1] = getUpdatedPackages("themes", frontend)})wg.Go(func() {icons, errs[2] = getUpdatedPackages("icons", "")@@ -329,6 +329,8 @@ func getInstalledPackages0(pkgType, frontend, keyword string) (installedPackagespkg.Enabled = &enabled}case "themes":+ installedIncompatible := bazaar.IsIncompatibleTheme(pkg, frontend)+ pkg.InstalledIncompatible = &installedIncompatiblepkg.Current = pkg.Name == Conf.Appearance.ThemeDark || pkg.Name == Conf.Appearance.ThemeLightcase "icons":pkg.Current = pkg.Name == Conf.Appearance.Icon