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: Improve marketplace package compatibility check and batch update (#17757)
Jeffrey Chenc9ff08a7451f
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex 860c3bdc17..4156a0c0c6 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -244,6 +244,13 @@ export const bazaar = {return `<span class="fn__space--small"></span><span data-type="copy-funding" data-funding="${escapeAttr(funding)}" class="block__icon block__icon--show ariaLabel" data-position="north" aria-label="${window.siyuan.languages.sponsor} ${escapeAttr(funding)}"><svg class="ft__pink"><use xlink:href="#iconHeart"></use></svg></span>`;}},+ _genIncompatibleChipHTML(item: IBazaarItem, source: "installed" | "bazaar") {+ const incompatible = source === "installed" ? item.installedIncompatible : item.bazaarIncompatible;+ if (!incompatible) {+ return "";+ }+ return `<span class="fn__space"></span><span data-position="north" class="fn__flex-center ariaLabel b3-chip b3-chip--error b3-chip--small" aria-label="${window.siyuan.languages.incompatiblePluginTip}">${window.siyuan.languages.incompatible}</span>`;+ },_genCardHTML(item: IBazaarItem, bazaarType: TBazaarType) {let hide = false;let themeMode = "";@@ -293,6 +300,7 @@ export const bazaar = {${escapeHtml(item.author)}</span>${bazaar._genFundingHTML(item.preferredFunding)}+ ${bazaar._genIncompatibleChipHTML(item, "bazaar")}<span class="fn__space--small"></span><div class="fn__flex-1"></div><div class="fn__space--small${!item.current && item.installed && showSwitch ? "" : " fn__none"}"></div>@@ -300,11 +308,45 @@ export const bazaar = {<svg><use xlink:href="#iconSelect"></use></svg></span><div class="fn__space--small${item.outdated ? "" : " fn__none"}"></div>- <span data-type="install-t" ${item.disallowUpdate ? "disabled" : ""} aria-label="${item.disallowUpdate ? window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.updateRequiredMinAppVer) : window.siyuan.languages.update}" data-position="north" class="ariaLabel block__icon block__icon--show${item.outdated ? "" : " fn__none"}">- <svg class="ft__primary"><use xlink:href="#iconRefresh"></use></svg>- </span>+ ${bazaar._genUpdateButtonHTML(item)}</div></div>+</div>`;+ },+ _genInstallButtonAriaLabel(item: IBazaarItem) {+ if (!item.disallowInstall) {+ return window.siyuan.languages.download;+ }+ if (item.bazaarIncompatible) {+ return window.siyuan.languages.incompatiblePluginTip;+ }+ return window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.minAppVersion || "");+ },+ _genUpdateButtonAriaLabel(item: IBazaarItem) {+ if (!item.disallowUpdate) {+ return window.siyuan.languages.update;+ }+ if (item.bazaarIncompatible) {+ return window.siyuan.languages.incompatiblePluginTip;+ }+ return window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.updateRequiredMinAppVer || "");+ },+ _genUpdateButtonHTML(item: IBazaarItem) {+ if (!item.outdated) {+ return "";+ }+ const ariaLabel = this._genUpdateButtonAriaLabel(item);+ return `<span data-position="north" data-type="install-t" ${item.disallowUpdate ? "disabled" : ""} aria-label="${ariaLabel}" class="ariaLabel block__icon block__icon--show">+ <svg class="ft__primary"><use xlink:href="#iconRefresh"></use></svg>+</span>`;+ },+ _genReadmeUpdateButtonHTML(item: IBazaarItem) {+ if (!item.outdated) {+ return "";+ }+ const ariaLabel = this._genUpdateButtonAriaLabel(item);+ return `<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></div>`;},_genUpdateItemHTML(item: IBazaarItem, bazaarType: TBazaarType) {@@ -327,14 +369,12 @@ export const bazaar = {</div></div><div class="b3-card__actions b3-card__actions--right">- ${item.incompatible ? `<span class="fn__space"></span><span data-position="north" class="fn__flex-center ariaLabel b3-chip b3-chip--error b3-chip--small" aria-label="${window.siyuan.languages.incompatiblePluginTip}">${window.siyuan.languages.incompatible}</span>` : ""}+ ${bazaar._genIncompatibleChipHTML(item, "bazaar")}${bazaar._genFundingHTML(item.preferredFunding)}<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>- <span data-position="north" data-type="install-t" ${item.disallowUpdate ? "disabled" : ""} aria-label="${item.disallowUpdate ? window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.updateRequiredMinAppVer) : window.siyuan.languages.update}" class="ariaLabel block__icon block__icon--show">- <svg class="ft__primary"><use xlink:href="#iconRefresh"></use></svg>- </span>+ ${bazaar._genUpdateButtonHTML(item)}</div></div>`;},@@ -436,7 +476,7 @@ export const bazaar = {</div></div><div class="b3-card__actions b3-card__actions--right">- ${item.incompatible ? `<span class="fn__space"></span><span data-position="north" class="fn__flex-center ariaLabel b3-chip b3-chip--error b3-chip--small" aria-label="${window.siyuan.languages.incompatiblePluginTip}">${window.siyuan.languages.incompatible}</span>` : ""}+ ${bazaar._genIncompatibleChipHTML(item, "installed")}${bazaar._genFundingHTML(item.preferredFunding)}<span data-position="north" class="ariaLabel block__icon block__icon--show${hasSetting ? "" : " fn__none"}" data-type="setting" aria-label="${window.siyuan.languages.config}"><svg><use xlink:href="#iconSettings"></use></svg>@@ -450,12 +490,10 @@ export const bazaar = {<span data-position="north" class="ariaLabel block__icon block__icon--show${!item.current && showSwitch ? "" : " fn__none"}" data-type="switch" aria-label="${window.siyuan.languages.use}"><svg><use xlink:href="#iconSelect"></use></svg></span>- <span data-position="north" data-type="install-t" ${item.disallowUpdate ? "disabled" : ""} aria-label="${item.disallowUpdate ? window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.updateRequiredMinAppVer) : window.siyuan.languages.update}" class="ariaLabel block__icon block__icon--show${item.outdated ? "" : " fn__none"}">- <svg class="ft__primary"><use xlink:href="#iconRefresh"></use></svg>- </span>+ ${bazaar._genUpdateButtonHTML(item)}<span class="fn__space${bazaarType === "plugins" ? "" : " fn__none"}"></span><span class="fn__space${bazaarType === "plugins" ? "" : " fn__none"}"></span>- <input ${((item.disallowInstall && !item.enabled) || item.incompatible) ? "disabled" : ""}+ <input ${((item.disallowInstall && !item.enabled) || item.installedIncompatible) ? "disabled" : ""}aria-label="${(item.disallowInstall && !item.enabled) ? window.siyuan.languages.bazaarNeedVersion.replace("${x}", item.minAppVersion) : ""}"data-position="north" class="ariaLabel b3-switch fn__flex-center${bazaarType === "plugins" ? "" : " fn__none"}"${item.enabled ? "checked" : ""}@@ -551,12 +589,10 @@ type="checkbox"><div class="ft__on-surface ft__smaller" style="line-height: 20px;">${window.siyuan.languages.installSize}<br>${data.hInstallSize}</div><div class="fn__hr--b"></div><div class="fn__hr--b"></div>- <div${(data.installed || downloaded) ? ' class="fn__none"' : ""}>- <button ${data.disallowInstall ? `disabled aria-label="${window.siyuan.languages.bazaarNeedVersion.replace("${x}", data.minAppVersion)}" data-position="north"` : ""} class="b3-button ariaLabel" style="width: 168px" data-type="install">${window.siyuan.languages.download}</button>- </div>- <div${(data.outdated && (data.installed || downloaded)) ? "" : ' class="fn__none"'}>- <button ${data.disallowUpdate ? `disabled aria-label="${window.siyuan.languages.bazaarNeedVersion.replace("${x}", data.updateRequiredMinAppVer)}" data-position="north"` : ""} class="b3-button ariaLabel" style="width: 168px" data-type="install-t">${window.siyuan.languages.update}</button>+ <div${data.installed ? ' class="fn__none"' : ""}>+ <button ${data.disallowInstall ? `disabled aria-label="${bazaar._genInstallButtonAriaLabel(data)}" data-position="north"` : ""} class="b3-button ariaLabel" style="width: 168px" data-type="install">${window.siyuan.languages.download}</button></div>+ ${bazaar._genReadmeUpdateButtonHTML(data)}<div class="fn__hr--b"></div><div><a href="${data.repoURL}/issues" target="_blank" title="Feedback via GitHub Issues" class="b3-button b3-button--success" style="width: 168px" data-type="feedback">${window.siyuan.languages.feedback}</a>@@ -733,7 +769,14 @@ type="checkbox">break;} else if (type === "install-all") {confirmDialog("⬆️ " + window.siyuan.languages.updateAll, window.siyuan.languages.confirmUpdateAll, () => {- fetchPost("/api/bazaar/batchUpdatePackage");+ fetchPost("/api/bazaar/batchUpdatePackage", {frontend: getFrontend()}, () => {+ let activeBazaarType: TBazaarType = "plugins";+ const activeBtn = bazaar.element.querySelector("#configBazaarDownloaded")?.previousElementSibling?.querySelector(".b3-button:not(.b3-button--outline)") as HTMLElement;+ if (activeBtn?.getAttribute("data-type")) {+ activeBazaarType = activeBtn.getAttribute("data-type").replace("my", "").toLowerCase() + "s" as TBazaarType;+ }+ bazaar._genMyHTML(activeBazaarType, app);+ });});event.preventDefault();event.stopPropagation();diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 8e68dd6f50..66ce6dfa3e 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -934,10 +934,11 @@ interface IBazaarItem {hUpdated: string;preferredFunding: string;disallowUpdate: boolean;- updateRequiredMinAppVer: string;- incompatible?: boolean; // 仅 plugin- enabled?: boolean; // 仅 plugin- modes?: string[]; // 仅 theme+ updateRequiredMinAppVer?: string;+ installedIncompatible?: boolean; // 仅 plugin+ bazaarIncompatible?: boolean; // 仅 plugin+ enabled?: boolean; // 仅 plugin+ modes?: string[]; // 仅 theme}interface IAV {diff --git a/kernel/api/bazaar.go b/kernel/api/bazaar.goindex 7321c1e0a4..b266a698bc 100644--- a/kernel/api/bazaar.go+++ b/kernel/api/bazaar.go@@ -37,7 +37,17 @@ func batchUpdatePackage(c *gin.Context) {ret := gulu.Ret.NewResult()defer c.JSON(http.StatusOK, ret)- model.BatchUpdatePackages()+ arg, ok := util.JsonArg(c, ret)+ if !ok {+ return+ }++ var frontend string+ if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("frontend", &frontend, true, true)) {+ return+ }++ model.BatchUpdatePackages(frontend)}func getUpdatedPackage(c *gin.Context) {diff --git a/kernel/bazaar/bazaar.go b/kernel/bazaar/bazaar.goindex 580190a258..de2136c7fa 100644--- a/kernel/bazaar/bazaar.go+++ b/kernel/bazaar/bazaar.go@@ -44,6 +44,18 @@ func GetBazaarPackages(pkgType string, frontend string) (packages []*Package) {return}+// GetBazaarPackagesMap 返回按包名索引的在线集市包映射(plugins 类型需要传递 frontend 参数)。+func GetBazaarPackagesMap(pkgType, frontend string) map[string]*Package {+ packages := GetBazaarPackages(pkgType, frontend)+ packagesMap := make(map[string]*Package, len(packages))+ for _, pkg := range packages {+ if "" != pkg.Name {+ packagesMap[pkg.Name] = pkg+ }+ }+ return packagesMap+}+// buildBazaarPackageWithMetadata 从 StageRepo 构建带有在线元数据的集市包。func buildBazaarPackageWithMetadata(repo *StageRepo, bazaarStats map[string]*bazaarStats, pkgType string, frontend string) *Package {if nil == repo || nil == repo.Package {@@ -67,13 +79,17 @@ func buildBazaarPackageWithMetadata(repo *StageRepo, bazaarStats map[string]*bazpkg.PreferredFunding = getPreferredFunding(pkg.Funding)// 更新信息- disallow := isBelowRequiredAppVersion(&pkg)- pkg.DisallowInstall = disallow- pkg.DisallowUpdate = disallow+ disallowVer := isBelowRequiredAppVersion(&pkg)+ pkg.DisallowInstall = disallowVer+ pkg.DisallowUpdate = disallowVerpkg.UpdateRequiredMinAppVer = pkg.MinAppVersionif "plugins" == pkgType {- incompatible := IsIncompatiblePlugin(&pkg, frontend)- pkg.Incompatible = &incompatible+ bazaarIncompatible := IsIncompatiblePlugin(&pkg, frontend)+ pkg.BazaarIncompatible = &bazaarIncompatible+ if bazaarIncompatible {+ pkg.DisallowInstall = true+ pkg.DisallowUpdate = true+ }}// 统计信息diff --git a/kernel/bazaar/installed.go b/kernel/bazaar/installed.goindex 29bb05b327..76758853cc 100644--- a/kernel/bazaar/installed.go+++ b/kernel/bazaar/installed.go@@ -52,7 +52,7 @@ func ReadInstalledPackageDirs(basePath string) ([]os.DirEntry, error) {}// SetInstalledPackageMetadata 设置本地集市包的通用元数据-func SetInstalledPackageMetadata(pkg *Package, installPath, baseURLPath, pkgType string, bazaarPackagesMap map[string]*Package) bool {+func SetInstalledPackageMetadata(pkg *Package, installPath, baseURLPath, pkgType, frontend string, bazaarPackagesMap map[string]*Package) bool {// 展示信息pkg.IconURL = baseURLPath + "icon.png"pkg.PreviewURL = baseURLPath + "preview.png"@@ -65,13 +65,17 @@ func SetInstalledPackageMetadata(pkg *Package, installPath, baseURLPath, pkgTypepkg.Installed = truepkg.DisallowInstall = isBelowRequiredAppVersion(pkg)if bazaarPkg := bazaarPackagesMap[pkg.Name]; nil != bazaarPkg {- pkg.DisallowUpdate = isBelowRequiredAppVersion(bazaarPkg)- pkg.UpdateRequiredMinAppVer = bazaarPkg.MinAppVersionpkg.RepoURL = bazaarPkg.RepoURL // 更新链接使用在线数据,避免本地元数据的链接错误+ pkg.UpdateRequiredMinAppVer = bazaarPkg.MinAppVersionif 0 > semver.Compare("v"+pkg.Version, "v"+bazaarPkg.Version) {pkg.RepoHash = bazaarPkg.RepoHashpkg.Outdated = true+ disallowUpdate := isBelowRequiredAppVersion(bazaarPkg)+ if "plugins" == pkgType {+ disallowUpdate = disallowUpdate || IsIncompatiblePlugin(bazaarPkg, frontend)+ }+ pkg.DisallowUpdate = disallowUpdate}} else {pkg.RepoURL = pkg.URLdiff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.goindex 82c472cee1..05bccf7be9 100644--- a/kernel/bazaar/package.go+++ b/kernel/bazaar/package.go@@ -82,12 +82,13 @@ type Package struct {Downloads int `json:"downloads"`DisallowInstall bool `json:"disallowInstall"`DisallowUpdate bool `json:"disallowUpdate"`- UpdateRequiredMinAppVer string `json:"updateRequiredMinAppVer"`+ UpdateRequiredMinAppVer string `json:"updateRequiredMinAppVer,omitempty"` // 升级目标要求的最小应用版本// 专用字段,nil 时不序列化- Incompatible *bool `json:"incompatible,omitempty"` // Plugin:是否不兼容- Enabled *bool `json:"enabled,omitempty"` // Plugin:是否启用- Modes *[]string `json:"modes,omitempty"` // Theme:支持的模式列表+ InstalledIncompatible *bool `json:"installedIncompatible,omitempty"` // Plugin:本地已安装版本是否不兼容+ BazaarIncompatible *bool `json:"bazaarIncompatible,omitempty"` // Plugin:在线集市版本是否不兼容+ Enabled *bool `json:"enabled,omitempty"` // Plugin:是否启用+ Modes *[]string `json:"modes,omitempty"` // Theme:支持的模式列表}type StageRepo struct {diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.goindex ef991dd52e..a00c359f09 100644--- a/kernel/bazaar/plugin.go+++ b/kernel/bazaar/plugin.go@@ -64,16 +64,16 @@ func ParseInstalledPlugin(name, frontend string) (found bool, version, displayNa// IsIncompatiblePlugin 判断插件是否与当前环境不兼容func IsIncompatiblePlugin(plugin *Package, frontend string) bool {- // frontend 为空时不检查兼容性(视为兼容)- if "" == frontend {- return false- }-backend := GetCurrentBackend()if !IsTargetSupported(plugin.Backends, backend) {return true}+ // frontend 为空时不检查兼容性(视为兼容)+ if "" == frontend {+ return false+ }+if !IsTargetSupported(plugin.Frontends, frontend) {return true}diff --git a/kernel/model/bazaar.go b/kernel/model/bazaar.goindex eadadef9fd..03709e4ef8 100644--- a/kernel/model/bazaar.go+++ b/kernel/model/bazaar.go@@ -23,13 +23,11 @@ import ("os""path/filepath""sync"- "time""github.com/88250/gulu""github.com/emirpasic/gods/sets/hashset""github.com/siyuan-note/logging""github.com/siyuan-note/siyuan/kernel/bazaar"- "github.com/siyuan-note/siyuan/kernel/task""github.com/siyuan-note/siyuan/kernel/util""golang.org/x/mod/semver""golang.org/x/sync/singleflight"@@ -59,61 +57,75 @@ func getPackageInstallPath(pkgType, packageName string) (string, string, error)}}-// updatePackages 更新一组集市包-func updatePackages(packages []*bazaar.Package, pkgType string, count *int, total int) bool {+// installMeta 记录安装前后的状态,供安装后处理使用+type installMeta struct {+ update bool+}++// batchInstallItem 同类型批量安装时单个包的结果+type batchInstallItem struct {+ name string+ meta installMeta+}++// updatePackages 更新一组集市包;同类型批量更新时,安装后处理只执行一次+func updatePackages(packages []*bazaar.Package, pkgType string, successCount *int, planned int) {+ items := make([]batchInstallItem, 0, len(packages))for _, pkg := range packages {- installPath, _, err := getPackageInstallPath(pkgType, pkg.Name)- if err != nil {- return false- }- err = bazaar.InstallPackage(pkg.RepoURL, pkg.RepoHash, installPath, Conf.System.ID, pkgType, pkg.Name)+ meta, err := installBazaarPackage(pkgType, pkg.RepoURL, pkg.RepoHash, pkg.Name)if err != nil {logging.LogErrorf("update %s [%s] failed: %s", pkgType, pkg.Name, err)util.PushErrMsg(fmt.Sprintf(Conf.language(238), pkg.Name), 5000)- return false+ continue}- *count++- util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), *count, total, pkg.Name))+ items = append(items, batchInstallItem{name: pkg.Name, meta: meta})+ *successCount+++ util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), *successCount, planned, pkg.Name))}- return true+ finishInstall(pkgType, items, 0)}-// BatchUpdatePackages 更新所有集市包-func BatchUpdatePackages() {- plugins, widgets, icons, themes, templates := GetUpdatedPackages("")+// filterUpdatableBazaarPackages 过滤出允许更新的集市包+func filterUpdatableBazaarPackages(packages []*bazaar.Package) []*bazaar.Package {+ updatable := make([]*bazaar.Package, 0, len(packages))+ for _, pkg := range packages {+ if !pkg.DisallowUpdate {+ updatable = append(updatable, pkg)+ }+ }+ return updatable+}- total := len(plugins) + len(widgets) + len(icons) + len(themes) + len(templates)- if 1 > total {+// BatchUpdatePackages 更新所有集市包+func BatchUpdatePackages(frontend string) {+ plugins, widgets, icons, themes, templates := GetUpdatedPackages(frontend)+ plugins = filterUpdatableBazaarPackages(plugins)+ widgets = filterUpdatableBazaarPackages(widgets)+ icons = filterUpdatableBazaarPackages(icons)+ themes = filterUpdatableBazaarPackages(themes)+ templates = filterUpdatableBazaarPackages(templates)++ planned := len(plugins) + len(widgets) + len(icons) + len(themes) + len(templates)+ if 1 > planned {return}- util.PushEndlessProgress(fmt.Sprintf(Conf.language(235), 1, total))defer util.PushClearProgress()- count := 1-- if !updatePackages(plugins, "plugins", &count, total) {- return- }- if !updatePackages(themes, "themes", &count, total) {- return- }- if !updatePackages(icons, "icons", &count, total) {- return+ successCount := 0+ updatePackages(plugins, "plugins", &successCount, planned)+ updatePackages(themes, "themes", &successCount, planned)+ updatePackages(icons, "icons", &successCount, planned)+ updatePackages(templates, "templates", &successCount, planned)+ updatePackages(widgets, "widgets", &successCount, planned)++ if 0 < successCount {+ util.PushMsg(fmt.Sprintf(Conf.language(237), successCount), 5000)}- if !updatePackages(templates, "templates", &count, total) {- return- }- if !updatePackages(widgets, "widgets", &count, total) {- return- }-- util.ReloadUI()- task.AppendAsyncTaskWithDelay(task.PushMsg, 3*time.Second, util.PushMsg, fmt.Sprintf(Conf.language(237), total), 5000)}// GetUpdatedPackages 获取所有类型集市包的更新列表//-// - frontend 仅用于插件兼容性展示+// - frontend 仅用于插件环境兼容性判断func GetUpdatedPackages(frontend string) (plugins, widgets, icons, themes, templates []*bazaar.Package) {wg := &sync.WaitGroup{}@@ -239,20 +251,14 @@ func getInstalledPackages0(pkgType, frontend, keyword string) (installedPackagesreturn}- bazaarPackages := bazaar.GetBazaarPackages(pkgType, frontend)- bazaarPackagesMap := make(map[string]*bazaar.Package, len(bazaarPackages))- for _, pkg := range bazaarPackages {- if "" != pkg.Name {- bazaarPackagesMap[pkg.Name] = pkg- }- }+ bazaarPackagesMap := bazaar.GetBazaarPackagesMap(pkgType, frontend)for _, info := range installedInfos {pkg := info.PkginstallPath := filepath.Join(basePath, info.DirName)baseURLPath := baseURLPathPrefix + info.DirName + "/"// 设置本地集市包的通用元数据- if !bazaar.SetInstalledPackageMetadata(pkg, installPath, baseURLPath, pkgType, bazaarPackagesMap) {+ if !bazaar.SetInstalledPackageMetadata(pkg, installPath, baseURLPath, pkgType, frontend, bazaarPackagesMap) {continue}installedPackages = append(installedPackages, pkg)@@ -268,8 +274,13 @@ func getInstalledPackages0(pkgType, frontend, keyword string) (installedPackagesfor _, pkg := range installedPackages {switch pkgType {case "plugins":- incompatible := bazaar.IsIncompatiblePlugin(pkg, frontend)- pkg.Incompatible = &incompatible+ installedIncompatible := bazaar.IsIncompatiblePlugin(pkg, frontend)+ pkg.InstalledIncompatible = &installedIncompatible+ var bazaarIncompatible bool+ if onlinePkg := bazaarPackagesMap[pkg.Name]; nil != onlinePkg {+ bazaarIncompatible = bazaar.IsIncompatiblePlugin(onlinePkg, frontend)+ }+ pkg.BazaarIncompatible = &bazaarIncompatiblepetal := getPetalByName(pkg.Name, petals)if nil != petal {enabled := petal.Enabled@@ -318,57 +329,89 @@ func GetBazaarPackageREADME(ctx context.Context, repoURL, repoHash, pkgType strireturn}-// InstallBazaarPackage 安装集市包,themeMode 仅在 pkgType 为 "themes" 时生效-func InstallBazaarPackage(pkgType, repoURL, repoHash, packageName string, themeMode int) error {+// installBazaarPackage 下载并安装集市包+func installBazaarPackage(pkgType, repoURL, repoHash, packageName string) (meta installMeta, err error) {installPath, jsonFileName, err := getPackageInstallPath(pkgType, packageName)if err != nil {- return err+ return}installedPkg, parseErr := bazaar.ParsePackageJSON(filepath.Join(installPath, jsonFileName))- update := parseErr == nil && installedPkg != nil && installedPkg.Name == packageName+ meta.update = parseErr == nil && installedPkg != nil && installedPkg.Name == packageNameerr = bazaar.InstallPackage(repoURL, repoHash, installPath, Conf.System.ID, pkgType, packageName)if err != nil {- return fmt.Errorf(Conf.Language(46), packageName, err)+ err = fmt.Errorf(Conf.Language(46), packageName, err)+ }+ return+}++// finishInstall 集市包安装后的处理(刷新外观、推送插件重载等);批量更新时同类型只执行一次+//+// - themeMode:0 浅色 / 1 深色,仅在新安装主题(meta.update 为 false)时写入外观;批量覆盖更新不会用到+func finishInstall(pkgType string, items []batchInstallItem, themeMode int) {+ if 1 > len(items) {+ return}switch pkgType {case "plugins":- if update {- // 已启用的插件更新之后需要重载- petal := GetPetalByName(packageName)+ reloadPluginSet := hashset.New()+ for _, item := range items {+ if !item.meta.update {+ continue+ }+ petal := GetPetalByName(item.name)if nil != petal && petal.Enabled {- // reload kernel plugin- SetPetalEnabled(petal.Name, petal.Enabled)- reloadPluginSet := hashset.New(packageName)- PushReloadPlugin(nil, nil, reloadPluginSet, nil, "")+ _, err := SetPetalEnabled(petal.Name, petal.Enabled) // 重新加载插件内容+ if err != nil {+ logging.LogErrorf("reload plugin [%s] after update failed: %s", item.name, err)+ util.PushErrMsg(err.Error(), 5000)+ continue+ }+ reloadPluginSet.Add(item.name)}}+ if 0 < reloadPluginSet.Size() {+ PushReloadPlugin(nil, nil, reloadPluginSet, nil, "")+ }case "themes":- if !update {- // 更新主题后不需要切换到该主题 https://github.com/siyuan-note/siyuan/issues/4966- if 0 == themeMode {- Conf.Appearance.ThemeLight = packageName- } else {- Conf.Appearance.ThemeDark = packageName+ for _, item := range items {+ if !item.meta.update {+ // 新安装主题时才自动切换 https://github.com/siyuan-note/siyuan/issues/4966+ if 0 == themeMode {+ Conf.Appearance.ThemeLight = item.name+ } else {+ Conf.Appearance.ThemeDark = item.name+ }+ Conf.Appearance.Mode = themeMode+ Conf.Appearance.ThemeJS = gulu.File.IsExist(filepath.Join(util.ThemesPath, item.name, "theme.js"))+ Conf.Save()}- Conf.Appearance.Mode = themeMode- Conf.Appearance.ThemeJS = gulu.File.IsExist(filepath.Join(util.ThemesPath, packageName, "theme.js"))- Conf.Save()}InitAppearance()WatchThemes()util.BroadcastByType("main", "setAppearance", 0, "", Conf.Appearance)case "icons":- if !update {- // 更新图标后不需要切换到该图标- Conf.Appearance.Icon = packageName- Conf.Save()+ for _, item := range items {+ if !item.meta.update {+ // 新安装图标时才自动切换+ Conf.Appearance.Icon = item.name+ Conf.Save()+ }}InitAppearance()util.BroadcastByType("main", "setAppearance", 0, "", Conf.Appearance)}+}++// InstallBazaarPackage 安装集市包,themeMode 仅在 pkgType 为 "themes" 时生效+func InstallBazaarPackage(pkgType, repoURL, repoHash, packageName string, themeMode int) error {+ meta, err := installBazaarPackage(pkgType, repoURL, repoHash, packageName)+ if err != nil {+ return err+ }+ finishInstall(pkgType, []batchInstallItem{{name: packageName, meta: meta}}, themeMode)return nil}diff --git a/kernel/model/plugin.go b/kernel/model/plugin.goindex 05a35dc509..1ffc1f821d 100644--- a/kernel/model/plugin.go+++ b/kernel/model/plugin.go@@ -66,7 +66,8 @@ func SetPetalEnabled(name string, enabled bool) (ret *Petal, err error) {found, version, displayName, incompatible, disabledInPublish, disallowInstall, kernelIncompatible := bazaar.ParseInstalledPlugin(name, "")if !found {- logging.LogErrorf("plugin [%s] not found", name)+ err = fmt.Errorf("plugin [%s] not found", name)+ logging.LogErrorf("%s", err)return}@@ -89,7 +90,7 @@ func SetPetalEnabled(name string, enabled bool) (ret *Petal, err error) {if enabled && disallowInstall {err = fmt.Errorf("require upgrade SiYuan to use this plugin [%s]", name)- logging.LogInfof("require upgrade SiYuan to use this plugin [%s]", name)+ logging.LogInfof("%s", err)return}